gpt4 book ai didi

python - 一段时间后由于某种原因在 rabbitmq 中关闭了连接

转载 作者:太空宇宙 更新时间:2023-11-03 13:44:56 24 4
gpt4 key购买 nike

我正在使用 pika python 库连接到本地主机上的 rabbitmq-server。

class BaseRabbitSender(MessageSender):
__metaclass__ = ABCMeta

def __init__(self, host):
self.node = BaseMessagingNode(host)
self.connection = pika.BlockingConnection(pika.ConnectionParameters(
host=host))
self.channel = self.connection.channel()

@abstractmethod
def send_message(self, message):
pass

def close_connection(self):
self.connection.close()


class DirectRabbitSender(BaseRabbitSender):
def __init__(self, host, queue_name):
super(DirectRabbitSender, self).__init__(host)
self.queue_name = queue_name
self.channel.queue_declare(queue=queue_name, durable=True)

def send_message(self, message):
self.channel.basic_publish(exchange='',
routing_key=self.queue_name,
body=message,
properties=pika.BasicProperties(
delivery_mode=2,
))

def close_connection(self):
self.connection.close()

出于某种原因,在相当长的一段时间后(比如几天)我收到了错误。

 File "build/bdist.linux-x86_64/egg/pika/adapters/blocking_connection.py", line 560, in basic_publish
(properties, body), False)
File "build/bdist.linux-x86_64/egg/pika/adapters/blocking_connection.py", line 1147, in _send_method
self.connection.send_method(self.channel_number, method_frame, content)
File "build/bdist.linux-x86_64/egg/pika/adapters/blocking_connection.py", line 267, in send_method
self._send_method(channel_number, method_frame, content)
File "build/bdist.linux-x86_64/egg/pika/connection.py", line 1504, in _send_method
self._send_frame(frame.Header(channel_number, length, content[0]))
File "build/bdist.linux-x86_64/egg/pika/adapters/blocking_connection.py", line 410, in _send_frame
self.process_data_events()
File "build/bdist.linux-x86_64/egg/pika/adapters/blocking_connection.py", line 236, in process_data_events
raise exceptions.ConnectionClosed()
ConnectionClosed

Rabbitmq 服务器日志

=INFO REPORT==== 3-Mar-2014::15:11:03 ===
accepting AMQP connection <0.26625.0> (127.0.0.1:41846 -> 127.0.0.1:5672)

=ERROR REPORT==== 3-Mar-2014::15:38:12 ===
closing AMQP connection <0.326.0> (127.0.0.1:58580 -> 127.0.0.1:5672):
{heartbeat_timeout,running}

=WARNING REPORT==== 3-Mar-2014::16:11:04 ===
closing AMQP connection <0.26625.0> (127.0.0.1:41846 -> 127.0.0.1:5672):
connection_closed_abruptly

=INFO REPORT==== 3-Mar-2014::16:11:05 ===
accepting AMQP connection <0.27016.0> (127.0.0.1:37776 -> 127.0.0.1:5672)

=ERROR REPORT==== 3-Mar-2014::17:41:05 ===
closing AMQP connection <0.27016.0> (127.0.0.1:37776 -> 127.0.0.1:5672):
{heartbeat_timeout,running}

它在 ubuntu 13.10 上运行。 RabbitMQ 3.1.3

我不明白发生了什么。你能解释一下吗?

最佳答案

相关日志行:{heartbeat_timeout,running}。

有些东西阻止 BlockingConnection 发送心跳,因此 RabbitMQ 认为您的客户端无法访问或已死。您有 3 个选择:

  • 避免阻塞行为
  • 增加心跳间隔
  • 尝试替代连接实现,例如 Tornado 。

关于python - 一段时间后由于某种原因在 rabbitmq 中关闭了连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22192909/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com