pika/pika — Issue #93: AMQPConnectionError with heartbeat and slow consumer callback
Author: mmb
Created: 2011-10-08 01:04:17+00:00
State: open

When using a heartbeat with a consumer callback that takes some time to execute, it seems like the callbacks stop the heartbeat and the server closes the connection. After the consumer callbacks are all done AMQPConnectionError is thrown because it's trying to send more heartbeats back through the closed connection. I have also tried with a nonblocking connection and the result is the same.

Producer:

```python
import pika

exchange = 'test'
connection = pika.BlockingConnection()
channel = connection.channel()

channel.exchange_declare(exchange=exchange, type='topic')

for x in range(5):
channel.basic_publish(
exchange=exchange, routing_key='test', body=str(x) * 100)

connection.close()
```

Consumer:

```python

import time

import pika

def callback(channel, method, properties, body):
time.sleep(1)
print body

exchange = 'test'

connection = pika.BlockingConnection(pika.ConnectionParameters(heartbeat=True))
channel = connection.channel()

channel.exchange_declare(exchange=exchange, type='topic')

queue = channel.queue_declare(exclusive=True)
queue_name = queue.method.queue

channel.queue_bind(exchange=exchange, queue=queue_name, routing_key='test')
channel.basic_consume(callback, queue=queue_name, no_ack=True)

channel.start_consuming()
```