How to delete a queue in rabbit mq

13,222

Solution 1

Since this seems to be a maintenance procedure, and not something you'll be doing routinely on your code, you should probably be using the RabbitMQ management plugin and delete the queue from there.

Anyway, you can delete it from pika with:

channel.queue_delete(queue='hello')

https://pika.readthedocs.org/en/latest/modules/channel.html#pika.channel.Channel.queue_delete

Solution 2

The detailed answer is as follows (with reference to above very helpful and useful answer)

import pika


connection = pika.BlockingConnection(pika.ConnectionParameters(
               'localhost'))
channel = connection.channel()


channel.queue_delete(queue='hello')

connection.close()

Solution 3

GUI rabbitMQ mgm't made that easy

$ sudo rabbitmq-plugins enable rabbitmq_management

http://localhost:15672/#/queues

Username : guest

password : guest


inspired by this

Share:
13,222

Related videos on Youtube

Shweta B. Patil
Author by

Shweta B. Patil

Updated on September 15, 2022

Comments

  • Shweta B. Patil
    Shweta B. Patil over 1 year

    I am using rabbitmctl using pika library. I use the following code to create a Producer

    #!/usr/bin/env python
    import pika
    import time
    import json
    import datetime
    
    
    connection = pika.BlockingConnection(pika.ConnectionParameters(
            host='localhost'))
    channel = connection.channel()
    
    
    
    channel.queue_declare(queue='hello')
    
    def callback(ch, method, properties, body):
        #print " current time: %s "  % (str(int((time.time())*1000)))
    
        print body
    
    channel.basic_consume(callback,
                          queue='hello',
                          no_ack=True)
    
    
    channel.start_consuming()
    

    Since I create an existing queue everytime (Over-write the creation of queue in case if queue is not created) The queue has been corrupted due to this.and now I want to delete the queue..how do i do that?