简体   繁体   中英

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

I'm switching legacy spring application to spring boot.

There is an issue with migrating rabbitmq code using spring cloud stream rabbitmq.

In the legacy system, rabbitmq queue is set up by giving exchange, routingKey and queue name.

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.

But with spring cloud stream, queue name is dotted with destination like

mq-test.topic.aa.mq-test

My properties for spring cloud stream is like this.

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.

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?

any help is appreciated.

See the RabbitMQ Binder documentation Using Existing Queues/Exchanges .

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. 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.

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:

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

...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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