<div dir="ltr">It's sample code intended to illustrate the mechanism.  Whether your logic really means you should be waiting or sleeping or whatever is another story.<div><br></div><div>The core of the idea:</div><div>
<ul><li>Publisher keeps track, in some kind of set-like data structure, the publish sequence numbers associated with the messages he's published.</li><li>As the broker receives the messages and does the requested work it asynchronously issues confirms back to the publisher.</li>
<li>The publisher retires these no longer pending confirms by removing them from the set.</li><li>If the connection closes indicating a failure, than any sequence numbers in the pending set have to be re-published, because the publisher has no guarantee the broker received them or, if it did, that it successfully did anything with them before they went wrong.</li>
</ul><div>The sample code is basically just napping periodically while it waits for the pending confirms set to drain as confirms come in.  Obviously your own producers may plan to run for long periods of time, or be doing other useful work as they run, and will need somewhat different logic.</div>
</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Feb 26, 2014 at 10:16 AM, cw storm <span dir="ltr"><<a href="mailto:cwstorm@gmail.com" target="_blank">cwstorm@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">I would like to use the example code provided in <a href="https://urldefense.proofpoint.com/v1/url?u=http://www.rabbitmq.com/blog/2011/02/10/introducing-publisher-confirms/&k=oIvRg1%2BdGAgOoM1BIlLLqw%3D%3D%0A&r=sF0ZnlnTVu0KrGgVA7hSe29cx%2BPGAwA3H8KZu6lkUvo%3D%0A&m=QUfUbFS9YzM58pz9kll9YojUmz0BsQCmKTEyEzb0%2BoI%3D%0A&s=b8ddf76532b9371ee56c739e1f4484e3de1919f070f791241be58f8200b4f29b" target="_blank">http://www.rabbitmq.com/blog/2011/02/10/introducing-publisher-confirms/</a><div>

<br></div><div>I'm trying to understand the below snippet:</div><div><br></div><div><pre style="color:rgb(85,85,85);font-size:13px;line-height:18px">for (long i = 0; i < MSG_COUNT; ++i) {
     unconfirmedSet.add(ch.getNextPublishSeqNo());
     ch.basicPublish("", QUEUE_NAME, MessageProperties.PERSISTENT_BASIC,
                       "nop".getBytes());
 }
while (unconfirmedSet.size() > 0)
     Thread.sleep(10);</pre><pre style="color:rgb(85,85,85);font-size:13px;line-height:18px">As stated, "<span style="font-family:Verdana,sans-serif">the producer waits for all the messages to be confirmed."  Assuming that's the above code.  Is the "while" logic safe?  What happens when the "unconfirmedSet.size" is always greater than 0?  Also, the "MSG_COUNT" if set to 10000, does the for loop will always loop 10000 times even though there might only be say 10 messages?</span></pre>

</div></div>
<br>_______________________________________________<br>
rabbitmq-discuss mailing list<br>
<a href="mailto:rabbitmq-discuss@lists.rabbitmq.com">rabbitmq-discuss@lists.rabbitmq.com</a><br>
<a href="https://urldefense.proofpoint.com/v1/url?u=https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss&k=oIvRg1%2BdGAgOoM1BIlLLqw%3D%3D%0A&r=sF0ZnlnTVu0KrGgVA7hSe29cx%2BPGAwA3H8KZu6lkUvo%3D%0A&m=QUfUbFS9YzM58pz9kll9YojUmz0BsQCmKTEyEzb0%2BoI%3D%0A&s=8211f71263dd5091577809eb7793ada1a818ae26a30e60f2e2d1c9de4ad4d33a" target="_blank">https://urldefense.proofpoint.com/v1/url?u=https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss&k=oIvRg1%2BdGAgOoM1BIlLLqw%3D%3D%0A&r=sF0ZnlnTVu0KrGgVA7hSe29cx%2BPGAwA3H8KZu6lkUvo%3D%0A&m=QUfUbFS9YzM58pz9kll9YojUmz0BsQCmKTEyEzb0%2BoI%3D%0A&s=8211f71263dd5091577809eb7793ada1a818ae26a30e60f2e2d1c9de4ad4d33a</a><br>

<br></blockquote></div><br></div>