当前位置: 动力学知识库 > 问答 > 编程问答 >

python - Getting a stable RabbitMQ consumer with pika 0.10.0

问题描述:

Attrmpting to find out why the connection to RabbitMQ continually drops. I am using the a blocking connection and the generator to continually process the message.

the connection looks like:

connection = pika.BlockingConnection(pika.ConnectionParameters(host=HOST, heartbeat_interval=0))

The generator is:

for method, properties, body in channel.consume(QUEUE_NAME)

Heartbeats are set to off using heartbeat_interval=0. I only create one connection and a new channel is created when I want to send a message back. The failure in pika appears to come from the acknowledgement:

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

The code looks as follows:

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...")

I enclosed the RabbitMQ logs:

=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">>}

分享给朋友:
您可能感兴趣的文章:
随机阅读: