【问题标题】:Rabbitmq error: [Errno 10054] An existing connection was forcibly closed by the remote hostRabbitmq 错误:[Errno 10054] 现有连接被远程主机强行关闭
【发布时间】:2016-08-18 15:06:27
【问题描述】:

我在 Python 中使用 Kombu 来使用持久的 RabbitMQ 队列。

在 Windows 中只有一个消费者在消费队列。此消费者产生以下错误:

Traceback (most recent call last):
  File ".\consumer_windows.py", line 66, in <module>
    message.ack()
  File "C:\Users\Administrator\Anaconda2\lib\site-packages\kombu\message.py", line 88, in ack
    self.channel.basic_ack(self.delivery_tag)
  File "C:\Users\Administrator\Anaconda2\lib\site-packages\amqp\channel.py", line 1584, in basic_ack
    self._send_method((60, 80), args)
  File "C:\Users\Administrator\Anaconda2\lib\site-packages\amqp\abstract_channel.py", line 56, in _send_method
    self.channel_id, method_sig, args, content,
  File "C:\Users\Administrator\Anaconda2\lib\site-packages\amqp\method_framing.py", line 221, in write_method
    write_frame(1, channel, payload)
  File "C:\Users\Administrator\Anaconda2\lib\site-packages\amqp\transport.py", line 182, in write_frame
    frame_type, channel, size, payload, 0xce,
  File "C:\Users\Administrator\Anaconda2\lib\socket.py", line 228, in meth
    return getattr(self._sock,name)(*args)
error: [Errno 10054] An existing connection was forcibly closed by the remote host

任何时候队列中最多有 500 条消息。每条消息都很小,但它是一项任务,最多需要 10 分钟才能完成(尽管每条消息通常需要不到 5 分钟)。

我已尝试重启消费者、RabbitMQ 服务器并删除队列,但错误仍然存​​在。

我见过 this question 但是 the answer 是 2010 年的,我的 rabbitmq.log 有不同的条目:

=ERROR REPORT==== 24-Apr-2016::08:26:20 ===
closing AMQP connection <0.6716.384> (192.168.X.X:59602 -> 192.168.Y.X:5672):
{writer,send_failed,{error,timeout}}

rabbitmq-sasl.log 中没有最近的事件。

为什么会发生这个错误,我该如何防止它发生?

【问题讨论】:

标签: python rabbitmq kombu


【解决方案1】:

我仍在寻找答案。与此同时,我重新启动了与我的 rabbit 服务器的连接:

while True:
    try:
​
        connection = pika.BlockingConnection(params)
        channel = connection.channel() # start a channel
        channel.queue_declare(queue=amqp_q, durable=True) # Declare a queue
        ...
​
    except pika.exceptions.ConnectionClosed:
        print('connection closed... and restarted')

【讨论】:

    【解决方案2】:

    我在托管的 MySQL 服务器上遇到了同样的问题... 我开始明白,如果我们长时间打开连接或长时间未修改,就会发生这种情况.. 如果您的程序在整个程序运行之前打开数据库或其他任何东西,请使其打开数据库写入所有内容并关闭并重复

    我不知道rabbitmq到底是什么,但我认为你写为标题的错误可能是这个原因

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-02-07
      • 1970-01-01
      • 2011-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多