JMS Overview
The Java Message Service (JMS) is a Java API that allows applications to create, send, receive, and read messages.JMS enables distributed communication that is loosely coupled, reliable, and asynchronous.Messages can be sent in two ways—PTP(Queue) and Pub/Sub(Topic)
Figure 1 illustrates the way these parts interact. Administrative tools allow you to bind destinations and connection factories into a Java Naming and Directory InterfaceTM (JNDI) API namespace. A JMS client can then look up the administered objects in the namespace and then establish a logical connection to the same objects through the JMS provider.
Figure 2 Point-to-Point Messaging
Figure 3 Publish/Subscribe Messaging
Figure 4 The JMS API Programming Model
Table 1 Relationship of PTP and Pub/Sub interfaces
JMS Parent | PTP Domain | Pub/Sub Domain |
ConnectionFactory | QueueConnectionFactory | TopicConnectionFactory |
Connection | QueueConnection | TopicConnection |
Destination | Queue | Topic |
Session | QueueSession | TopicSession |
MessageProducer | QueueSender | TopicPublisher |
MessageConsumer | QueueReciever, QueueBrowser | TopicSubscriber |
Developing a JMS Client
1. Use JNDI to find a ConnectionFactory object.
2. Use JNDI to find one or more Destination objects.
3. Use the ConnectionFactory to create a JMS Connection.
4. Use the Connection to create one or more JMS Sessions.
5. Use a Session and the Destinations to create the MessageProducers and MessageConsumers needed.
6. Tell the Connection to start delivery of messages.
Multi-Threading
Table 2 JMS objects that support concurrent use
JMS Object | Supports Concurrent Use |
Destionation | Yes |
ConnectionFactory | Yes |
Connection | Yes |
Session | No |
MessageProducer | No |
MessageConsumer | No |
Table 3 Message Header Field Value Sent
Header Fields | Set By |
JMSDestination | Send Method |
JMSDeliveryMode | Send Method |
JMSExpiration | Send Method |
JMSPriority | Send Method |
JMSMessageID | Send Method |
JMSTimestamp | Send Method |
JMSCorrelationID | Client |
JMSReplyTo | Client |
JMSType | Client |
JMSRedelivered | Provider |
JMS Message Body
StreamMessage |
MapMessage |
TextMessage |
ObjectMessage |
BytesMessage |