pythonrabbitmqpika

Acknowledging a message inside the consumer_callback in Pika / RabbitMQ


I have a setup where I would like to be able to acknowledge a pika message after a couple of lines inside the consumer_callback and then carry on with some more time intensiv tasks. I have written some code that does exactly this, but it seems, that the acknowledgement only gets sent out after the consumer_callback returns. I'm using pika 10 with the SelectConnection.

I'm wondering if there is a way to achieve this. The methods I've tried so far are:

Any help is greatly appreciated. Maybe I need a different connection type?


Solution

  • Upgrade to Pika 0.12.0 and follow the example in this code, or do something similar: link.

    I realize the example using a different connection type, but you get the idea. Pika's ioloop must be running in one thread, and your time intensive task can carry on in another thread.