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?
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With