RabbitMQ连接关闭异常

2024-10-03 19:24:03 发布

您现在位置:Python中文网/ 问答频道 /正文

文件“/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking”_连接.py“,第218行,处理中的数据事件 提高异常连接关闭() pika.exceptions.ConnectionClosed在

def main():
print('zmq', zmq.zmq_version(), zmq.pyzmq_version())
zctx = zmq.Context()
socket_rep = zctx.socket(zmq.REP)
socket_rep.bind('tcp://*:'+str(dragon_pb2.tcpport.Value('stage1_server_request_storage')))

RabbitReceiver(host='localhost', on_receive_callback=handle_massage, exchange_name='exchange1', queue_name='name1')

while True:
    try:
        request = socket_rep.recv_json()
        status, result = get_records(request)
        if result is None:
            result = {}
        # print result
        socket_rep.send_multipart([status, blosc.compress(json.dumps(result), 9)])

    except keyboardInterrupt:
        print("Buy")
        sys.exit()


 if __name__ == '__main__':
      main()


class RabbitReceiver(AbstractReceiver):
    def __init__(self, on_receive_callback, host, exchange_name, queue_name):
        AbstractReceiver.__init__(self, host=host, on_receive_callback=on_receive_callback)
        connection = pika.BlockingConnection(pika.ConnectionParameters(
            host=AbstractReceiver.host))
        channel = connection.channel()
        channel.exchange_declare(exchange=exchange_name,
                                 type='fanout')

        channel.queue_declare(queue=queue_name, durable=True)

        channel.queue_bind(exchange=exchange_name,
                           queue=queue_name)
        channel.basic_consume(self.on_message_receive,
                      queue=queue_name)

        channel.start_consuming()

    def on_message_receive(self, channel, method, header, body):
        AbstractReceiver.on_message_receive(self, body)
        channel.basic_ack(delivery_tag = method.delivery_tag)

我知道RabbitReceiver创建后的代码可能不会执行,因为start_ncuming正在阻塞。但现在我不担心这个。 我想知道它为什么会给我这个错误? 可能我错过了什么。。。在


Tags: nameselfhostexchangequeueoncallbackchannel