Differences between PointToPoint and Publish/subscribe model in JMS
Point to Point Messaging Model and Publish Subscribe Messaging Model are the two types of messaging modules/types/domains supported by Java Message Service (JMS).
These two are programming models that support asynchronous messaging between heterogeneous systems.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
There are some important terms, which will help us in understanding the difference between the two messaging model types in a better way:
- JMS destination is a staging area that acts as a source for the messages consumed by a client and a target/ destination for the messages produced.
- JMS producer is a JMS client that sends a message.
- JMS consumer is a JMS client that receives a message.
- A JMS client can be both a producer and a consumer of messages.
- Time dependency simply means that if a producer has published some messages for some topic a consumer has not subscribed to, then the consumer will not receive the messages for that topic.
Let’s see the difference between these two messaging model types:
|PointToPoint messaging-model (P2P)||Publish/subscribe model(Pub sub)|
|Here the JMS Destination is queue.||While JMS Destination in Pub sub is a topic.|
|Here the JMS producer is the sender.||While JMS producer in Pub sub is a publisher.|
|Here the JMS consumer is receiver.||While JMS consumer in Pub sub is a subscriber.|
|Here the message is received by only 1 JMS consumer.||While in Pub sub, a message can be received by multiple JMS consumers.|
|Here the JMS consumer sends an acknowledgement to producer on receiving the message.||While in Pub sub, the JMS consumer does not send any acknowledgement on receiving the message.|
|Here there exists a time dependency for the receiver to receive the message.||While in Pub sub, there is no time dependency laid between producer-consumer.|
|This model is pull-based, which means that the receiver is responsible for requesting new messages to be sent by a sender.||While this model is push-based, which means that the messages are automatically delivered to consumers without them having to request for new messages.|
|For ex. sending a fax/ voice message.||For ex. newspapers.|