RabbitMQ:Pika连接被对等错误重置

时间:2019-07-05 06:27:59

标签: python python-2.7 rabbitmq pika

我要排队的消息很大,并且回调函数需要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}}

1 个答案:

答案 0 :(得分:0)

您的消息 太大 ,无法在RabbitMQ中的TCP写超时之前通过网络发送:

{writer,send_failed,{error,timeout}}

您应该压缩消息以使其更小,或将其拆分为多条消息。您的网络可能过载,或者服务器过载。或者,可能还有其他网络或服务器问题阻止邮件的快速传递-这里没有足够的信息来对其进行诊断。

作为最后的选择,您可以通过tcp_listen_options.send_timeout增加RabbitMQ的套接字写入超时,但这只会掩盖真正根本原因的症状。