title: Using publisher confirms with RabbitMQ, in which cases publisher will be notified about success/failure?
body: <p>Quoting the book, RabbitMQ in Depth:</p>
  
  <blockquote>
    <p>A Basic.Ack request is sent to a publisher when a message that it has
    published has been directly consumed by consumer applications on all
    queues it was routed to or that the message was enqueued and persisted
    if requested.</p>
  </blockquote>
  
  <p>Confused with <code>Has been directly consumed</code>, does it mean when consumer send <code>ack</code> to broker publisher will be informed that consumer process message successfully? or it means that publisher will be notified when consumer just receive message from the queue?</p>
  
  <p><code>or that the message was enqueued and persisted if requested</code>. Is this like conjuction or publisher will be informed when either of those happens? (In that case publisher would be notified twice)</p>
  
  <p>Using <code>node.js</code> and <code>amqplib</code> wanted to check what is happening actually:</p>
  
  <pre><code>// consumer.js
  amqp.connect(...)
  .then(connection =&gt; connection.createChannel())
  .then(() =&gt; { assert exchange here })
  .then(() =&gt; { assert queue here })
  .then(() =&gt; { bind queue and exchange here })
  .then(() =&gt; {
    channel.consume(QUEUE, (message) =&gt; {
      console.log('Raw RabbitMQ message received', message)
  
      // Simulate some job to do
      setTimeout(() =&gt; {
        channel.ack(message, false)
      }, 5000})
  
    }, { noAck: false })
  })
  
  // publisher.js
  amqp.connect(...)
  .then(connection =&gt; connection.createConfirmChannel())
  .then(() =&gt; { assert exchange here })
  .then(() =&gt; {
    channel.publish(exchange, routingKey, new Buffer(...),{}, (err, ok) =&gt; {
      if (err) {
        console.log('Error from handling confirmation on publisher side', err)
      } else {
        console.log('From handling confirmation on publisher side', ok)
      }
    })
  })
  </code></pre>
  
  <p>Running the example, i can see following logs:</p>
  
  <pre><code>From handling confirmation on publisher side undefined
  Raw RabbitMQ message received
  Time to ack the message
  </code></pre>
  
  <p><strong>As far as i see, at least by this log, publisher will be notified only when message was enqueued?</strong> (So having consumer <code>ack</code>ing the message will not influence publisher in any way)</p>
  
  <p>Quoting further:</p>
  
  <blockquote>
    <p>If a message cannot be routed, the broker will send a Basic.Nack RPC
    request indicating the failure. It is then up to the publisher to
    decide what to do with the message.</p>
  </blockquote>
  
  <p>Changing the above example, where i only changed the routing key of the message to something that should not be routed anywhere (there are no bindings that would match routing key), from logs i can see <strong>only</strong> following.</p>
  
  <pre><code>From handling confirmation on publisher side undefined
  </code></pre>
  
  <p>Now i'm more confused, about what publisher is notified exactly here? I would understand that it receive an error, like <code>Can't route anywhere</code>, that would be aligned with quote above. But as you can see <code>err</code> is not defined and as side question even if <code>amqplib</code> in their official docs are using <code>(err, ok)</code>, in no single case i see those defined. So here output is same like in above example, how one can differ between above example and un-routable message. </p>
  
  <p>So what im up to here, when exactly publisher will be notified about what is happening with the message? Any concrete example in which one would use PublisherConfirms? From logging above, i would conclude that is nice to have it in cases where you want to be 100% sure that message was enqueued.</p>