我正在使用pika Python库连接到本地的RabbitMQ服务器。
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
兔子队列服务器日志
=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。
我不明白发生了什么,请给我解释一下。