Search code examples
pythonrabbitmqpika

How to identify the message in a delivery notification?


In pika, I have called channel.confirm_delivery(on_confirm_delivery) in order to be informed when messages are delivered successfully (or fail to be delivered). Then, I call channel.basic_publish to publish the messages. Everything is performed asynchronously.

How, when the on_confirm_delivery callback is called, do I find what the concerned message? In the parameters, The only information that changes in the object passed as a parameter to the callback is delivery_tag, which seems to be an auto-incremented number. However, basic_publish doesn't return any delivery tag.

In other words, if I call basic_publish twice, how do I know, when I receive an acknowledgement, whether it's the first or the second message which is acknowledged?


Solution

  • From RabbitMQ document, I find:

    Delivery tags are monotonically growing positive integers and are presented as such by client libraries.

    So you can keep a growing integer in your code per channel, set it to 0 when channel is open, increase it when you publish a message. Then this integer will be same as the delivery_tag.