What is the Difference Between Queue and Topic

The main difference between queue and topic is that queue is the message-oriented middleware used in point to point message domain, while the topic is the message-oriented middleware used in publisher- subscriber message domain.

Java Message Service (JMS) is an application program interface (API) from Sun Microsystems that supports the formal communication known as messaging between computers in a network. In other words, it helps to establish reliable communication between various components of distributed applications. Furthermore, JMS has two messaging domains or models which are point to point and publisher-subscriber.  

Key Areas Covered

1. What is Queue
      -Definition, Functionality
2. What is Topic
     -Definition, Functionality
3. Difference Between Queue and Topic
     -Comparison of Key Differences

Key Terms

JMS, Queue, Topic

Difference Between Queue and Topic - Comparison Summary

What is Queue

In the point to point model, the sender sends a message to a receiver. The sender stores the messages into a queue and the receiver reads the messages from the queue. It holds the message until its receiver reads the message. The queue works as the message-oriented middleware in point to point messaging domain. In this model, the sender knows about the destination of the message. In other words, it knows whether the message is going.

Difference Between Queue and Topic

There is no specific timing requirement in point to point model. Therefore, the sender can send the message at any time. Similarly, the receiver can read the message at any time. Another advantage of the queue is the acknowledgement of the identity of the receiver and the sender. In this model, the receiver can notify the sender. Therefore, the sender knows that the receiver got the message successfully.

What is Topic

In the publisher or subscriber model, the publisher posts or publishes a message and the subscribers can read it. It is similar to broadcasting. In other words, there are multiple subscribers. The topic is responsible for holding and delivering the messages.

Furthermore, in this model, the publisher has to remain active for a subscriber to obtain the messages. If not, there is a possibility of reallocating the messages. Moreover, there are no acknowledgements. Thus, it can lead to a publisher not having any subscribers.

Difference Between Queue and Topic

Definition

The queue is the message-oriented middleware that holds the message until the receiver is ready. In contrast, the topic is the message-oriented middleware that is responsible for holding and delivering messages to subscribers. Thus, this is the main difference between queue and topic.

Functionality

In point to point messaging, the sender stores the messages on the queue and the receiver reads the messages from the queue. On the other hand, in publisher, subscriber messaging, the sender stores the messages on the topic and topic delivers the messages to the subscribers.

Number of clients

Also, another difference between queue and topic is that queue works with a receiver while the topic works with multiple subscribers.

Conclusion

Java Message Service (JMS) is a Java message-oriented middleware API for sending messages. It mainly supports two messaging models or domains which are point to point and publisher-subscriber. Point to point uses queue while publisher-subscriber uses topic. The main difference between queue and topic is that queue is the message-oriented middleware used in point to point message domain while the topic is the message-oriented middleware used in publisher-subscriber message domain.

References:

1.“JMS Tutorial – Javatpoint.” Www.javatpoint.com, Available here.

Image Courtesy:

1.”2327538″ (CC0) via Pixabay

About the Author: Lithmee

Lithmee holds a Bachelor of Science degree in Computer Systems Engineering and is reading for her Master’s degree in Computer Science. She is passionate about sharing her knowldge in the areas of programming, data science, and computer systems.

Leave a Reply