Spring RabbitTemplate-如何在发送时自动创建队列 [英] Spring RabbitTemplate - How to create queues automatically upon send

查看:233
本文介绍了Spring RabbitTemplate-如何在发送时自动创建队列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将RabbitMQ与Spring的RabbitTemplate一起使用.

I am using RabbitMQ together with Spring's RabbitTemplate.

使用模板发送方法将消息发送到队列时,我希望自动创建/声明队列(如果尚不存在).

When sending messages to queues using the template send methods, I want the queue to automatically be created/declared if it is not already exists.

这非常重要,因为根据我们的业务逻辑,队列名称是在运行时生成的,因此我无法提前声明它们.

It is very important since according to our business logic queue names are generated on run-time and I cannot declare them in advance.

以前,我们使用JmsTemplate和任何调用来发送或接收自动创建的队列.

Previously we have used JmsTemplate and any call to send or receive automatically created the queue.

推荐答案

是的,您可以使用 RabbitAdmin admin.getQueueProperties()来查看队列是否存在.和 admin.declareQueue(new Queue(...))添加一个队列.为了避免每次发送的开销,您可能应该跟踪已经检查过/创建过的一个.

Yes, you can use a RabbitAdmin and admin.getQueueProperties() to see if the queue exists and admin.declareQueue(new Queue(...)) to add a queue. You should probably keep track of which one's you've already checked/created in order to avoid the overhead on every send.

您还可以使用管理员添加交换并将队列绑定到它们.

You can also add exchanges and bind queues to them with the admin.

这篇关于Spring RabbitTemplate-如何在发送时自动创建队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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