[英]Spring boot integration of sleuth with jms
在我的 spring 启动应用程序中,spring sleuth 只适用于我的休息服务,而不适用于 @JmsListener。 互联网上的所有答案都可以追溯到 2016-17 年。 他们是 Spring Cloud Sleuth 检测所有 @JmsListener 注释方法以传播跟踪信息的一种方式吗?
目前还没有这种开箱即用的仪器。 你可以关注这个问题https://github.com/openzipkin/brave/issues/584因为一旦它在 Brave 中完成,它很可能会被添加到 Sleuth 中。
代替JmsTemplate
发送消息和JmsListener
接收消息,使用spring cloud stream发送和接收消息,一切都会自动处理。
发送信息:
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!");
}
}
接收消息:
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);
}
}
我正在使用 azure 服务总线,我的 .yml 配置是:
spring:
cloud:
azure:
servicebus:
connection-string: service-bus-url
stream:
bindings:
input:
destination: topic-name
group: topic-group
output:
destination: topic-name
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.