There are two kinds of Messaging.
- Synchronous Messaging: Synchronous messaging involves a client that waits for the server to respond to a message.
- Asynchronous Messaging: Asynchronous messaging involves a client that does not wait for a message from the server. An event is used to trigger a message from a server.
Each JMS-enabled client must establish the following:
A connection object provided by the JMS server (the message broker)
Within a connection, one or more sessions, which provide a context for message sending and receiving
Within a session, either a queue or topic object representing the destination (the message staging area) within the message broker
Within a session, the appropriate sender or publisher or receiver or subscriber object (depending on whether the client is a message producer or consumer and uses a point-to-point or publish/subscribe strategy, respectively)
Within a session, a message object (to send or to receive)
A JMS message consists of three parts:
- Message header - For message identification. For example, the header is used to determine if a given message is appropriate for a "subscriber"
- Properties - For application-specific, provider-specific, and optional header fields
- Body - Holds the content of the message. Several formats are supported, including TextMessage, which wrap a simple String, that wrap arbitrary Java objects (which must be serializable). Other formats are supported as well.
In point-to-point, messages are sent via queues. Messages are put onto the queues by the message producers (the clients). The message consumer is responsible for pulling the message from the queue. Point-to-point is typically used when a given message must be processed (received) only once by a given consumer. In this way, there is only one consumer of the given message.
In publish-and-subscribe, messages are sent through topics. Messages are published to topics by the message producers. The messages may be received by any consumers that subscribe to the given topic. In this way, a message may be received, or processed, by multiple consumers.
1. App server creates the server session and stores them in a pool.
2. Connection consumer uses the server session to put messages in the session of the JMS.
3. Server session is the one that spawns the JMS session.
4. Applications written by Application programmers creates the message listener.