JMS architecture is a widely acclaimed architecture in the messaging world.The Java Message Service (JMS), which is designed by Sun Microsystems and several other companies under the Java Community Process as JSR 914, is the first enterprise messaging API that has received wide industry support. The Java Message Service (JMS) was designed to make it easy to develop business applications that asynchronously send and receive business data and events. It defines a common enterprise messaging API that is designed to be easily and efficiently supported by a wide range of enterprise messaging products. JMS supports both messaging models: point-to-point (queuing) and publish-subscribe

JMS was defined to allow Java application to use enterprise messaging systems. More importantly, it provides a common way for Java applications to access such enterprise messaging systems. JMS falls under middleware, and specifically Message-Oriented Middleware (MOM), which is a relatively low-level of abstraction that runs underneath complementary layers such as database and application adapters, event processing, and business process automation. MOM is becoming an essential component for integrating intra-company operations as it allows separate business components to be combined into a reliable, yet flexible, system.

JMS defines a set of interfaces and semantics that allow Java applications to communicate with other messaging implementations. A JMS implementation is known as a JMS provider. JMS makes the learning curve easy by minimizing the set of concepts a Java developer must learn to use enterprise messaging products, and at the same time it maximizes the portability of messaging applications.

JMS Architecture


A JMS application is composed of the following parts:

  • A JMS provider: A messaging system that implements the JMS specification.
  • JMS clients: Java applications that send and receive messages.
  • Messages: Objects that are used to communicate information between JMS clients.
  • Administered objects: Preconfigured JMS objects that are created by an administrator for the use of JMS clients.
READ  JMS-Point-to-point interfaces

Message Delivery Models

JMS supports two different message delivery models:

Point-to-Point (Queue destination): In this model, a message is delivered from a producer to one consumer. The messages are delivered to the destination, which is a queue, and then delivered to one of the consumers registered for the queue. While any number of producers can send messages to the queue, each message is guaranteed to be delivered, and consumed by one consumer. If no consumers are registered to consume the messages, the queue holds them until a consumer registers to consume them.

Publish/Subscribe (Topic destination): In this model, a message is delivered from a producer to any number of consumers. Messages are delivered to the topic destination, and then to all active consumers who have subscribed to the topic. In addition, any number of producers can send messages to a topic destination, and each message can be delivered to any number of subscribers. If there are no consumers registered, the topic destination doesn’t hold messages unless it has durable subscription for inactive consumers. A durable subscription represents a consumer registered with the topic destination that can be inactive at the time the messages are sent to the topic.

The JMS Programming Model

A JMS application consists of a set of application-defined messages and a set of clients that exchange them. JMS clients interact by sending and receiving messages using the JMS API. A message is composed of three parts: header, properties, and a body.

The header, which is required for every message, contains information that is used for routing and identifying messages. Some of these fields are set automatically, by the JMS provider, during producing and delivering a message, and others are set by the client on a message by message basis.

READ  JMS Interview Questions

Properties, which are optional, provide values that clients can use to filter messages. They provide additional information about the data, such as which process created it, the time it was created. Properties can be considered as an extension to the header, and consist of property name/value pairs. Using properties, clients can fine-tune their selection of messages by specifying certain values that act as selection criteria.

The body, which is also optional, contains the actual data to be exchanged. The JMS specification defined six type or classes of messages that a JMS provider must support:

  • Message: This represents a message without a message body.
  • StreamMessage: A message whose body contains a stream of Java primitive types. It is written and read sequentially.
  • MapMessage: A message whose body contains a set of name/value pairs. The order of entries is not defined.
  • TextMessage: A message whose body contains a Java string…such as an XML message.
  • ObjectMessage: A message whose body contains a serialized Java object.
  • BytesMessage: A message whose body contains a stream of uninterpreted bytes.

Producing and Consuming Messages

Here are the necessary steps to develop clients to produce and consumer messages. Note that there are some common steps that shouldn’t be duplicated if the client is both producing and consuming messages. Figure below depicts the high-level view of the steps

Producing and Consuming Messages

Producing and Consuming Messages