[rabbitmq-discuss] Publish-Confirm

Jerry Kuch jkuch at gopivotal.com
Wed Feb 26 18:25:11 GMT 2014


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.

The core of the idea:

   - Publisher keeps track, in some kind of set-like data structure, the
   publish sequence numbers associated with the messages he's published.
   - As the broker receives the messages and does the requested work it
   asynchronously issues confirms back to the publisher.
   - The publisher retires these no longer pending confirms by removing
   them from the set.
   - 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.

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.




On Wed, Feb 26, 2014 at 10:16 AM, cw storm <cwstorm at gmail.com> wrote:

> I would like to use the example code provided in
> http://www.rabbitmq.com/blog/2011/02/10/introducing-publisher-confirms/<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>
>
> I'm trying to understand the below snippet:
>
> 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);
>
> As stated, "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?
>
>
> _______________________________________________
> rabbitmq-discuss mailing list
> rabbitmq-discuss at lists.rabbitmq.com
>
> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20140226/79e9e5f0/attachment.html>


More information about the rabbitmq-discuss mailing list