This is a typical interview question: What is the difference between a Queue and a Topic ( or Queue Vs Topic).
Before you go for the comparisons you need to learn the basics such as what is a JMS Queue what was the purpose of this technology and so on...
I would like to point you to this wiki page:
Topic: Java Message Service
After you have reviewed the above page you might have understood what is the difference already. But for those who are time short... read on.
First Elements of an JMS Queue:
JMS provider
An implementation of the JMS interface for a Message Oriented Middleware (MOM). Providers are implemented as either a Java JMS implementation or an adapter to a non-Java MOM.
JMS client An application or process that produces and/or receives messages.
JMS producer/publisher A JMS client that creates and sends messages.
JMS consumer/subscriber
A JMS client that receives messages.
JMS message
An object that contains the data being transferred between JMS clients.
JMS queue
A staging area that contains messages that have been sent and are waiting to be read. Note that, contrary to what the name queue suggests, messages have to be delivered in the order sent A JMS queue only guarantees that each message is processed only once.
JMS topic A distribution mechanism for publishing messages that are delivered to multiple subscribers.
Source: Java Message Service
The comparison: Queue VS Topic
Queue:
Descriptive example: A JMS queue is a channel through which users "pull" messages they want to receive using the p2p model, instead of automatically receiving messages on a particular topic. The producer submits messages to the queue, and recipients can browse the queue and decide which messages they wish to receive. In the p2p model, users can see the contents of the messages held in the queue before deciding whether or not to accept their delivery.
Topic:
Before you go for the comparisons you need to learn the basics such as what is a JMS Queue what was the purpose of this technology and so on...
I would like to point you to this wiki page:
Topic: Java Message Service
After you have reviewed the above page you might have understood what is the difference already. But for those who are time short... read on.
First Elements of an JMS Queue:
JMS provider
An implementation of the JMS interface for a Message Oriented Middleware (MOM). Providers are implemented as either a Java JMS implementation or an adapter to a non-Java MOM.
JMS client An application or process that produces and/or receives messages.
JMS producer/publisher A JMS client that creates and sends messages.
JMS consumer/subscriber
A JMS client that receives messages.
JMS message
An object that contains the data being transferred between JMS clients.
JMS queue
A staging area that contains messages that have been sent and are waiting to be read. Note that, contrary to what the name queue suggests, messages have to be delivered in the order sent A JMS queue only guarantees that each message is processed only once.
JMS topic A distribution mechanism for publishing messages that are delivered to multiple subscribers.
Source: Java Message Service
The comparison: Queue VS Topic
Queue:
- Point-to-point model
- Only one consumer gets the message
- Messages have to be delivered in the order sent
- A JMS queue only guarantees that each message is processed only once.
- The Queue knows who the consumer or the JMS client is. The destination is known.
- The JMS client (the consumer) does not have to be active or connected to the queue all the time to receive or read the message.
- Every message successfully processed is acknowledged by the consumer.
Descriptive example: A JMS queue is a channel through which users "pull" messages they want to receive using the p2p model, instead of automatically receiving messages on a particular topic. The producer submits messages to the queue, and recipients can browse the queue and decide which messages they wish to receive. In the p2p model, users can see the contents of the messages held in the queue before deciding whether or not to accept their delivery.
Topic:
- Publish/subscribe model
- Multiple clients subscribe to the message
- There is no guarantee messages have to be delivered in the order sent
- There is no guarantees that each message is processed only once. -- As this can be sensed from the model
- The Topic, have multiple subscribers and there is a chance that the topic does not know all the subscribers. The destination is unknown.
- The subscriber / JMS client needs to the active when the messages are produced by the producer, unless the subscription was a durable subscription.
- No, Every message successfully processed is not acknowledged by the consumer/subscriber.
No comments:
Post a Comment