Spring RabbitTemplate - How to create queues automatically upon send(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 - 如何在发送时自动创建队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Spring RabbitTemplate - 如何在发送时自动创建队列


- Eclipse 的最佳 XML 编辑器 2022-01-01
- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01
- 获取数字的最后一位 2022-01-01
- 未找到/usr/local/lib 中的库 2022-01-01
- 转换 ldap 日期 2022-01-01
- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01
- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01
- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01
- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01
- 如何指定 CORS 的响应标头? 2022-01-01