Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I stop consuming in RabbitMQ with Java and Python clients?

I have both Java and Python clients that I use channel.basicConsume(). At some point I would like to stop those consumers without stopping the entire program.

In Python with Pika I have put channel.stop_consuming() calls in place, but those generate errors that I am ignoring. Seems to work

In Java I am not sure how to do this since stop_consume() doesn't appear to be available.

All the documentation I see talks about all the ways to create consumers, but I can't seem to find anything that shows how to stop them.

What is the best way to go about this?

like image 292
noisygecko Avatar asked Mar 21 '13 18:03

noisygecko


People also ask

How do I stop eating in RabbitMQ Python?

You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. def stop_consuming(self): """ From pika docs: Tell RabbitMQ that you would like to stop consuming by sending the Basic. Cancel RPC command. """ if self.

How do I stop RabbitMQ queue?

There are different options to delete queues in RabbitMQ. The web-based UI can be used via the RabbitMQ Management Interface, a queue policy can be added or a script can be used via rabbitmqadmin or HTTP API curl. A script or a queue policy is recommended to delete multiple queues.

How do I cancel a consumer in RabbitMQ?

cancel method by the broker, which they present to the consumer callback. For example, in our Java client, the Consumer interface has a handleCancel callback, which can be overridden by sub-classing the DefaultConsumer class: channel.

How do I delete a consumer in RabbitMQ queue?

You can kill connections to the RabbitMQ broker using the rabbitmqctl tool (see the man page) or by using the Web UI. You could also purge and delete the queue which belonged to the rogue consumer. However, you can't kill the consumer process itself using those tools.


1 Answers

The counterpart of basic_consume is basic_cancel. basic_cancel will fire the provided on_basic_cancel_ok callback function when rabbitmq has done the cancelation. Be prepared for a short period where you may still receive some messages.

See: Pika Channel

like image 80
itsafire Avatar answered Oct 23 '22 10:10

itsafire