Try PubSub+

Order of messages in different topics and fairness

radekmradekm Member Posts: 5

Hi,
I have a question about order of messages in different topics:

1) Suppose a service publishes messages A, B into topic T1
and then messages C, D into topic T2. If a different service
subscribes (via JCSMP API) to both topics T1 and T2 will it receive messages A, B
before C, D?

2) Is there a different answer to 1) if a subscriber uses one subscription
eg. > instead of two concrete subscription to T1 and T2?

3) Is there a different answer to 1) if there is some other publisher
which is at the same time publishing lots of messages into T2?

Thanks

Tagged:

Comments

  • AaronAaron Member, Moderator, Employee Posts: 177 Solace Employee

    Hey @radekm ... I have a few different thoughts than Tom, so I'm going to put them here...

    I trust that we're assuming things like: the publisher is publishing all messages from the same thread, the publisher and subscriber both only have one connection (Session) to the broker, all messages are being published with the same quality of service (aka Delivery Mode: Direct/Guaranteed), same Class-Of-Service (1,2,3), and same Priority. And assuming no loss (e.g. due to network drop-out for Direct messaging).

    With all those assumptions holding true, then #1) yes a subscriber listening to both t1 and t2 will receive messages in order: A, B, C, D. Because the messages arrived in the broker in that order, because the publisher sent them in that order from a single thread on the same TCP connection.

    Ordering is guaranteed _across _topics, in the order that the broker received them. In Tom's explanation above for #1, he's talking about two different publishers... and yes, in that case there is/could be a race condition as to which messages arrive at the broker first. But still, once the messages arrive at the broker, all consumers with the same set of subscriptions will receive the messages in the exact same order. (given my assumptions above).

    BTW, one other assumption I should have made: if using Guaranteed messaging, the pattern is to have queues for the consumer, and subscribed to topics. The publisher still publishes on Topics, but should ensure the DeliveryMode is Persistetnt. In this case, I'm assuming you only have a single queue subscribed to both t1 and t2. If you had two different queues, then again there could be a race condition as to which messages are received first.

    I guess for the #3 question, no there should be no changes to ordering! There might be some change in timing between messages if the broker is being overloaded, and obviously the consumer will be receiving a lot of extra messages on t2, but the absolute order of A, B, C, D will not change.

    @TomF am I missing something in what you're trying to explain?

  • manishmanish Member Posts: 28 ✭✭

    Hi,

    @TomF @Aaron , I learned so many concept from above answer .

    Thank you so much for detailed answer and well explained concepts . I am sure other people would have got benefited from above answer.

    @radekm Good Question Mate

  • TomFTomF Member, Employee Posts: 225 Solace Employee

    @aaron, we're right on the edge of corner cases here, but assuming t1 and t2 are being sent by different producers, my point was there is a chance of network congestion upsetting the ordering the broker receives the messages from t1 and t2.

Sign In or Register to comment.