Reputation: 1831
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?
Upvotes: 5
Views: 9153
Reputation: 6083
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
Upvotes: 9
Reputation: 7624
You should be consuming in a Thread so just interrupt the that thread and leave the rest of your program running
Thread t = new Thread(){
public void run(){
//consumer is in here
}
};
t.start();
// somewhere else later
t.interrupt();
You may need to make the Thread t
available elsewhere buy having it as a field of the object as opposed to a local variable
Upvotes: -2