简体   繁体   English

Java Spring Boot App无法将zipkin跟踪信息传递给Rabbitmq

[英]java spring boot app failed to passing zipkin trace info to rabbitmq

I was working on an Ecommerce microservice-based application. 我正在开发一个基于电子商务微服务的应用程序。 HTTP request structure: frontend -> order -> shipping -> rabbitmq -> queue-master. HTTP请求结构:前端->订单->运输-> Rabbitmq->队列主控。 The shipping container get the trace info from order but it doesn't pass along to rabbitmq. 装运容器从订单中获取跟踪信息,但不会传递给rabbitmq。 Is there any configuration I should do? 我应该做些配置吗? I thought using "spring-cloud-starter-zipkin" will help me handle it effortlessly. 我认为使用“ spring-cloud-starter-zipkin”将帮助我轻松处理它。

(tcpdump) shipping get post request with trace info: (tcpdump)运送获取带有跟踪信息的发帖请求:

 2018-05-11 14:52:47.225204 IP 172.18.0.1.55648 > 172.18.0.8.80: Flags [P.], seq 1:320, ack 1, win 229, options [nop,nop,TS val 316382616 ecr 316382616], length 319:    HTTP: POST /shipping HTTP/1.1
 E..sF.@.@............`.PU5.6.f
 .....Y......
 ........POST /shipping HTTP/1.1
 Accept: application/json
 Content-Type: application/json
 X-B3-TraceId: a5a28c66a3557a66
 X-B3-SpanId: 94e11436dc6c4bee
 X-B3-Sampled: 1
 X-Span-Name: http:/shipping
 X-B3-ParentSpanId: 1a084fd84593e495
 User-Agent: Java/1.8.0_131
 Host: shipping
 Connection: keep-alive
 Content-Length: 79

shipping send out to rabbitmq missing tracing data. 装运发送到Rabbitmq缺少跟踪数据。

 2018-05-11 14:52:47.228864 IP 172.18.0.8.34840 > 172.18.0.6.5672: Flags [P.], seq 3168203512:3168203740, ack 344352272, win 237, options [nop,nop,TS val 316382617 ecr  316375545], length 228
 E...;.@.@..............(......f.....Y=.....
 ................<.(....shipping-task........g.<.........O...application/json.UTF-8...<
 __TypeId__S...,works.weave.socks.shipping.entities.Shipment.........O{"id":"8b92ebba-d95d-4212-af3e-6304ba5fc363","name":"57a98d98e4b00679b4a830b2"}.

EDITED: Some code about post shipping request: (shipment is just an object with id and name) 编辑:关于发运请求的一些代码:(发运只是具有ID和名称的对象)


@ResponseStatus(HttpStatus.CREATED)
@RequestMapping(value = "/shipping", method = RequestMethod.POST)
public
@ResponseBody
Shipment postShipping(@RequestBody Shipment shipment) {
    System.out.println("Adding shipment to queue...");
    try {
        rabbitTemplate.convertAndSend("shipping-task", shipment);
    } catch (Exception e) {
        System.out.println("Unable to add to queue (the queue is probably down). Accepting anyway. Don't do this " +
                "for real!");
    }
    return shipment;
}

OK! 好! I see now the problem! 我现在看到了问题!

So, you say that your HTTP request has these tracing headers: X-B3-TraceId , X-B3-SpanId , X-B3-Sampled , X-Span-Name , X-B3-ParentSpanId . 因此,您说您的HTTP请求具有以下跟踪标头: X-B3-TraceIdX-B3-SpanIdX-B3-SampledX-Span-NameX-B3-ParentSpanId

Then you have this code: 然后,您有以下代码:

rabbitTemplate.convertAndSend("shipping-task", shipment);

And that's absolutely natural that your tracing header are not transferred to the RabbitMQ: there is just no those headers to send. 而且,将跟踪标头不传输到RabbitMQ是绝对自然的:没有要发送的标头。

I believe that you can extract those headers in this @RequestMapping method and populate them to the AMQP message before sending. 我相信您可以在@RequestMapping方法中提取这些标头,然后在发送之前将它们填充到AMQP消息中。 See org.springframework.amqp.core.MessageBuilder . 参见org.springframework.amqp.core.MessageBuilder

I also think that Spring Cloud Sleuth should have some mechanism to obtain those headers, eg Tracer.currentSpan() : http://cloud.spring.io/spring-cloud-static/spring-cloud-sleuth/2.0.0.RC1/single/spring-cloud-sleuth.html#_current_span 我还认为Spring Cloud Sleuth应该具有某种机制来获取这些标头,例如Tracer.currentSpan()http : Tracer.currentSpan() /single/spring-cloud-sleuth.html#_current_span

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM