Examples:
Content
- #1: activemq-p2p
Example #1
activemq-p2p
Description
- Point-To-Point (ActiveMQ P2P Messaging)
- A message can be delivered to one receiver only. Here, Queue is used as a message-oriented middleware.
- The messages stay in the queue until received and processed.
- There is no timing-related dependency between the sender and receiver. Sent messages could be retrieved without any expiry.
Description and code: http://jreact.com/index.php/2024/05/08/activemq-p2p/
Messaging Domains
- Point-To-Point (P2P Messaging)
- A message can be delivered to one receiver only. Here, Queue is used as a message-oriented middleware (MOM).
- The messages stay in the queue until received and processed.
- There is no timing-related dependency between the sender and receiver. Sent messages could be retrieved without any expiry.
- Publisher/Subscriber (Pub/Sub Messaging)
- A message can be delivered to all of its subscribers.
- We could also use a Topic as a message-oriented middleware that is responsible for holding and delivering messages.
- There is a timing dependency between the publisher and the subscriber.

Queue vs. Topic
With JMS you have the option of publishing messages to a Topic or Queue. There is a fundamental difference between the two which is illustrated below. A Topic forwards a message from the producer to many consumers at once. It’s a broadcast. This is often called Publish-and-Subscribe (Pub/Sub) messaging. A Queue may also have many consumers, but it forwards each message to only one consumer. The consumers wait in line, in a queue, taking turns getting new messages from the Queue. This often called Point-to-Point (P2P) messaging.

- Topics
- In JMS, a Topic implements publish and subscribe semantics.
- When you publish a message, it goes to all the subscribers who are interested – so zero to many subscribers will receive a copy of the message.
- Only subscribers who had an active subscription at the time the broker receives the message will get a copy of the message.
- Queues
- A JMS Queue implements load balancer semantics.
- A single message will be received by exactly one consumer.
- If there are no consumers available at the time the message is sent, it will be kept until a consumer is available that can process the message.
- If a consumer receives a message and does not acknowledge it before closing, then the message will be redelivered to another consumer.
- A queue can have many consumers with messages loaded and balanced across the available consumers.So Queues implement a reliable load balancer in JMS.
