2017-02-22 73 views
0

我有两个非常简单的spring-cloud-stream应用程序。 Service3,消息生产者,通过binder-kafka向消费者Service4发送消息。无法用spring-cloud-sleuth跟踪spring-cloud-stream监听器

我用spring-cloud-sleuth来追踪它们之间的跨度。但是在Zipkin服务器中只有Service3的跨度可用。 Service4没有跨度显示。

  1. 服务3

    dependencies { 
    compile('org.springframework.boot:spring-boot-starter-web') 
    compile('org.springframework.boot:spring-boot-starter-thymeleaf') 
    
    compile('org.springframework.cloud:spring-cloud-starter-sleuth') 
    
    // Marshal spans over a Spring cloud stream binder 
    compile('org.springframework.cloud:spring-cloud-sleuth-stream') 
    compile('org.springframework.cloud:spring-cloud-stream-binder-kafka') 
    
    testCompile group: 'junit', name: 'junit', version: '4.11' 
    } 
    
    
    @SpringBootApplication 
    public class Service3 { 
        public static void main(String[] args) { 
         SpringApplication.run(Service3.class, args); 
        } 
    } 
    
    
    @Controller 
    @EnableBinding(Source.class) 
    public class WebController { 
    
        @Autowired 
        private Source source; 
    
    
        @GetMapping("/srv4") 
        private String getSrv4Info(){ 
         String msg = "Hello Service 4"; 
         this.source.output().send(MessageBuilder.withPayload(msg).build()); 
    
         return "srv4"; 
        } 
    } 
    
  2. 服务4

    dependencies { 
        compile('org.springframework.boot:spring-boot-starter-web') 
    
        compile('org.springframework.cloud:spring-cloud-starter-sleuth') 
    
        // Marshal spans over a Spring cloud stream binder 
        compile('org.springframework.cloud:spring-cloud-sleuth-stream') 
        compile('org.springframework.cloud:spring-cloud-sleuth-zipkin-stream') 
        compile('org.springframework.cloud:spring-cloud-stream-binder-kafka') 
    
        runtime('io.zipkin.java:zipkin-autoconfigure-ui') 
    
        testCompile group: 'junit', name: 'junit', version: '4.11' 
    } 
    
    @SpringBootApplication 
    @EnableZipkinStreamServer 
    public class Service4 { 
        public static void main(String[] args) { 
         SpringApplication.run(Service4.class, args); 
        } 
    } 
    
    @EnableBinding(Sink.class) 
    public class MsgReceiver { 
        @StreamListener(Sink.INPUT) 
        private void listen(Message<String> msg){ 
         System.out.println(msg.getPayload()); 
        } 
    } 
    

Servic4 (message consumer) is not traced

我错过了什么?

+0

最后,我发现与我的应用程序相关的2个问题。 1.无法追踪带有@EnalbeZipkinStreamServer的应用程序。这看起来像一个设计。 – RocWay

+0

是的,这是由设计完成的原因,我们不想跟踪示踪剂 –

回答

0

这是一个猜测。

卡夫卡没有消息标题的概念(存储跨度)。

SCSt因此必须在消息中嵌入消息头。

当前版本要求您“选择”以此方式运输哪些标题。

Documentation here

spring.cloud.stream.kafka.binder.headers

将由粘结剂运自定义标题的列表。

默认值:空。

不幸的是,模式目前不支持,你必须单独列出头。我们是considering adding support for patterns和/或默认运输所有标题。

+0

感谢您的建议。 @russell,你是对的。我发现与这个问题有关的github问题。 https://github.com/spring-cloud/spring-cloud-sleuth/issues/282。 – RocWay

+0

今天我修复了所有必要的标题自动传播 –

+0

这将是非常有用的,节省了大量的挖掘时间。 :) – RocWay

0

最后,我发现了2个与我的应用程序有关的问题。 1.无法追踪带有@EnalbeZipkinStreamServer的应用程序。这看起来像一个设计。 2.如果卡夫卡被用作粘合剂,应用程序应该为以下指定标题:

spring.cloud.stream.kafka.binder.headers[0]=spanId 
    spring.cloud.stream.kafka.binder.headers[1]=spanSampled 
    spring.cloud.stream.kafka.binder.headers[2]=spanProcessId 
    spring.cloud.stream.kafka.binder.headers[3]=spanParentSpanId 
    spring.cloud.stream.kafka.binder.headers[4]=spanTraceId 
    spring.cloud.stream.kafka.binder.headers[5]=spanName 
    spring.cloud.stream.kafka.binder.headers[6]=spanFlags 
+0

随着我今天所做的改变,这不再是必要的 –