【发布时间】:2016-09-16 04:59:22
【问题描述】:
我尝试使用 RabbitMQ 发送和接收消息。我没有计算机科学背景,我使用的术语可能不是很准确。
我尝试复制教程文件: 提交我的html表单时,我的python脚本(cgi)消息正在提交到队列
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
channel = connection.channel()
channel.queue_declare(queue='task_queue', durable=True)
message = PN
channel.basic_publish(exchange='',
routing_key='task_queue',
body=message,
properties=pika.BasicProperties(
delivery_mode = 2, # make message persistent
))
connection.close()
我的接收器正在运行:
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
channel = connection.channel()
channel.queue_declare(queue='task_queue', durable=True)
print(' [*] Waiting for messages. To exit press CTRL+C')
def callback(ch, method, properties, body):
print(" [x] Received Project %r" % body)
#ch.basic_ack(delivery_tag = method.delivery_tag)
if not (os.path.isfile(js_path)):
print (' [*] ERROR files missing ')
#ch.basic_ack(delivery_tag = method.delivery_tag)
return
p= subprocess.Popen(run a subprocess here)
p.wait()
print (' [*] Temporary Files removed')
print(" [*] Waiting for messages. To exit press CTRL+C")
channel.basic_qos(prefetch_count=1)
channel.basic_consume(callback,queue='task_queue',no_ack=True)
channel.start_consuming()
它管理大部分时间,但随机崩溃并出现以下错误:
Traceback(最近一次调用最后一次):文件“Receive5.py”,第 139 行,在 channel.start_sumption() 文件 "C:\Python27\lib\site-packages\pika\adapters\blocking_connection.py", 第 1681 行,开始消费 self.connection.process_data_events(time_limit=None) 文件 "C:\Python27\lib\site-packages\pika\adapters\blocking_connection.py", 第 647 行,在 process_data_events 中 self._flush_output(common_terminator) 文件 "C:\Python27\lib\site-packages\pika\adapters\blocking_connection.py", 第 426 行,在 _flush_output 中 引发 exceptions.ConnectionClosed() pika.exceptions.ConnectionClosed
【问题讨论】:
-
您应该检查日志,由于某种原因,消费者的连接已关闭
-
看起来是一个“心跳”问题..¨=错误报告==== 20-May-2016::08:36:28 === 关闭 AMQP 连接...错过心跳客户端,超时:60s =INFO REPORT==== 20-May-2016::08:40:22 === 接受 AMQP 连接 ... =INFO REPORT==== 20-May-2016::08:44 :51 === 接受 AMQP 连接 ... =INFO REPORT==== 20-May-2016::08:44:51 === 关闭 AMQP 连接 ... =ERROR REPORT==== 20-May- 2016::08:46:22 === 关闭 AMQP 连接...错过来自客户端的心跳,超时:60 秒 =INFO REPORT==== 20-May-2016::09:38:51 === 接受 AMQP 连接...
-
通过将心跳设置为 0 解决的问题 ...
-
已经快两年了,我认为这个问题没有得到更好的处理或记录:(