简体   繁体   English

如何使用springm stream rabbitmq的rabbitmq的当前交换和队列名称

[英]How to use current exchange and queue name of rabbitmq with spring cloud stream rabbitmq

I'm switching legacy spring application to spring boot. 我正在将传统的spring应用程序切换到spring boot。

There is an issue with migrating rabbitmq code using spring cloud stream rabbitmq. 使用spring cloud stream rabbitmq迁移rabbitmq代码存在问题。

In the legacy system, rabbitmq queue is set up by giving exchange, routingKey and queue name. 在遗留系统中,通过提供exchange,routingKey和队列名称来设置rabbitmq队列。

For instance, 例如,

exchange name = mq-test.topic
routingKey = mq-test
queueName = aa.mq-test

So in rabbitmq management view I can see that exchange is mq-test.topic, queue is aa.mq-test. 所以在rabbitmq管理视图中,我可以看到交换是mq-test.topic,queue是aa.mq-test。

But with spring cloud stream, queue name is dotted with destination like 但是对于春天云流,队列名称点缀着目的地

mq-test.topic.aa.mq-test MQ-test.topic.aa.mq测试

My properties for spring cloud stream is like this. 我对spring spring stream的属性是这样的。

spring.cloud.stream.bindings.channelName.destination=mq-test.topic
spring.cloud.stream.bindings.channelName.producer.bindingRoutingKey=mq-test
spring.cloud.stream.bindings.channelName.producer.requiredGroups=aa.mq-test

I also used routingKeyExpression property on behalf of bindingRoutingKey but the result is the same. 我还代表bindingRoutingKey使用了routingKeyExpression属性,但结果是一样的。

There are legacy applications consuming the data via the queue names and my new application is only producing so I can't change the exchange and queue name policy. 有遗留应用程序通过队列名称消耗数据,而我的新应用程序只生成,因此我无法更改交换和队列名称策略。

How can I keep the exchange/queue naming with spring cloud stream? 如何使用spring cloud stream保持交换/队列命名?

any help is appreciated. 任何帮助表示赞赏。

See the RabbitMQ Binder documentation Using Existing Queues/Exchanges . 请参阅RabbitMQ Binder文档使用现有队列/交换

By default, the binder will automatically provision a topic exchange with the name being derived from the value of the destination binding property . 默认情况下,活页夹将自动设置主题交换,其名称是从目标绑定属性的值派生的。 The destination defaults to the binding name, if not provided. 如果未提供,则目标默认为绑定名称。 When binding a consumer, a queue will automatically be provisioned with the name . 绑定使用者时,将自动为队列配置名称。 (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 - for a partitioned binding. 对于非分区绑定,队列将绑定到具有“match-all”通配符路由密钥(#)的交换,或者 - 对于分区绑定。 The prefix is an empty String by default. 默认情况下,前缀为空String。 If an output binding is specified with requiredGroups, a queue/binding will be provisioned for each group. 如果使用requiredGroups指定了输出绑定,则将为每个组配置队列/绑定。

There are a number of rabbit-specific binding properties that allow you to modify this default behavior. 有许多特定于兔子的绑定属性允许您修改此默认行为。

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: 如果您希望使用现有的交换/队列,则可以完全禁用自动配置,假设交换机名为myExchange且队列名为myQueue:

spring.cloud.stream.binding.<binding name>.destination=myExhange

spring.cloud.stream.binding.<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

... ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM