此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 spring-cloud-stream 4.1.4! |
使用现有队列/交易所
默认情况下,Binder 将自动配置主题交换,其名称派生自 destination binding 属性的值<prefix><destination>
.
如果未提供,则 destination 默认为绑定名称。
绑定 Consumer 时,队列会自动预置名称<prefix><destination>.<group>
(如果group
binding 属性)或匿名自动删除队列(如果没有group
.
队列将使用 “match-all” 通配符路由键 () 绑定到交换,以实现非分区绑定,或者#
<destination>-<instanceIndex>
对于分区绑定。
前缀为空String
默认情况下。
如果使用requiredGroups
,将为每个组配置一个队列/绑定。
有许多特定于 rabbit 的绑定属性允许您修改此默认行为。
如果您有要使用的现有 Exchange/队列,则可以按如下方式完全禁用自动供应,假设该 Exchange 名为myExchange
队列名为myQueue
:
-
spring.cloud.stream.bindings.<binding name>.destination=myExchange
-
spring.cloud.stream.bindings.<binding name>.group=myQueue
-
spring.cloud.stream.rabbit.bindings.<binding name>.consumer.bindQueue=false
-
spring.cloud.stream.rabbit.bindings.<binding name>.consumer.declareExchange=false
-
spring.cloud.stream.rabbit.bindings.<binding name>.consumer.queueNameGroupOnly=true
如果您希望 Binders 预置 queue/exchange,但您希望使用此处讨论的默认值以外的其他功能来执行此作,请使用以下属性。 有关更多信息,请参阅上面的属性文档。
-
spring.cloud.stream.rabbit.bindings.<binding name>.consumer.bindingRoutingKey=myRoutingKey
-
spring.cloud.stream.rabbit.bindings.<binding name>.consumer.exchangeType=<type>
-
spring.cloud.stream.rabbit.bindings.<binding name>.producer.routingKeyExpression='myRoutingKey'
在声明死信交换/队列时,也有类似的属性,当autoBindDlq
是true
.