[英]Can i delete a queue using spring configuration on Rabbit MQ?
I am changing some exchange for a queue on RabbitMQ , but if the queue already exists i need to delete manually then only spring will create the queue with the changed exchange. 我正在为RabbitMQ上的队列更改某些交换,但是如果该队列已经存在,则需要手动删除,那么只有spring会使用更改后的交换创建队列。
Do we have any option in spring rabbit that can delete the queue based on the queue configuration in spring file . Spring Rabbit中是否有任何选项可以根据spring文件中的队列配置删除队列。
for eg : i am expecting rabbit:deletequeue name="a" and again create rabbit:queue name="a" 例如:我期望Rabbit:deletequeue name =“ a”并再次创建Rabbit:queue name =“ a”
So it will delete the queue and then it will create again with new properties that will eliminate the manual deletion of queue on Rabbit MQ. 因此,它将删除队列,然后使用新属性再次创建,这将消除在Rabbit MQ上手动删除队列的情况。
Correct me if i am wrong else please guide me with a solution 纠正我,如果我错了,否则请指导我解决方案
Srinivas 斯里尼瓦斯
You can do it using AmqpAdmin 您可以使用AmqpAdmin来完成
3.8 http://docs.spring.io/spring-amqp/reference/html/amqp.html 3.8 http://docs.spring.io/spring-amqp/reference/html/amqp.html
public interface AmqpAdmin {
// Exchange Operations
void declareExchange(Exchange exchange);
void deleteExchange(String exchangeName);
// Queue Operations
Queue declareQueue();
String declareQueue(Queue queue);
void deleteQueue(String queueName);
void deleteQueue(String queueName, boolean unused, boolean empty);
void purgeQueue(String queueName, boolean noWait);
// Binding Operations
void declareBinding(Binding binding);
void removeBinding(Binding binding);
Properties getQueueProperties(String queueName);
}
Or just create a Queue with autoDelete option. 或仅使用autoDelete选项创建队列。
You can't do it with configuration but, you can stop the admin from declaring the queues automatically by setting auto-startup="false"
. 您无法通过配置来做到这一点,但是可以通过设置auto-startup="false"
来阻止管理员自动声明队列。
Then, in your own bean (implement SmartLifeCycle
, return Integer.MAX_VALUE
from getPhase()
and, in start()
use the rabbit admin to delete the queue(s). Then invoke its initialize()
method to declare everything in the context. 然后,在您自己的bean中(实现SmartLifeCycle
,从getPhase()
返回Integer.MAX_VALUE
,在start()
使用getPhase()
admin删除队列。然后调用其initialize()
方法在上下文中声明所有内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.