Introduction to JMS
What is JMS?
Java Message Service (JMS) API is a part of
the Java Enterprise Edition (JEE) specification. JMS is all about
sending and receiving messages between two or more clients. It is a
specification that describes a method by which Java programs to create,
send and receive messages.
JMS API enables communication that is loosely coupled and messaging that is asynchronous in nature.
|What is Messages?|
|A message has been described in various ways by different specification. However it is an entity of the communication. It is bytes of data that is meaningful between the applications which use it. Messages are used to transfer information from one application to other ones which may or may not run in same platforms.|
|What is Messaging?|
|Messaging is communication between system
components or different applications (in a distributed environment)
which are loosely coupled unlike its peers like TCP sockets, CORBA or
RMI.Advantage of messaging:
The advantages of messaging include the ability to integrate different platforms, reduce system bottlenecks, increase scalability and reliability of message delivery.
A JMS Application consists of the following components:
JMS Provider: A messaging system that implements the JMS specification.
Messaging using MOM in JMS
In JMS Message Oriented Middleware (MOM) plays a vital role which differentiates messaging from its peers. MOM is a component that helps in message communication between two systems connected across network. MOM ensures asynchronous form of communication, supports reliable message delivery and transaction control. The Middleware creates a distributed communications layer that insulates the application developer from the details of the various operating system and network interfaces.
List of some of the MOM Service Providers:
|MOM Service Provider Products||Company|
JMS clients: Java applications that produce or receive messages.
- JMS Producer / Publisher: A JMS client that creates and sends messages.
- JMS Consumer/ Subscriber: A JMS client that receives messages.
Messages: Objects that are used to communicate information between JMS clients.
Administered objects: Pre-configured JMS objects that are created by an administrator for the use of JMS clients. These objects are isolated from the proprietary technology providers. This helps in JMS client’s portability.
Types of Messaging model:
Types of messaging domain model
As we discussed earlier a JMS application will have one or more JMS
clients that exchange message asynchronously with the help of MOM.
There are two types of messaging model in JMS:
Point to Point Messaging in JMS
a) Point to Point (PTP): In the PTP diagram the point-to-point (PTP) domain or application has three primary components like message queues, senders, and receivers. Each message is addressed to a specific queue, and receiving clients extract messages from the queues established to hold their messages. Queues retain all messages sent to them until the messages are consumed or until the messages timeouts.
Pub/Sub Messaging Model
b) Publisher/ Subscriber (Pub/Sub): In the Pub/Sub diagram clients address messages to a topic. Publishers and subscribers are generally anonymous and can dynamically publish or subscribe to the content hierarchy. Topics retain messages only as long as it takes to distribute them to current subscribers.
|Point to Point||Publisher/ Subscriber|
|Each message has only one consumer||Each message can have multiple consumers.|
|Messages are first sent to the destination named Queue.||Messages are first published in the destination called Topic.|
|A sender and a receiver of a message have no timing dependencies. The receiver can fetch the message whether or not it was running when the client sent the message.||Publishers and subscribers have a timing dependency. A client that subscribes to a topic can consume only messages published after the client has created a subscription, and the subscriber must continue to be active in order for it to consume messages.|
|The receiver acknowledges the successful processing of a message.||Does not provide acknowledgement|
Typical use of JMS in enterprise solutions:
a)JMS is useful where there might be requirement for pushing data to the consumers e.g. Bulletin board, News updates, Stock quotes, Auction websites etc.
b)Today the whole world is al about collaboration. Businesses and applications can interact with each other via messaging as JMS will allow them to integrate with each other without tight coupling.
In the next blogs we will explain more details on the implementation so keep watching this space. Please provide your feedback and comments on this article.
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)