簡體   English   中英

sleuth 與 jms 的 Spring Boot 集成

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM