Val Blant
Val Blant

Reputation: 1762

Durable Subscribers with different Message Selectors

I was wondering if someone here could clarify the following for me.

Let's say that I have a Topic, with 5 Durable Subscribers attached to it. Each subscriber was created with the following call (the name is obviously different for every one):

session.createDurableSubscriber( 
   (Topic) destination, 
   "NAME_n", // Unique for every subscriber
   "PARTY_ID = '123'", // Message selector
   true );

So, when I publish a message with PARTY_ID = '123', it will be retained in the Topic until all 5 durable subscribers got a copy, correct?

Now, let's say that we have 3 other durable subscribers, with message selector "PARTY_ID = '666'". When I publish a '666' message to the Topic, will the message be removed from the Topic after the 3 durable '666' subscribers receive the message, or will it keep it there until ALL subscribers receive the message, which in this case will never happen due to selector restrictions?

In other words, does message retention on a Topic take the message selector of the Message and Subscriber into account?

Upvotes: 0

Views: 691

Answers (1)

Shashi
Shashi

Reputation: 15263

When a message is published, the messaging provider will put a copy of that message to all the subscribers that match the selection criteria specified by the subscribers. In your case a copy of the message will be put to 5 subscribers as they match the selector 'PARTY_ID=123'. Then message is discarded by the messaging provider. Similarly for selector 'PARTY_ID=666', messaging provider will copy the message to matching subscribers only and then discard the message.

Please note the messaging provider will put a copy of the message to the storage (typically a queue) assigned to the subscribers and will go on to process next message from publishers. It will not wait for the subscriber to consume the message from the queue.

Message retention or Retain Publication is another concept where the messaging provider will retain (or cache) a publication for topic until the next publication is received for the same topic. The next publication may be published in the next second or after 5 minutes or 5 hrs. Basically the time of next publication is unpredicted. This concept is quite useful when subscriber comes in after a publication has been maid and the next publication is made after sometime. With Retain publication, the a copy of the retained publication is delivered immediately to the subscriber so that the subscriber does not have to wait long for the next publication.

Let's assume that a publisher is publishing on score of a FIFA2014 ongoing match between The Netherlands and Spain on topic FIFA2014/MATCHUPDATE/NED-ESP. The publisher publishes a new message every time a goal is scored. Since the scoring of goal is unpredictable, messages are published with 'Retain Publication' property which tells the message provider to keep a copy of the message till the next message is published on FIFA2014/MATCHUPDATE/NED-ESP. Assume that there are two subscribers when the first publication was made and with score being 0:0. Now let's assume that a third subscriber comes in after the first publication was made, it will get a publication immediately with score being 0:0. It does not have to wait to know the score till a next goal is scored. See this link.

Hope I am clear.

Upvotes: 2

Related Questions