Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do a nack in Python

I tried to use these functions: - basic_nack - basic_reject but I couldn't do it

I want an example of the nack in python using pika with one of these functions: - basic_nack - basic_reject

 def callback(ch, method, properties, body):
     ch.basic_reject(delivery_tag=method.delivery_tag) 

return pika.exceptions.ChannelClosed: (406, 'PRECONDITION_FAILED - unknown delivery tag 1')
like image 877
Julian Linares Avatar asked Feb 15 '26 04:02

Julian Linares


1 Answers

From the pika documentation the message rejection can be done like this:

import pika

connection = pika.BlockingConnection()
channel = connection.channel()

for method_frame, properties, body in channel.consume('test'):
    channel.basic_reject(method_frame.delivery_tag)

Note that you need to pass delivery_tag value from method_frame object, which specifies which message is being rejected.

basic_reject() method also accepts additional argument requeue, which is by default True.

like image 152
zypox Avatar answered Feb 18 '26 01:02

zypox