spring - 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
...
推荐阅读
- google-sheets - 希望根据评分/分数创建过滤器,以用于播客的存档
- async-await - 为什么我的 catch 块没有执行?
- python - 我有一个随机数生成器,它从列表中获取一个字符串,但它不起作用
- r - 由于 URL 的“请求过多”,如何修复 R CMD 检查传入可行性的注意事项
- sql - KSQL WINDOW TUMBLING 产生奇怪的键
- c# - 属性值在 Razor 页面中重置 OnPost
- python - EOFError:压缩文件在到达流结束标记之前结束:使用 mnist 数据集
- python - 在 csv 文件的每一行中提取第一个不是 NaN 的元素
- python - 如何从嵌套字典中获取特定数组并在将它们更改为 ndarry、稀疏矩阵时保持其完整性
- node.js - firebase 身份验证未激活