Using Existing Queues/Exchanges

默认情况下,绑定程序将自动设置一个主题交换,其名称派生自目标绑定属性 <prefix><destination> 的值。如果未指定,目标将默认为绑定名称。在绑定使用者时,将使用名称 <prefix><destination>.<group>(如果指定了 group 绑定属性)或在没有 group 时使用匿名、自动删除队列自动设置队列。队列将绑定到 exchange,其中“匹配全部”通配符路由键(#)适用于非分区绑定,或 <destination>-<instanceIndex> 适用于分区绑定。默认情况下,前缀是空 String。如果输出绑定使用 requiredGroups 指定,则将为每个 group 设置队列/绑定。

By default, the binder will automatically provision a topic exchange with the name being derived from the value of the destination binding property <prefix><destination>. The destination defaults to the binding name, if not provided. When binding a consumer, a queue will automatically be provisioned with the name <prefix><destination>.<group> (if a group binding property is specified), or an anonymous, auto-delete queue when there is no group. The queue will be bound to the exchange with the "match-all" wildcard routing key (#) for a non-partitioned binding or <destination>-<instanceIndex> for a partitioned binding. The prefix is an empty String by default. If an output binding is specified with requiredGroups, a queue/binding will be provisioned for each group.

有一些 rabbit 特定的绑定属性,允许您修改此默认行为。

There are a number of rabbit-specific binding properties that allow you to modify this default behavior.

如果您有希望使用的现有交换/队列,则可以按如下方式完全禁用自动设置,假设交换名为 myExchange,队列名为 myQueue

If you have an existing exchange/queue that you wish to use, you can completely disable automatic provisioning as follows, assuming the exchange is named myExchange and the queue is named 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

如果您希望绑定程序设置队列/交换,但希望使用此处讨论的默认值以外的方式进行设置,请使用以下属性。请参阅上面的属性文档以获取更多信息。

If you want the binder to provision the queue/exchange, but you want to do it using something other than the defaults discussed here, use the following properties. Refer to the property documentation above for more information.

  • 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'

autoBindDlqtrue 时,在声明死信交换机/队列时,有相似的属性。

There are similar properties used when declaring a dead-letter exchange/queue, when autoBindDlq is true.