JMS Queue vs. JMS Topic

By Kristen V. Erickson

Queues and topics are both elements of the Java Message Service, a Java middleware technology that connects software components and allows processes to interact with one another. The JMS elements -- provider, client, message, queue, topic, subscriber and publisher -- work together to provide reliable communication between systems within a computer network, distributing messages to the proper applicants. Queue and topic have similarities and differences.

Messaging Models

The two models for JMS messaging are publish-and-subscribe and point-to-point. Publish-and-subscribe, or pub/sub, allows the producer to send messages to many users at the same time. Consumers can subscribe to a particular topic, or channel, and receive all messages within the chosen topic. This model is asynchronous. Point-to-point, or p2p, allows users to send messages both asynchronously and synchronously using different channels called queues. Typically, in the p2p model, a user requests a message that a producer sends to the queue, rather than subscribing to a channel and receiving all messages sent on a particular topic.

Topic Channel

A JMS topic is the channel through which users subscribe to receive specific messages from a producer in the publish-and-subscribe model of JMS messaging. The model can be compared to subscribing to a newspaper; for example, if John Doe subscribed to "The New York Times," he would receive the paper every day from the newspaper publisher. Similarly, if John Doe used JMS messaging to subscribe to a particular topic, he would receive all sent messages from a producer regarding that topic.

Queue System

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.

Original Purpose

JMS is used in a variety of ways, but it was created specifically to allow different applications to communicate with each other. As technology advances and new computer applications are created, a messaging system that can interconnect applications and allow them to interoperate is essential. The two JMS communication models, pub/sub and p2p, permit various applications to interact with each other easily and dependably.