What is the difference between queue and topic

A connection is created between the client and the server from a connection factory. Connections can be shared by several threads. The user credentials are supplied at this level. It is probably common for a client application to share access to a single connection to the server (unless different security credentials are required for different destinations).
A session is created from a connection. The session may only be used by one thread at one time. The user credentials are inherited from the parent connection. It is probably common for each MessageProducer (TopicPublisher or QueueSender) or MessageConsumer (TopicSubscriber or QueueReceiver) to have their own session due to the threading restriction.
You can look at it like a tree. At the top you have a connection factory, beneath this you have your connections and then beneath the connections you have sessions. The leaves of the tree are the JMS actors (MessageProducers and MessageConsumers).

References: 

Creating Robust JMS Applications :  http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JMS6.html

 

Showing Answers 1 - 7 of 7 Answers

swap

  • May 3rd, 2005
 

Both work on 2 different comminication models. Queue is point-to-point and topic is publish-subscriber.

  Was this answer useful?  Yes

J. P. Naidu

  • Jul 27th, 2005
 

In queues message can be consumed by only one client where as in the topic it can consumed by n number of clients. Both are separate domain in MOM.  
 
Queue represent PTP domain and Topic represent Pub/Sub domain

sreenivasareddybade

  • Sep 27th, 2005
 

topic is used to send more than one system at a time. where as a queue is used to send one to one system. 

  Was this answer useful?  Yes

vijayshekar

  • Oct 17th, 2005
 

A point-to-point (PTP) product or application is built around the concept of message queues, senders, and receivers. Each message is addressed to a specific queue, and receiving clients extract messages from the queue(s) established to hold their messages. Queues retain all messages sent to them until the messages are consumed or until the messages expire.

In a publish/subscribe (pub/sub) product or application, clients address messages to a topic. Publishers and subscribers are generally anonymous and may dynamically publish or subscribe to the content hierarchy. The system takes care of distributing the messages arriving from a topic's multiple publishers to its multiple subscribers. Topics retain messages only as long as it takes to distribute them to current subscribers.

pradeep

  • Feb 12th, 2007
 

Could any one of you give some sample code for JMS and MDB

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions