Home           J2EE Concepts           JMS           Java Language           Contact           Back           Bookmark this Page          










Some useful tips related to:
 - health & fitness
 - vehicle care
 - cooking
 - misc household tasks

JMS API Building Blocks


A typical JMS applications consists of following:
- Connection factories
- Destinations
- Connections
- Sessions
- Message Producers
- Message Consumers
- Messages

 

A Connection Factory is used by a JMS client to create connection with the provider. Typically a connection factory is created using admin console. The code in client that instantiates connection factory looks like following:
   Context ctx = new InitialContext();
   ConnectionFactory connectionFactory = (ConnectionFactory) ctx.lookup("jms/ConnectionFactory");

A Destination represents the source or target of messages for a client. In point to point domain, destinations are called Queues & in publish subscriber domain, destinations are called Topics.
A JMS application can have any combination of queues & topics.

A Connection represents virtual connection with the provider. This concept is similar to JDBC connection.
Before dealing with messages, you must first open a connection and when finished you must close it too. Failure to properly closing a connection could lead to issues simliar to leaving an open connection with DB.

A Session could be thought of as a single threaded context for producing & consuming messages. Sessions can also be understood better if we compare them to JDBC sessions. Multiple sessions can be opened on single connection & closing a connection would result in close all of its sessions.

A Message Producer is an object created by a session and used for sending messages to a destination.

A Message Consumer is used for receiving messages sent by message producer.

A Message typically consists of three parts: header, properties (optional) & body (optional).