2

I have a simple scenario, where publisher(my java application) publish the message on topic. 50 clients have subscribed on same JMS topic.As soon as message is published on topic, all the 50 subscriber will be notified .Say only one subscriber(0ut 0f 50) process the message and send the acknowledgement after processing.(Once this client processing is done, i can see the message as consumed on apache MQ console. Otherwise if no client sends the acknowledgment after receiving the message i see the message as pending message).

Now question is once any client sends the acknowledgment and any new client subscribe on topic, will he be notified about the message ? or it works in a way where message has been consumed by any of the client (which internally means acknowledgment has been sent by any of the client), no further notification will be sent to any new subscriber and message will be taken off from the Topic(This is the behaviuor i am experiencing but looks like it should not work in this fashion as per as per Publish/subscribe model under http://en.wikipedia.org/wiki/Java_Message_Service )?

M Sach
  • 33,416
  • 76
  • 221
  • 314

1 Answers1

3

I have not worked with Apache MQ. But in general:

In a Publish/Subscribe model, when a message is published, all subscribers will receive that publication.

Acknowledgement by subscribers is only to messaging providers and not to the publisher. When a subscriber acknowledges the receipt of a message, that message is removed by the messaging provider so that the message is not delivered again.

If a new subscriber comes in after a message is published on a topic, then the subscriber will not get that publication. Any new publication on the topic will be received by the subscriber. Some providers like IBM WebSphere MQ have a feature called "Retain Publication" wherein a copy of a publication is cached. Any new subscribers who come in after a publication is made will receive this cached publication. Retain publication feature is useful when there is a time delay between publications on a topic, new subscribers will get the cached publication immediately rather than waiting for a new publication to be made by publisher.

Shashi
  • 14,980
  • 2
  • 33
  • 52
  • Thanks Shashi. As you told When a subscriber acknowledges the receipt of a message, that message is removed by the messaging provider so that the message is not delivered again.It means message will be removed as soon as acknowledgment is received by any of the subscriber.To remove the message,its not necessary that acknowledgment should be sent by all subscribers. Only one acknowledgment is sufficient? – M Sach Nov 15 '12 at 07:36
  • No. It typically depends on the messaging provider implementation. A provider might create temporary queue for each subscriber and put a copy of publication on to that queue. Once the subscriber receives the message, provider removes that from the queue. In this case every subscriber acknowledges. Some provider might not use queues and removes the message only after the last subscriber in the list of subscribers acknowledges. – Shashi Nov 15 '12 at 08:36
  • Atleast in case active MQ, my observation is Active MQ UI console shows the message as consumed once it receives the first acknowledgment. I hope when console shows the message as consumed, it means messages has been removed from topic.(Because if new subscriber subscribes, he no longer gets the message that has been consumed). But i did not get any content on net to confirm it? – M Sach Nov 15 '12 at 10:55
  • You could be right. But a new subscriber will not get the message as the message was published before the new subscriber registered. Messages will be delivered to only those subscribers who were active when the publication was made. – Shashi Nov 15 '12 at 11:19