Difference Between Queue and Topic

January 2023 · 3 minute read

Queue vs Topic

Java message service, or simply JMS, is a medium which sends messages to two or more clients. It permits contact between diverse mechanisms of a distributed application. This message-oriented middleware has two models which are the point-to-point model and publish or subscribe model. These two models have other names, too. The point-to-point model is also known as the queue model, and the publisher or subscriber model is also simply known as the topic model.

The queue or point-to-point model works by having a sender place messages to a queue, and the receiver will be able to read the messages from the queue. However, publisher or subscriber or the topic model works by disseminating messages by posting messages about a particular topic and having subscribers read them.

There are many differences between these two models which we will simply call “queue” and “topic.” In queue, the sender knows where the message will be going. There is a specific sender and a specific receiver, and there is the intention of being acknowledged as such. On the other hand, in topic you only have a publisher and a subscriber or subscribers. There is anonymity in the identity of both the publisher and subscriber.

Another main difference between the two is the number of recipients. In queue, you only have one receiver or consumer; unlike in topic where in you can have your message be disseminated to a number of subscribers. Also, in topic, the publisher has to be continuously active for a subscriber to receive the messages. Otherwise the message will be reallocated. In queue you do not have to worry about timing because the sender will have the luxury to send messages whenever he or she wants to. And the same goes for the receiver; he or she also has the liberty of reading it whenever he or she wants. In queue you will also be assured that as the sender you have successfully sent out your message because you will be notified by the receiver, but the same is not true for a topic system. There is even the risk of not having any subscribers.

SUMMARY:

1.The point-to-point or queue model works by the sender to receiver setup. On the other hand, publisher/subscriber or topic model works by bulletin setup.

2.In the queue model there is acknowledgement of the identity of the receiver and oftentimes the sender. In the topic model there is anonymity in the identities of both the subscriber and publisher.

3.Queue model is only allowed one recipient; topic, on the other hand, can have multiple recipients.

4.In queue model, the sender and receiver do not have to be both active at the same time. In the topic model, timing is very vital.

5.In the queue model, the sender will receive a notification when the message gets to the receiver. The topic model, on the other hand, will not notify you with such, and there is even a risk that you will have no subscribers.


ncG1vJloZrCvp2OxqrLFnqmeppOar6bA1p6cp2aemsFwwMScn6ennKS0unvIp6ueqp6awXCwyJ%2BdnqqVo7CmecGeq7CdlaN6ssHErpxmmZ6ZerW7z6KaaA%3D%3D