Shweta B. Patil
Shweta B. Patil

Reputation: 1169

How to delete a queue in rabbit mq

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?

Upvotes: 21

Views: 18920

Answers (3)

bereket gebredingle
bereket gebredingle

Reputation: 12996

GUI rabbitMQ mgm't made that easy

$ sudo rabbitmq-plugins enable rabbitmq_management

http://localhost:15672/#/queues

Username : guest

password : guest


inspired by this

Upvotes: 2

Shweta B. Patil
Shweta B. Patil

Reputation: 1169

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()

Upvotes: 8

Pedro Werneck
Pedro Werneck

Reputation: 41878

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

Upvotes: 36

Related Questions