Friday, 6 March 2015

Clear all queue in rabitmq

To clear a queue in rabbitmq or get no of jobs/consumers in/on the queue:

open python shell
enable a connection to the rabbitmq server
open a channel to the connection

import amqplib.client_0_8 as amqp 

host = <IP>
port = <PORT>
connection= amqp.Connection(host ='%s:%s' % (host, port),
                                                  userid = '<user>',
                                                  password = '<password>',
                                                  ssl = False,
                                                  virtual_host = 'rabbitvhost')  
channel = connection.channel()

name, jobs, consumers = channel.queue_declare(queue='queue_name', passive=True)
         

jobs # no of jobs in the queue
consumers # no of workers working on that queue


#Delete the queue
channel.queue_delete(queue='queue_name')

# Close the channel
channel.close() 
# Close our connection
connection.close()
happy programming :)

No comments:

Post a Comment