Java Messaging Service (JMS)
Messaging is a common integration pattern used by Java applications. The Java messaging API (JMS) supports message creation, delivery, receipt and the ability to read messages. JMS defines roles for messaging services known as JMS providers and guarantees delivery between systems. Popular implementations of JMS are Active MQ, IBM MQ and Open MQ.
Common messaging models
1) Point-to-point
A JMS producer will write a message to a queue which is then consumed off the queue by a single JMS consumer.

2) Publish-subscribe
The pub-sub messaging model uses a topic instead of a queue which facilitates messages to be distributed to multiple JMS consumers instead of a single consumer.

Message Structure
A JMS message contains 3 sections:
a) Headers
The JMS headers are fixed across all JMS messages and include the destination, delivery method, message ID, delivery time and other envelope information.
b) Properties
The properties section of the message allows producers or the JMS provider to add optional headers to the message that can be read by the consumers.
c) Body
The body of the JMS message can be one of five types, providing support for streams, maps, text, objects or bytes.

JMS interfaces
| API | Description |
| ConnectionFactory | Encapsulates the connection configuration parameters |
| JMSContext | Provides a combination of session and connection; allows for the creation of consumers and producers |
| JMSConsumer | Client object for reading messages from a queue or topic |
| JMSProducer | Object for building and sending messages to a queue or topic |
JMS Producers
Within the JMS API, the producer interface is used to send messages to a JMS Queue or topic. The approach for creating a producer and sending a message has been simplified with the use of annotations since JMS 2.0.
You May Also Like