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