试图找出与RabbitMQ的连接不断下降的原因。我正在使用阻塞连接和生成器来持续处理消息。
连接看起来像:
connection = pika.BlockingConnection(pika.ConnectionParameters(host=HOST, heartbeat_interval=0))
发电机是:
for method, properties, body in channel.consume(QUEUE_NAME)
使用heartbeat_interval=0
将心跳设置为关闭。我只创建一个连接,当我想要发回消息时创建一个新的频道。鼠兔的失败似乎来自承认:
Traceback (most recent call last):
File "everlast_generator.py", line 101, in <module>
channel.basic_ack(delivery_tag = method.delivery_tag)
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py", line 1909, in basic_ack
self._impl.basic_ack(delivery_tag=delivery_tag, multiple=multiple)
File "/usr/local/lib/python2.7/dist-packages/pika/channel.py", line 159, in basic_ack
raise exceptions.ChannelClosed()
ChannelClosed
代码如下:
connection = pika.BlockingConnection(pika.ConnectionParameters(host=HOST, heartbeat_interval=0))
channel = connection.channel()
for method, properties, body in channel.consume(QUEUE_NAME):
### do some work ###
### do some more work on inbound message ###
result = some_function()
if result is not None:
try:
channel.basic_ack(delivery_tag = method.delivery_tag)
response_channel(result, connection) # send back a response on a different queue!
except Exception as e:
LOGGING.info('Failed', e)
print 'Failed'
print traceback.print_exception(exc_type, exc_value, exc_traceback, limit=6)
LOGGING.exception("Failed...")
我附上了RabbitMQ日志:
=WARNING REPORT==== 8-Nov-2016::17:02:02 ===
closing AMQP connection <0.24461.177> (XXX.XX.XXX.XX:51635 -> 188.40.59.81:5672):
client unexpectedly closed TCP connection
=INFO REPORT==== 8-Nov-2016::17:05:02 ===
accepting AMQP connection <0.29986.177> (XXX.XX.XXX.XX:44467 -> 188.40.59.81:5672)
=INFO REPORT==== 8-Nov-2016::17:15:12 ===
accepting AMQP connection <0.2764.178> (127.0.0.1:49617 -> 127.0.0.1:5672)
=ERROR REPORT==== 8-Nov-2016::18:11:57 ===
closing AMQP connection <0.2764.178> (127.0.0.1:49617 -> 127.0.0.1:5672):
{writer,send_failed,{error,timeout}}
=ERROR REPORT==== 8-Nov-2016::18:22:03 ===
closing AMQP connection <0.29986.177> (XXX.XX.XXX.XX:44467 -> 188.40.59.81:5672):
missed heartbeats from client, timeout: 60s
=WARNING REPORT==== 8-Nov-2016::20:01:08 ===
closing AMQP connection <0.685.172> (127.0.0.1:59709 -> 127.0.0.1:5672):
client unexpectedly closed TCP connection
=INFO REPORT==== 8-Nov-2016::20:01:48 ===
accepting AMQP connection <0.27076.180> (127.0.0.1:50455 -> 127.0.0.1:5672)
=WARNING REPORT==== 8-Nov-2016::20:25:49 ===
closing AMQP connection <0.27076.180> (127.0.0.1:50455 -> 127.0.0.1:5672):
client unexpectedly closed TCP connection
=INFO REPORT==== 8-Nov-2016::20:27:22 ===
accepting AMQP connection <0.7675.181> (127.0.0.1:39305 -> 127.0.0.1:5672)
=WARNING REPORT==== 8-Nov-2016::20:43:46 ===
closing AMQP connection <0.5549.27> (127.0.0.1:39320 -> 127.0.0.1:5672):
client unexpectedly closed TCP connection
=INFO REPORT==== 9-Nov-2016::06:40:31 ===
accepting AMQP connection <0.323.191> (XXX.XX.XXX.XX:38247 -> XXX.XX.XXX.XX:5672)
=ERROR REPORT==== 9-Nov-2016::06:40:31 ===
closing AMQP connection <0.323.191> (XXX.XX.XXX.XX:38247 -> XXX.XX.XXX.XX:5672):
{bad_header,<<"GET / HT">>}