Modify and re-queue a message using pika on python

Question:

I’m using Pika/RabbitMQ lib for processing messages in a python 3.8 project. When processing the messages the function can fail due to several reasons. There are a few cases when the message can be recovered in part if modified. I’m currently creating a new message with the modified body and queuing it. This is not ideal since the processor is the one re-queuing a message that it did not send.

I’m wondering if there’s a way to modify the original message body and send a basic_nack in order to re-queue a modified message to be processed again. In this way I don’t have to recreate the message broker and message sender.

Asked By: zetacu

||

Answers:

I’m wondering if there’s a way to modify the original message body and send a basic_nack in order to re-queue a modified message to be processed again

No this is not possible with any AMQP broker. Creating a new message with the modified body and publishing it is the correct action to take.


NOTE: Team RabbitMQ monitors the rabbitmq-users mailing list and only sometimes answers questions on StackOverflow.

Answered By: Luke Bakken
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.