0

我有 2 个非常简单的 spring-cloud-stream 应用程序。消息生产者 Service3 通过 binder-kafka 向消费者 Service4 发送消息。

我使用 spring-cloud-sleuth 来追踪它们之间的跨度。但是 zipkin 服务器中只有 Service3 中的 span 可用。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(消息使用者)

我错过了什么?

4

2 回答 2

0

这是一个猜测。

Kafka 没有消息头的概念(存储跨度的地方)。

因此,SCSt 必须在有效负载中嵌入消息头。

当前版本要求您“选择加入”您希望以这种方式传输的标头。

文档在这里

spring.cloud.stream.kafka.binder.headers

将由活页夹传输的自定义标头列表。

默认值:空。

不幸的是,目前不支持模式,您必须单独列出标题。我们正在考虑添加对模式的支持和/或默认传输所有标头。

于 2017-02-22T15:14:57.870 回答
0

最后,我发现了与我的应用程序相关的 2 个问题。1. 无法追踪带有@EnalbeZipkinStreamServer 的应用程序。这看起来像是设计使然。2. 如果使用 kafka 作为 binder,应用程序应指定 headers,如下所示:

    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
于 2017-02-23T07:11:02.987 回答