Spring Cloud Sleuth integration with Spring amqp download

Look for an example showing the integration of spring cloud detective with spring amqp downloader (rabbit) publisher and subscriber.

I see the following log messages

2016-10-21 08: 35: 15.708 INFO [manufacturer, 9148f56490e5742f, 943ed050691842ab, false] 30928 --- [nio-8080-exec-1] abccontrollers.MessagingController: received impulse request with OrderShipped activity 2016-10-21 08 : 35: 15.730 INFO [manufacturer, 9148f56490e5742f, 943ed050691842ab, false] 30928 --- [nio-8080-exec-1] abcservice.ProducerService: message posted

When I look at the messages in the queue, I do not see traceId or any other data added to the header. Should I use MessagePostProcessor to add them to the header?

And what should be done at the front desk?

+4
source share
2 answers

We do not use Spring AMQP out of the box. However, you can use Spring Integration or Spring Cloud Stream, which we support, and then everything will work out of the box. If you need to use Spring AMQP, for some reason you will need to enter the code yourself (and send us PR;)).

+1
source

Using Spring AMQP, you can set MessagePostProcessorin RabbitTemplateusing the setBeforePublishPostProcessors method .

We implemented the method org.springframework.amqp.core.MessagePostProcessorand Overrided the postProcessMessageas follows:

@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());
}

inject , rabbitMq .
, inject org.springframework.cloud.sleuth.instrument.messaging.MessagingSpanInjector

v1.1.1 spring -cloud-sleuth-stream, , (1.2) .

+1

Source: https://habr.com/ru/post/1658443/


All Articles