In this post, we are going to discuss Messaging Models supported by Java Messaging System (JMS). Before reading this post, please go through my previous post about JMS to understand some JMS Basic concepts.
Table of Contents
JMS Messaging Models
JMS API supports two kinds of Messaging models (Programming models) to support Asynchronous Messaging between Heterogeneous Systems.
- Point-To-Point Model(P2P Model)
- Publish-Subscribe Model(Pub/Sub Model)

JMS Messaging Models
Point-to-Point Messaging Model
Point-to-Point Messaging Model is also known as P2P Model. Below diagram shows typical Point-To-Point Messaging model in any Messaging system.

JMS P2P Messaging Model
How a P2P Model works?
Point-To-Point model follows these concepts:
- P2P Model uses “Queue” as JMS Destination
- In P2P Model, a JMS Sender or JMS Producer creates and sends messages to a Queue.
- JMS Queue is an administered object, which is created in a JMS Provider by Administrator.
- In P2P Model, a JMS Receiver or JMS Consumer receives and reads messages from a Queue.
- In P2P Model, a JMS Message is delivered to one and only one JMS Consumer.
- We can configure any number of JMS Senders and JMS Receivers to a particular queue. However, any message should be delivered to one and only one Receiver.
- There is no timing dependency between JMS Sender and JMS receiver. That means the JMS Receiver can consume the messages whether it is alive or not when the JMS Sender sent that message.
- In this model, Destination stores messages till its consumed by Receiver.
Possible P2P Model Messaging systems
In this section, we will discuss “What are the possible ways to implement P2P Messaging Model”.
Approach 1: In this P2P Approach, we have configured one sender and one receiver. It is a very simple and straightforward approach as there is only a one-to-one connection.
One sender sends messages to queue and receiver receives those messages.

JMS P2P Model – Approach 1
Approach 2: In this P2P Model, we have configured one sender and multiple receivers. However, communication will happen between one sender to one receiver only. If the sender sends a message to Receiver-1, then only that Receiver (i.e. Receiver-1) receives that message and sends ACK (Acknowledgement) back to the Sender.

JMS P2P Model – Approach 2
Approach 3: In this P2P Model, we have configured multiple Senders and only one Receiver. However, communication will happen one sender to one receiver only.

JMS P2P Model – Approach 3
Approach 4: In this P2P Model, we have configured multiple senders and multiple receivers. However, communication will happen between one sender to one receiver only. If Sender-2 sends a message to Receiver-2, then only that Receiver (i.e. Receiver-2) receives that message and sends ACK (Acknowledgement) back to the Sender-2.

JMS P2P Model – Approach 4
- A P2P model may have more than one sender and more than one receiver, but each message is consumed by one and only one receiver.
- Sometimes, same JMS client may act as a JMS Sender or a JMS Receiver.

P2P Model Multiple Receivers
Even though this queue has more than one receiver, but each message is consumed by only one Receiver. For example, “Msg1” is only consumed by “JMS Receiver 3”.
Publish/Subscribe Messaging Model
Pub/Sub Messaging model is again divided into two categories.
- Durable Messaging Model: Durable Model is also known as Persistent Messaging Model. In this model, Messages are stored in some kind of store in JMS Server until they are delivered to the destination properly.
- Non-Durable Messaging Model: Non-Durable Model is also known as Non-Persistent Messaging Model. In this model, Messages are not stored in the JMS Server.

JMS Pub Sub Messaging Model
The following diagram shows a typical Publish/Subscribe messaging system.

JMS Pub Sub Example
How Pub/Sub Model Works
- Pub/Sub model uses Topic as JMS Destination.
- JMS Administrator uses JMS Provider Admin Console and configures all required ConnectionFactory and Topics Objects in JMS Provider.
- JMS Publisher creates and publishes messages to Topics.
- JMS Subscriber subscribes to interested Topics and consumes all messages.
- Pub/Sub Messaging model has timing dependency. That means JMS Subscriber can consume messages which are published to the Topic only after it subscribes to that Topic. Any messages posted before its subscription or any messages posted when it is inactive, cannot be delivered to that Consumer.
- Unlike P2P Model, in this model Destination does not store messages.
Just like P2P Model, Pub/Sub model also contains many possible architectures:
- One Publisher and many Subscribers
- Many Publishers and one Subscriber
- Many Publishers and many Subscribers
Differences between P2P and Pub/Sub Messaging Model
The following table explains the major differences between the two JMS Messaging Models.
S.No. | Point-To-Point Messaging Model | Publish/Subscribe Messaging Model |
---|---|---|
1. | Each message is delivered to one and only one JMS Receiver | Each message is delivered to multiple Consumers. |
2. | P2P Model has no timing dependency. | Pub/Sub model has some timing dependency. |
3. | JMS Receiver sends acknowledgements to JMS Sender once it receives messages. | Acknowledgement is not required. |
Awesome post!!! i love this post!
Awesome article. Appreciated your work. Really helpful for beginners like us. ๐๐
If I want to leverage Kafka and Kafka connect for P2P messaging , can I consider the P2P model as a specific case of PubSub messaging model ??
Awesome information.Thanks for your post. Add code snippet as well to get acknowledgement
I was confused about p2p and pub/sub differences and how they work. Now, I have understood very well after reading this post. However, I still do have some questions about whether pub/sub system requires acknowledgement or not. In my lecture, It is said it has acknowledgement . Moreover, pub/sub is a paradigm. But we still call it a system.
Thank you.
Awesome post !! ๐ Thanks for explaining it so nicely.