Java Message Service (JMS) API
The Java Message Service is a Java API that allows applications to create, send, receive, and read messages.
The JMS API defines a common set of interfaces and associated semantics that allow programs written in the Java programming language to communicate with other messaging implementations.
The JMS API enables communication that is not only loosely coupled but also,
- Asynchronous: A JMS provider can deliver messages to a client as they arrive; a client does not have to request messages in order to receive them.
- Reliable: The JMS API can ensure that a message is delivered once and only once. Lower levels of reliability are available for applications that can afford to miss messages or to receive duplicate messages.
A JMS application is composed of the following parts:
- JMS Clients – These are the Java language programs that send and receive messages.
- Non-JMS Clients – These are clients that use a message system’s native client API instead of JMS.
- Messages – Each application defines a set of messages that are used to communicate information between its clients.
- JMS Provider – This is a messaging system (MOM) that implements JMS API in addition to the other administrative and control functionality required of a full featured messaging product.
- Administered Objects – Administered objects are preconfigured JMS objects created by an administrator for the use of clients.
JMS Administered Objects
There are two types of JMS administered objects:
- ConnectionFactory – This is the object a client uses to create a connection with a provider.
- Destination – This is the object a client uses to specify the destination of messages it is sending and the source of messages it receives.
JMS Messaging Models
The JMS API supports two models:
Point-to-Point (PTP) Model
- In point-to-point messaging model, a producer creates and sends a message which will be received only by a single consumer.
- In point-to-point model, the message destination is called “Queue”.
- PTP characteristics,
- Each message has only one consumer.
- 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.
- The receiver acknowledges the successful processing of a message.
- In publish/subscribe model, any number of clients can subscribe to a message destination and when a client sends (publishes) a message to the destination, that message is received by all clients who have subscribed to that destination.
- In this model, the message producer is called publisher and the consumers are called subscribers. Also the message destination is called “Topic”.
- Publish/Subscribe model characteristics,
- Each message can have multiple consumers.
- 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.