File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes JMS Queue and Topic Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "JMS Queue and Topic" Watch "JMS Queue and Topic" New topic

JMS Queue and Topic

Natalie Kopple
Ranch Hand

Joined: May 06, 2003
Posts: 325
Would someone help me to understand when we would use queue versus topic and vice versa? and why would someone use a queue with multiple consumers? Thank you.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33102

In a queue, only one destination gets the message and in a topic all subscribers get it. A queue with multiple consumers could be used for redundancy.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Natalie Kopple
Ranch Hand

Joined: May 06, 2003
Posts: 325
Thanks Jeanne for your help. I did some homework and also would like to answer my own question.

Using a queue with multiple consumers usually makes sense when different consumers are responsible for processing messages containing the same headers (often generated by the same producer) written onto the same queue. For instance, message selectors could be used in a trading application, to differentiate between buy and sell orders, when the producer is incapable of writing the JMS messages onto two separate buy and sell queues.

When multiple consumers use the same queue, message selectors need to be configured correctly across these consumers so that there is no conflict in determining the intended consumer.

In the case of message-driven-beans (a consumer of JMS messages), the selector can be specified in the ejb-jar.xml file thereby allowing for the configuration to be done at deployment time (instead of the opposing view of specifying the message selector during development).
I agree. Here's the link:
subject: JMS Queue and Topic
It's not a secret anymore!