簡體   English   中英

Spring Cloud Stream Reactive,如何為生產者設置路由密鑰

[英]Spring Cloud Stream Reactive, how to set routing key for producer

Spring Cloud Stream允許我們使用應用程序配置來設置路由密鑰,例如:

cloud.stream:
    default:
      contentType: "application/json"

    rabbit.bindings:
      output-resync-events:
        producer:
          prefix: "xxx."
          routing-key-expression: '''command.service'''

    bindings:
      output-resync-events:
        destination: "resync-requests"

但是我需要為每個發送的消息動態設置routing-key

我知道BinderAwareChannelResolver但這似乎僅允許您創建一個新的Exchange本身,而不是所需的結果。

我想使用相同的TopicExchange但使用不同的routing-key

另外,是否有可能使用Spring Cloud Stream的Reactive API實現這一目標?

它使用SPEL,因此您可以在運行時像這樣進行設置: messagingConfig.dataCopiedChannel().send(MessageBuilder.fromMessage(message).setHeader("type", "key-stuff").build()); 其中essagingConfig是用於將綁定注入到類中以發送消息的接口。

然后,您將application.properties配置為如下所示: spring.cloud.stream.bindings.data-copied.destination=data.topic.exchange spring.cloud.stream.rabbit.bindings.data-copied.producer.routing-key-expression=headers.type

這會將其通過“ key-stuff”路由鍵發送到data.topic.exchange。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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