<div>I have a publish-subscribe use case where I would like to block on the publish side until each of the subscribers confirm that they have completed handling the message sent by the publisher.</div><div><br></div><div>I (incorrectly?) assumed that I could use RabbitMQ and its Java amqp-client&#39;s Channel.waitForConfirmsOrDie method as part of my solution. The issue is that I haven&#39;t found a case in which waitForConfirmsOrDie will actually block.</div>
<div><br></div><div>According to the javadocs (<a href="http://www.rabbitmq.com/javadoc/com/rabbitmq/client/Channel.html#waitForConfirmsOrDie()">http://www.rabbitmq.com/javadoc/com/rabbitmq/client/Channel.html#waitForConfirmsOrDie()</a>), waitForConfirmsOrDie is supposed to:</div>
<div><br></div><div>&gt; Wait until all messages published since the last call have been either ack&#39;d or nack&#39;d by the broker. If any of the messages were nack&#39;d, waitForConfirmsOrDie will throw an IOException. When called on a non-Confirm channel, it will return immediately.</div>
<div><br></div><div>In order to test that this method really works, I started with example code from the RabbitMQ website (<a href="http://hg.rabbitmq.com/rabbitmq-java-client/raw-file/da241e35951b/test/src/com/rabbitmq/examples/ConfirmDontLoseMessages.java">http://hg.rabbitmq.com/rabbitmq-java-client/raw-file/da241e35951b/test/src/com/rabbitmq/examples/ConfirmDontLoseMessages.java</a>).</div>
<div><br></div><div>The example code creates a publisher and a consumer, each on its own separate thread. Then the publisher sends messages to the exchange while the consumer consumes the messages. It seems to me that the publisher is supposed to block until all of the messages are ack&#39;d via its call to waitForConfirmsOrDie(). Is this what this is really supposed to do?</div>
<div><br></div><div>This example code seemed like it matched up perfectly with what I was trying to do. But, it doesn&#39;t seem to work the way I thought it did. In fact, if, in the consumer thread, I turn off auto-acking messages, then waitForConfirmsOrDie() still returns immediately.</div>
<div><br></div><div>I turned off auto ack by just changing one false to true:�</div><div>ch.queueDeclare(QUEUE_NAME, false, false, false, null);�</div><div>becomes�</div><div>ch.queueDeclare(QUEUE_NAME, true, false, false, null); (2nd arg false instead of true).�</div>
<div><br></div><div>I believe this means that acks should no longer be sent by the consumer.</div><div><br></div><div>So what does waitForConfirmsOrDie() actually do? When would it block?</div><div><br></div><div>If waitForConfirmsOrDie doesn&#39;t do what I want, is there a way to make a publisher wait until all subscribers ack a message before proceeding?</div>