Arpit
Arpit

Reputation: 112

Spring boot integration of sleuth with jms

In my spring boot application the spring sleuth only works with my rest service and not with @JmsListener. All the answer on the internet date back in 2016-17. Is their a way for Spring Cloud Sleuth to instrument all @JmsListener annotated methods in order to propagate tracing information ?

Upvotes: 2

Views: 4032

Answers (2)

Drunken Daddy
Drunken Daddy

Reputation: 8001

Instead to JmsTemplate to send messages and JmsListener to receive messages, use spring cloud stream to send and receive messages and everything will be automatically taken care of.

sent messages:

import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.support.GenericMessage;

@EnableBinding(Source.class)
public class MessageSender {

    @Autowired
    private final Source source;

    @GetMapping("/test")
    public void test() {
        this.source.output().send(new GenericMessage<>("Dummy Message"));
        log.info("Message sent!");
    }    

}

Receive messages:

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.cloud.stream.messaging.Sink;

@Slf4j
@EnableBinding(Sink.class)
public class TranscribedDataListener {

    @StreamListener(Sink.INPUT)
    public void handleMessage(String message) {
        log.info("Message received: {}", message);
    }

}

I'm using azure service bus, my .yml configuration is:

spring:
  cloud:
    azure:
      servicebus:
        connection-string: service-bus-url
    stream:
      bindings:
        input:
          destination: topic-name
          group: topic-group
        output:
          destination: topic-name

Upvotes: 0

Marcin Grzejszczak
Marcin Grzejszczak

Reputation: 11189

There is no such instrumentation coming out of the box at the moment. You can follow this issue https://github.com/openzipkin/brave/issues/584 cause once it's done in Brave it will be most likely added in Sleuth.

Upvotes: 3

Related Questions