title: Re-consuming nack'ed messages when all the other work is done
body: <p>I'm implementing RabbitMQ to perform some image editing operations on another server. Though, from time to time the request may arrive on that server before the source image is synced to it - in which case I would like to pop the message back in the the queue and process it after all other operations have completed.</p>
  
  <p>However, calling basic.nack with the resubmit bit set makes my queue re-receive that message immediately - ahead of any operations that operations that can actually complete.</p>
  
  <p>Currently I feel like I'm forced to implement some logic that just re-submits the original message to the exchange, but I'd like to avoid that. Both because the same message may have been successfully processed on another server (with it's own queue), and because I expect this to be so much of a common pattern that there must be better way.</p>
  
  <p>(oh, I'm using php-amqplib in both consumer and server code)</p>
  
  <p>Thanks!</p>
  
  <p><strong>Update</strong>: I solved my problem using Dead Letter Exchange, as suggested by zaq178miami</p>
  
  <p>My current solution:</p>
  
  <ul>
  <li>Declares a dead letter exchange <code>$dead_letter_exchange</code> on the original queue <code>$worker</code></li>
  <li>Declares a recovery exchange <code>$recovery_exchange</code></li>
  <li>Declares a queue <code>$dead_queue</code>, with a <code>x-message-ttl</code> of 5 seconds and <code>x-dead-letter-exchange</code> set to <code>$recovery_exchange</code></li>
  <li>Binds <code>$dead_letter_queue</code> to <code>$dead_letter_exchange</code></li>
  <li>And binds <code>$worker</code> to <code>$recovery_exchange</code></li>
  <li><code>$dead_letter_exchange</code> and <code>$recovery_exchange</code> are generated names, based on the exchange I'm consuming from and the value of <code>$worker</code></li>
  </ul>
  
  <p>Making every message that gets nack'ed return to the worker only on that specific queue (server) after five seconds for a retry. I may still want to apply some logic that throws the message away after <code>$n</code> retries.</p>
  
  <p>I'm still open to better ideas ;-)</p>