The Java Message Service (JMS) API provides a common way for Java programs to create, send, receive and read an enterprise messaging system's messages.
A JMS application is composed of the following parts:
JMS providers differ significantly in their implementations of underlying messaging technology. There are also major differences in how a JMS provider's system is installed and administered.
For JMS clients to be portable, they must be isolated from these proprietary aspects of a provider. This is done by defining JMS administered objects that are created and customised by a provider's administrator and later used by clients. The client uses them through JMS interfaces that are portable. The administrator creates them using provider-specific facilities.
There are two types of JMS administered objects:
ConnectionFactory - the object a client uses to create a
connection with a JMS providerDestination - the object a client uses to specify the
destination of messages it is sending and the source of messages
it receivesAdministered objects are placed by an administrator in a JNDI (Java Naming and Directory Interface) namespace. A JMS client typically notes in its documentation the JMS administered objects it requires and how the JNDI names of these objects should be provided to it.
JMS supports two styles of messaging:
These two styles represent two of the dominant approaches to messaging currently in use.
For historical reasons JMS offers four alternative sets of interfaces for sending and receiving messages:
Each API offers a different set of interfaces for connecting to a JMS provider and for sending and receiving messages. However they all share a common set of interfaces for representing messages and message destinations and to provide various utility features.
All interfaces are in the javax.jms package.
The main interfaces common to multiple APIs are as follows:
Message, BytesMessage, MapMessage, ObjectMessage, StreamMessage and TextMessage -
a message sent to or received from a JMS provider.Queue - an administered object that encapsulates the identity of a message destination for point-to-point messagingTopic - an administered object that encapsulates the identity of a message destination for pub/sub messaging.Destination - the common supertype of Queue and TopicConnectionFactory - an administered object used by a client to create a Connection. This interface is also used by the simplified API.
Connection - an active connection to a JMS provider
Session - a single-threaded context for sending and receiving messages
MessageProducer - an object created by a Session that is used for sending messages to a queue or topic
MessageConsumer - an object created by a Session that is used for receiving messages sent to a queue or topic
ConnectionFactory - an administered object used by a client to create a JMSContext. This interface is also used by the classic API.
JMSContext - an active connection to a JMS provider and a single-threaded context for sending and receiving messages
JMSProducer - an object created by a JMSContext that is used for sending messages to a queue or topic
JMSConsumer - an object created by a JMSContext that is used for receiving messages sent to a queue or topic
Although the domain-specific API remains part of JMS for reasons of backwards compatibility it should be considered to be completely superseded by the classic and simplified APIs.
The main interfaces provided by the domain-specific API for point-to-point messaging are as follows:
QueueConnectionFactory - an administered object used by a client to create a QueueConnection.
QueueConnection - an active connection to a JMS provider
QueueSession - a single-threaded context for sending and receiving messages
QueueSender - an object created by a QueueSession that is used for sending messages to a queue
QueueReceiver - an object created by a QueueSession that is used for receiving messages sent to a queue
TopicConnectionFactory - an administered object used by a client to create a TopicConnection.
TopicConnection - an active connection to a JMS provider
TopicSession - a single-threaded context for sending and receiving messages
TopicPublisher - an object created by a TopicSession that is used for sending messages to a topic
TopicSubscriber - an object created by a TopicSession that is used for receiving messages sent to a topic
The term consume is used in this document to mean the receipt of a message by a JMS client; that is, a JMS provider has received a message and has given it to its client. Since JMS supports both synchronous and asynchronous receipt of messages, the term consume is used when there is no need to make a distinction between them.
The term produce is used as the most general term for sending a message. It means giving a message to a JMS provider for delivery to a destination.
Broadly speaking, a JMS application is one or more JMS clients that exchange messages. The application may also involve non-JMS clients; however, these clients use the JMS provider's native API in place of the JMS API.
A JMS application can be architected and deployed as a unit. In many cases, JMS clients are added incrementally to an existing application.
The message definitions used by an application may originate with JMS, or they may have been defined by the non-JMS part of the application.
A typical JMS client using the classic API executes the following JMS setup procedure:
ConnectionFactory objectDestination objectsConnection object with message delivery inhibitedSession objectsMessageProducer and MessageConsumer objects neededConnection to start delivery of messagesIn contrast, a typical JMS client using the simplified API does the following:
ConnectionFactory objectDestination objectsConnectionFactory to create a JMSContext objectJMSContext to create the JMSProducer and JMSConsumer objects needed.At this point a client has the basic JMS setup needed to produce and consume messages.
Java Message Service 2.0 specification
Java Platform, Enterprise Edition (Java EE) Technical Documentation
| Modifier and Type | Interface and Description |
|---|---|
| public interface | BytesMessage
A |
| public interface | CompletionListener
A |
| public interface | Connection
A |
| public interface | ConnectionConsumer
For application servers, |
| public interface | ConnectionFactory
A |
| public interface | ConnectionMetaData
A |
| public interface | DeliveryMode
The delivery modes supported by the JMS API are |
| public interface | Destination
A |
| public interface | ExceptionListener
If a JMS provider detects a serious problem with a |
| public interface | JMSConsumer
A client using the simplified JMS API introduced for JMS 2.0 uses a
|
| public interface | JMSContext
A |
| public interface | JMSProducer
A |
| public interface | MapMessage
A |
| public interface | Message
The |
| public interface | MessageConsumer
A client uses a |
| public interface | MessageListener
A |
| public interface | MessageProducer
A client uses a |
| public interface | ObjectMessage
An |
| public interface | Queue
A |
| public interface | QueueBrowser
A client uses a |
| public interface | QueueConnection
A |
| public interface | QueueConnectionFactory
A client uses a |
| public interface | QueueReceiver
A client uses a |
| public interface | QueueSender
A client uses a |
| public interface | QueueSession
A |
| public interface | ServerSession
A |
| public interface | ServerSessionPool
A |
| public interface | Session
A |
| public interface | StreamMessage
A |
| public interface | TemporaryQueue
A |
| public interface | TemporaryTopic
A |
| public interface | TextMessage
A |
| public interface | Topic
A |
| public interface | TopicConnection
A |
| public interface | TopicConnectionFactory
A client uses a |
| public interface | TopicPublisher
A client uses a |
| public interface | TopicSession
A |
| public interface | TopicSubscriber
A client uses a |
| public interface | XAConnection
The |
| public interface | XAConnectionFactory
The |
| public interface | XAJMSContext
The |
| public interface | XAQueueConnection
An |
| public interface | XAQueueConnectionFactory
An |
| public interface | XAQueueSession
An |
| public interface | XASession
The |
| public interface | XATopicConnection
An |
| public interface | XATopicConnectionFactory
An |
| public interface | XATopicSession
An |
| Modifier and Type | Annotation and Description |
|---|---|
| public @interface | JMSConnectionFactory
This annotation may be used to specify the JNDI lookup name of a |
| public @interface | JMSConnectionFactoryDefinition
An application may use this annotation to specify a JMS |
| public @interface | JMSConnectionFactoryDefinitions
Specifies one or more |
| public @interface | JMSDestinationDefinition
An application may use this annotation to specify a JMS |
| public @interface | JMSDestinationDefinitions
Specifies one or more |
| public @interface | JMSPasswordCredential
This annotation may be used to specify the userName and password
to be used when injecting a |
| public @interface | JMSSessionMode
This annotation may be used to specify the session mode
to be used when injecting a |
| Modifier and Type | Class and Description |
|---|---|
| public class | IllegalStateException
This exception is thrown when a method is invoked at an illegal or inappropriate time or if the provider is not in an appropriate state for the requested operation. |
| public class | IllegalStateRuntimeException
This unchecked exception is thrown when a method is invoked at an illegal or
inappropriate time or if the provider is not in an appropriate state for the
requested operation, and the method signature does not permit a
|
| public class | InvalidClientIDException
This exception must be thrown when a client attempts to set a connection's client ID to a value that is rejected by a provider. |
| public class | InvalidClientIDRuntimeException
This unchecked exception must be thrown when a client attempts to set a
connection's client ID to a value that is rejected by a provider, and the
method signature does not permit a |
| public class | InvalidDestinationException
This exception must be thrown when a destination either is not understood by a provider or is no longer valid. |
| public class | InvalidDestinationRuntimeException
This unchecked exception must be thrown when a destination either is not
understood by a provider or is no longer valid, and the method signature does
not permit a |
| public class | InvalidSelectorException
This exception must be thrown when a JMS client attempts to give a provider a message selector with invalid syntax. |
| public class | InvalidSelectorRuntimeException
This unchecked exception must be thrown when a JMS client attempts to give a
provider a message selector with invalid syntax, and the method signature
does not permit a |
| public class | JMSException
This is the root class of all checked exceptions in the JMS API. |
| public class | JMSRuntimeException
This is the root class of all unchecked exceptions in the JMS API. |
| public class | JMSSecurityException
This exception must be thrown when a provider rejects a user name/password submitted by a client. |
| public class | JMSSecurityRuntimeException
This unchecked exception must be thrown when a provider rejects a user
name/password submitted by a client, or for any case where a security
restriction prevents a method from completing, and the method signature does
not permit a |
| public class | MessageEOFException
This exception must be thrown when an unexpected
end of stream has been reached when a |
| public class | MessageFormatException
This exception must be thrown when a JMS client attempts to use a data type not supported by a message or attempts to read data in a message as the wrong type. |
| public class | MessageFormatRuntimeException
This unchecked exception must be thrown when a JMS application attempts to
use a data type not supported by a message or attempts to read data in a
message as the wrong type, and the method signature does not permit a
|
| public class | MessageNotReadableException
This exception must be thrown when a JMS client attempts to read a write-only message. |
| public class | MessageNotWriteableException
This exception must be thrown when a JMS client attempts to write to a read-only message. |
| public class | MessageNotWriteableRuntimeException
This unchecked exception must be thrown when a JMS client attempts to write to a read-only message. |
| public class | QueueRequestor
The |
| public class | ResourceAllocationException
This exception is thrown when a provider is unable to allocate the resources required by a method. |
| public class | ResourceAllocationRuntimeException
This unchecked exception is thrown when a provider is unable to allocate the resources required by a method. |
| public class | TopicRequestor
The |
| public class | TransactionInProgressException
This exception is thrown when an operation is invalid because a transaction is in progress. |
| public class | TransactionInProgressRuntimeException
This unchecked exception is thrown when an operation is invalid because a transaction is in progress. |
| public class | TransactionRolledBackException
This exception must be thrown when a
call to |
| public class | TransactionRolledBackRuntimeException
This unchecked exception must be thrown when a call to
|