如何在spring cloud stream rabbitmq中使用rabbitmq的当前交换和队列名称 [英] How to use current exchange and queue name of rabbitmq with spring cloud stream rabbitmq

查看:130
本文介绍了如何在spring cloud stream rabbitmq中使用rabbitmq的当前交换和队列名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将旧版 Spring 应用程序切换到 Spring Boot.

I'm switching legacy spring application to spring boot.

使用 spring cloud stream rabbitmq 迁移 rabbitmq 代码存在问题.

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

在旧系统中,rabbitmq 队列是通过提供交换、路由密钥和队列名称来设置的.

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

例如,

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

所以在rabbitmq管理视图中我可以看到交换是 mq-test.topic,队列是 aa.mq-test.

So in rabbitmq management view I can see that exchange is mq-test.topic, queue is aa.mq-test.

但是对于 Spring Cloud 流,队列名称点缀着目的地,如

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

mq-test.topic.aa.mq-test

mq-test.topic.aa.mq-test

我的 spring 云流属性是这样的.

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

我也使用了 routingKeyExpression 属性来代表 bindingRoutingKey 但结果是一样的.

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.

如何使用 Spring Cloud 流保持交换/队列命名?

How can I keep the exchange/queue naming with spring cloud stream?

感谢任何帮助.

推荐答案

查看 RabbitMQ Binder 文档 使用现有队列/交换.

See the RabbitMQ Binder documentation Using Existing Queues/Exchanges.

默认情况下,活页夹将自动提供主题交换,其名称源自目标绑定属性的值.如果未提供,目标默认为绑定名称.绑定消费者时,队列将自动提供名称.(如果指定了组绑定属性),或者没有组时的匿名自动删除队列.队列将被绑定到具有match-all"的交换.通配符路由键 (#) 用于非分区绑定或 - 用于分区绑定.前缀默认为空字符串.如果使用 requiredGroups 指定了输出绑定,则将为每个组提供一个队列/绑定.

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.

如果您希望使用现有的交换/队列,则可以按如下方式完全禁用自动配置,假设交换名为 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.binding..destination=myExhange

spring.cloud.stream.binding..group=myQueue

spring.cloud.stream.rabbit.bindings.<绑定名称>.consumer.bindQueue=false

spring.cloud.stream.rabbit.bindings.<绑定名称>.consumer.declareExchange=false

spring.cloud.stream.rabbit.bindings..consumer.queueNameGroupOnly=true

...

这篇关于如何在spring cloud stream rabbitmq中使用rabbitmq的当前交换和队列名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆