Show List
Introduction to JMS
Java Message Service (JMS) API is used for message communication between loosely coupled systems. It enables create, send and reading the message.
Features of JMS
- Asynchronous/Synchronous: JMS supports both asynchronous/synchronous message delivery. In asynchronous method, clients do not need to be online in order to received the message when it is sent. The message will be received when the client become available.
- Reliable: JMS can ensure that message will be delivered once and only once. This is helpful as duplicate message or lost messages can create problems.
- JMS supports both point-to-point and publish/subscribe messaging.
Point-to-point messaging
In point-to-point messaging, one message is delivered to one receiver only. Message is addressed to a particular queue. Queue holds the message until message is consumed or expired. The receiver sends acknowledgement after receiving the message.
Publish/Subscribe messaging
In the publish/subscribe messaging, a single message can be delivered to multiple clients that have subscribed to the topic. The topic holds and delivers the messages. The subscriber must continue to be available to consume the message.
JMS Components
JMS application has following main building blocks:
- JMS Provider: Various messaging servers support JMS API. Active MQ, Rabbit MQ and IBM MQ are some example messaging queues that support JMS. JMS provider is responsible for routing and delivery of messages.
- Connection factory is used to create connection for producer/receiver to connect to message queue or topic.
Message Components
JMS Message has three parts and may contain predefined/custom fields.
Message Header
Contains a number of fields that are used by sender/receiver to identify message. Examples:
- JMSDeliveryMode
- JMSMessageId
- JMSReplyTo
- JMSPriority
- JMSExpiration
Message Properties
These are custom name value pairs and can be used for filtering messages.
Message Body
Message body can have different formats. Examples:
- Text
- Object
- Bytes
- Stream
- Map
Leave a Comment