rabbitmq python 发送失败,错误“未知的递送标签”当我尝试使用pika(python)向RabbitMQ发送ack消息时发生...

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.adapters.blocking_connection import BlockingConnection

from pika import connection, credentials

import time

import threading

import random

from pika.adapters.select_connection import SelectConnection

from pika.connection import Connection

import traceback

def doWork(body, args, channel):

r = random.random()

time.sleep(r * 10)

try:

channel.basic_ack(delivery_tag=args.delivery_tag)

except :

traceback.print_exc()

auth = credentials.PlainCredentials(username="guest", password="guest")

params = connection.ConnectionParameters(host="localhost", credentials=auth)

conn = BlockingConnection(params)

channel = conn.channel()

while True:

time.sleep(0.03)

try:

method_frame, header_frame, body = channel.basic_get(queue="test_queue")

if method_frame.NAME == 'Basic.GetEmpty':

continue

t = threading.Thread(target=doWork, args=[body, method_frame, channel])

t.setDaemon(True)

t.start()

except Exception, e:

traceback.print_exc()

continue

Error desctiption:

Traceback (most recent call last):

File "C:\work\projects\mq\start.py", line 43, in

method_frame, header_frame, body = channel.basic_get(queue="test_queue")

File "C:\work\projects\mq\libs\pika\adapters\blocking_connection.py", line 318, in basic_get

self.basic_get_(self, self._on_basic_get, ticket, queue, no_ack)

File "C:\work\projects\mq\libs\pika\channel.py", line 469, in basic_get

no_ack=no_ack))

File "C:\work\projects\mq\libs\pika\adapters\blocking_connection.py", line 244, in send_method

self.connection.process_data_events()

File "C:\work\projects\mq\libs\pika\adapters\blocking_connection.py", line 94, in process_data_events

self._handle_read()

File "C:\work\projects\mq\libs\pika\adapters\base_connection.py", line 162, in _handle_read

self._on_data_available(data)

File "C:\work\projects\mq\libs\pika\connection.py", line 589, in _on_data_available

frame) # Args

File "C:\work\projects\mq\libs\pika\callback.py", line 124, in process

callback(*args, **keywords)

File "C:\work\projects\mq\libs\pika\adapters\blocking_connection.py", line 269, in _on_remote_close

frame.method.reply_text)

AMQPChannelError: (406, 'PRECONDITION_FAILED - unknown delivery tag 204')

Versions: pika 0.9.5, rabbitMQ 2.6.1

解决方案

The problem probably is that you're setting no_ack=True like this:

consumer_tag = channel.basic_consume(

message_delivery_event,

no_ack=True,

queue=queue,

)

And then acknowledging the messages:

channel.basic_ack(delivery_tag=args.delivery_tag)

You have to chose if you want to acknowledge or not and set the correct consume parameter.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值