Error “unknown delivery tag” occurs when i try ack messages to RabbitMQ using pika (python)

前端 未结 7 1047
别跟我提以往
别跟我提以往 2021-02-07 00:57

I want process messages in few threads but i\'m getting error during execute this code:

from __future__ import with_statement
import pika
import sys
from pika.ad         


        
7条回答
  •  无人及你
    2021-02-07 01:01

    For me, it was just that I told the queue I wasn't going to ack, then I acked.

    E.g. WRONG:

    channel.basic_consume(callback, queue=queue_name, no_ack=True)
    

    and then in my callback:

    def callback(ch, method, properties, body):
      # do stuff
      ch.basic_ack(delivery_tag = method.delivery_tag)
    

    RIGHT:

    channel.basic_consume(callback, queue=queue_name, no_ack=False)
    

    Bottom line: If you want to manually ack, set no_ack=False.

    From the docs:

    no_ack: (bool) if set to True, automatic acknowledgement mode will be used (see http://www.rabbitmq.com/confirms.html)

提交回复
热议问题