PointToPoint vs Publish/subscribe model in JMS?

M Sach picture M Sach · Nov 14, 2012 · Viewed 17.5k times · Source

I am new to JMS.I have started with hello world where i am publishing the message from java application on Topic and listening it from client(node.js javascript).I have gone thru http://en.wikipedia.org/wiki/Java_Message_Service. Now i have got some doubts based on my previuos theortical understanding and what is suggested at above link?

As per my understanding,Point to Point is the queue implementation where there can be at most one consumer subscribed on queue and can be consumed by that only. Neither producer nor the consumer knows about each other.Queue is hosted on message brokers in my case Apache active MQ. Queue can be created by producer before publishing the message(or it can be created from console in advance).

In case of Publish/subscribe Model, its almost same as PointToPoint except the fact we use Topic instead of queue.In this model, there can be more than more consumer on Topic. Once the message is published, all the subscribers will be notified. Now if any of the subscriber, send the acknowledgment for the published message, message will taken as consumed and it will no longer be available for new subscriber?

Answer

Shashi picture Shashi · Nov 15, 2012

Point to Point means message(s) is sent from one application(producer or sender) to another application(consumer/receiver) via a queue. There can be more than one consumer listening on a queue but only one of them will be get the message. Hence it is Point to Point or One to One.

On the other hand Publish/Subscribe is another messaging model where a message(or publication as it is commonly called) is sent to multiple consumers(or subscribers) through a topic. The topic is the link between publisher and subscriber. The subscribers may or may not acknowledge the published message. Implementations like JMS acknowledge the message the messaging providers but not the sender of the message. Publications will be received by all subscribers, durable and non-durable. Any new subscribers on the same topic will not get the publication unless it is a Retained publication.

I would recommend you to read further on,

  1. Durable subscription
  2. Non-durable subscription
  3. Retained publication