title: Acknowledge messages with pika for RabbitMQ
body: <p>I'm using RabbitMQ for message exchange between different docker containers. On the client side I use pika for communication with RabbitMQ. Now the following problem appeared:</p>
  
  <p>Using BlockingConnection I receive a message in my consumer which triggers a quite time consuming task. During processing of this task RabbitMQ closed the connection because the heartbeat wasn't sent from the consuming connection as it's busy processing the task.</p>
  
  <p>The solution I came up to deal with this is that I shutoff the automatic acknowledgment in pika when attaching a callback to the consumer queue like this <code>channel.basic_consume(queue='myqueue', on_message_callback=my_callback, auto_ack=False)</code>. Additionally I moved the time consuming processing to a daemonized python thread in order to allow the BlockingConnection to send the heartbeat required by RabbitMQ. </p>
  
  <p>Now I need to acknowledge the RabbitMQ message from the thread once the processing is finished. For that I extract the <code>delivery_tag</code> from the <code>method</code> as well as the <code>channel_number</code> from the <code>channel</code> property provided by pika.</p>
  
  <pre><code>channel_number = channel.channel_number
  delivery_tag = method.delivery_tag
  </code></pre>
  
  <p>Now in the thread I create a new connection as pika is not threadsafe</p>
  
  <pre><code>conn = BlockingConnection(ConnectionParameters(host="rabbitmq"))
  channel = conn.channel(channel_number=channel_number)
  channel.queue_declare(queue='myqueue', durable=False)
  channel.basic_ack(delivery_tag=delivery_tag)
  conn.close()
  </code></pre>
  
  <p>to acknowledge the message. </p>
  
  <p>However the acknowleging doesn't work as pika yields this warnings:</p>
  
  <pre><code>WARNING:pika.channel:Received remote Channel.Close (406): 'PRECONDITION_FAILED - unknown delivery tag 1' on &lt;Channel number=1 CLOSING conn=&lt;SelectConnection OPEN transport=&lt;pika.adapters.utils.io_services_utils._AsyncPlaintextTransport object at 0x7f94f1dad9e8&gt; params=&lt;ConnectionParameters host=rabbitmq port=5672 virtual_host=/ ssl=False&gt;&gt;&gt;
  WARNING:pika.adapters.blocking_connection:Got ChannelClosed while closing channel from connection.close: ChannelClosedByBroker: (406) 'PRECONDITION_FAILED - unknown delivery tag 1'
  </code></pre>
  
  <p>Q1: Is it possible to acknowledge a message from connection B which was received by connection A?</p>
  
  <p>Q2: Any idea why this is not working? </p>
  
  <p>I read about <a href="https://github.com/gmr/rabbitpy" rel="nofollow noreferrer">rabbitpy</a> and <a href="https://github.com/eandersson/amqpstorm" rel="nofollow noreferrer">AMQPStorm</a> and try those now</p>