简体   繁体   中英

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.

Do we have any option in spring rabbit that can delete the queue based on the queue configuration in spring file .

for eg : i am expecting rabbit:deletequeue name="a" and again create 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.

Correct me if i am wrong else please guide me with a solution

Srinivas

You can do it using AmqpAdmin

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.

You can't do it with configuration but, you can stop the admin from declaring the queues automatically by setting 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM