简体   繁体   English

将Spring Cloud Sleuth与Spring Boot Amqp集成

[英]Integrating Spring Cloud Sleuth with Spring boot amqp

Looking for an example that shows integrating spring cloud sleuth with spring boot amqp (rabbit) publisher and subscriber. 寻找一个示例,该示例显示了将Spring Cloud Sleuth与Spring Boot Amqp(兔子)发布者和订阅者集成在一起。

I do see the following messages in the log 我确实在日志中看到以下消息

2016-10-21 08:35:15.708 INFO [producer,9148f56490e5742f,943ed050691842ab,false] 30928 --- [nio-8080-exec-1] abccontrollers.MessagingController : Received Request to pulish with Activity OrderShipped 2016-10-21 08:35:15.730 INFO [producer,9148f56490e5742f,943ed050691842ab,false] 30928 --- [nio-8080-exec-1] abcservice.ProducerService : Message published 2016-10-21 08:35:15.708 INFO [producer,9148f56490e5742f,943ed050691842ab,false] 30928 --- [nio-8080-exec-1] abccontrollers.MessagingController:收到带有Activity OrderShipped的请求推送2016-10-21 08 :35:15.730 INFO [生产商,9148f56490e5742f,943ed050691842ab,false] 30928 --- [nio-8080-exec-1] abcservice.ProducerService:消息已发布

When I look at messages on Queue, I don't see traceId or any other details added to the header. 当我查看Queue上的消息时,看不到traceId或任何其他添加到标题的详细信息。 Should I use MessagePostProcessor to add these to the header? 我应该使用MessagePostProcessor将它们添加到标题吗?

Also what should be done on the receiving service? 另外,接收服务应该怎么做?

Using Spring AMQP you can set MessagePostProcessor on the RabbitTemplate using the setBeforePublishPostProcessors method. 使用Spring AMQP可以设置MessagePostProcessorRabbitTemplate使用setBeforePublishPostProcessors方法。

We implemented the org.springframework.amqp.core.MessagePostProcessor and Overrided the postProcessMessage method this way: 我们实现了org.springframework.amqp.core.MessagePostProcessor并以此方式覆盖了postProcessMessage方法:

@Override
public org.springframework.amqp.core.Message postProcessMessage(org.springframework.amqp.core.Message message)
        throws AmqpException {
    MessagingMessageConverter converter = new MessagingMessageConverter();
    MessageBuilder<?> mb = MessageBuilder.fromMessage((Message<?>) converter.fromMessage(message));
    inject(tracer.getCurrentSpan(), mb);
    return converter.toMessage(mb.build(), message.getMessageProperties());
}

The inject method can now set all the required headers on the message, and it will be passed to the rabbitMq with the changes. 现在, inject方法可以在消息上设置所有必需的标头,并将其与更改一起传递给rabbitMq。
You have a great example of how to implement such inject method in org.springframework.cloud.sleuth.instrument.messaging.MessagingSpanInjector 您有一个很好的示例,说明如何在org.springframework.cloud.sleuth.instrument.messaging.MessagingSpanInjector实现这种inject方法

We are using v1.1.1 of spring-cloud-sleuth-stream so my example is based on this version, in next release(1.2) it will be easier. 我们使用的是spring-cloud-sleuth-stream v1.1.1,因此我的示例基于该版本,在下一发行版(1.2)中将更加容易。

We don't instrument Spring AMQP out of the box. 我们不会开箱即用地检测Spring AMQP。 You can however use Spring Integration or Spring Cloud Stream that we do support and then everything will work out of the box. 但是,您可以使用我们支持的Spring Integration或Spring Cloud Stream,然后一切都将立即可用。 If you need to use Spring AMQP for some reason you'll have to instrument the code yourself (and sends us a PR ;) ). 如果出于某种原因需要使用Spring AMQP,则必须自己检测代码(并向我们发送PR;))。

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

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