SpringCloud Stream整合RocketMQ 2022

前幾天剛看了別人的教程 學了@Input @OutPut 這種寫法,然后今天看了個開源項目里面已經用了SpringCloud Stream3.0.x新特性,@Input @OutPut 方式已經過時 淘汰了函數式調用...我丟!又要學!

一、yml配置

--- # rocketmq 配置
spring:
  cloud:
    stream:
      function:
        # 重點配置 與 binding 名與消費者對應,多個可以使用;
        definition: demo
      rocketmq:
        binder:
          # rocketmq 地址
          name-server: localhost:9876
      bindings:
        demo-out-0:
          content-type: application/json
          destination: stream-test-topic
          group: test-group
          binder: rocketmq
        demo-in-0:
          content-type: application/json
          destination: stream-test-topic
          group: test-group
          binder: rocketmq

二、生產者

    @Autowired
    private StreamBridge streamBridge;

    public void streamTestMsg(String msg){
        // 構建消息對象
        TestMessaging testMessaging = new TestMessaging()
                .setMsgId(UUID.randomUUID().toString())
                .setMsgText(msg);
        streamBridge.send("demo-out-0", MessageBuilder.withPayload(testMessaging).build());
    }

三、消費者

    @Bean
    Consumer<TestMessaging> demo() {
        log.error("初始化訂閱");
        return msg -> {
            log.error("通過stream消費到消息 => {}", msg.toString());
        };
    }

總結

直接 簡單了10倍,kafka之類全都一樣。

?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容