【发布时间】:2020-06-30 06:54:41
【问题描述】:
import pika,traceback
import xyz
import time
from datetime import datetime
import ast
import error_mail
credentials = pika.PlainCredentials('xxxxx', 'xxxxxx')
parameters = pika.ConnectionParameters('xxxxxxxxx', 5672, '/',credentials,blocked_connection_timeout=400,heartbeat=600)
connection=pika.BlockingConnection(parameters)
channel = connection.channel()
channel.queue_declare(queue='xxxxxxxx')
def callback(ch, method, properties,body):
try:
print("*****data******")
print ("TIMESTAMP[#] {}".format(datetime.now()))
print(body)
xyz.yyy(body)
ch.basic_ack(delivery_tag=method.delivery_tag)
except Exception as e:
error = traceback.format_exc()
print(error)
error_mail.sent_Mail(error)
channel.basic_consume(
queue='xxxxxxxx', on_message_callback=callback)
print('Waiting for messages')
channel.start_consuming()
ch.basic_ack(delivery_tag=method.delivery_tag) 文件“/home/ubuntu/.local/lib/python2.7/site-packages/pika/adapters/blocking_connection.py”,第 2103 行,在 basic_ack self._impl.basic_ack(delivery_tag=delivery_tag,multiple=multiple) 文件“/home/ubuntu/.local/lib/python2.7/site-packages/pika/channel.py”,第 202 行,在 basic_ack self._raise_if_not_open() _raise_if_not_open 中的文件“/home/ubuntu/.local/lib/python2.7/site-packages/pika/channel.py”,第 1389 行 raise exceptions.ChannelWrongStateError('Channel is closed.') ChannelWrongStateError:通道已关闭。
【问题讨论】:
-
您好 Sharad,请提供您的代码。这样我们就可以为您提供帮助
-
嗨 Guillem,我在问题中更新了我的代码
-
提供一些上下文或解释要求将有助于我们更好地理解问题。
-
同时提供发布者代码也不错