【发布时间】:2019-07-05 06:27:59
【问题描述】:
我在队列中收到的消息很大,回调函数需要 40-50 秒才能完成每条消息的处理。我在回调函数中有以下部分代码:
if ch.is_open:
print "channel is open: ", ch.is_open
print "Method delivery tag: ", method.delivery_tag
else:
print "Channel is closed"
ch.basic_ack(delivery_tag = method.delivery_tag)
我将始终从 if 语句中得到打印,如下所示:
Channel is open: True
Method delivery tag: x #Some number
但我在打印语句后得到以下错误,
File "receive_vb.py", line 200, in <module>
channel.start_consuming()
File "/usr/lib/python2.7/site-packages/pika/adapters/blocking_connection.py", line 1822, in start_consuming
self.connection.process_data_events(time_limit=None)
File "/usr/lib/python2.7/site-packages/pika/adapters/blocking_connection.py", line 758, in process_data_events
self._dispatch_channel_events()
File "/usr/lib/python2.7/site-packages/pika/adapters/blocking_connection.py", line 521, in _dispatch_channel_events
impl_channel._get_cookie()._dispatch_events()
File "/usr/lib/python2.7/site-packages/pika/adapters/blocking_connection.py", line 1445, in _dispatch_events
evt.body)
File "receive_vb.py", line 180, in callback
ch.basic_ack(delivery_tag = method.delivery_tag)
File "/usr/lib/python2.7/site-packages/pika/adapters/blocking_connection.py", line 2031, in basic_ack
self._flush_output()
File "/usr/lib/python2.7/site-packages/pika/adapters/blocking_connection.py", line 1292, in _flush_output
*waiters)
File "/usr/lib/python2.7/site-packages/pika/adapters/blocking_connection.py", line 477, in _flush_output
result.reason_text)
pika.exceptions.ConnectionClosed: (-1, "error(104, 'Connection reset by peer')")
对于第一条消息本身。所以我尝试在没有basic_ack 的情况下运行,消息被处理并在不同的消息中随机命中错误。第 2 条消息、第 474 条消息、第 181 条消息等等。
我尝试设置heartbeat_interval = 0 和一些大数字,比如heartbeat_interval =150 没有任何结果。我该如何解决这个问题。在此先感谢
以下是 RabbitMQ 日志
=INFO REPORT==== 5-Jul-2019::03:58:56 ===
accepting AMQP connection <0.17625.50> (10.168.37.108:45318 -> 10.168.37.108:5672)
=INFO REPORT==== 5-Jul-2019::03:58:56 ===
connection <0.17625.50> (10.168.37.108:45318 -> 10.168.37.108:5672): user 'guest' authenticated and granted access to vhost '/'
=ERROR REPORT==== 5-Jul-2019::03:59:26 ===
closing AMQP connection <0.17625.50> (10.168.37.108:45318 -> 10.168.37.108:5672):
{writer,send_failed,{error,timeout}}
【问题讨论】:
-
您能否也检查一下您的服务器设置(尝试查找类似 30 秒的任何内容 - 您在 30 秒后的超时看起来很可疑)。您不能从客户端覆盖服务器最大值(请参阅stackoverflow.com/questions/34721178/…)
-
我假设你没有做任何你不应该做的事情,比如使用线程
标签: python python-2.7 rabbitmq pika