We will go for practical implementation in the next topic. This topic provides theoretical background of JMS.
A part of Java Enterprise Edition, JMS (Java Message Service) is used to create, send, receive and read messages between two or more clients. The communication is loosely coupled, reliable and asynchronous. A JMS application consists of a JMS provider, JMS clients, Message objects used in communication, and Administered Objects created by administrators for the use of clients.
The JMS specification provides for both point-to-point (PTP) and publish/subscribe approach to messaging. In point-to-point messaging approach, a client submits the massage to a queue, and the consumer client picks up the message from the queue, with each message having only one consumer. In pub/sub (publish/subscribe) approach, clients address message to a topic, which is then pushed on by the topic to one of the multiple subscribers. Before a client can act as a subscriber, it must have registered as a subscriber with the topic.
JMS Administered Objects provide for destination and connection factories, and are usually configured in JNDI namespace.
A JMS Connection factory is responsible for providing connection object from client to the provider. Each connection factory is an instance of the ConnectionFactory, QueueConnectionFactory, or TopicConnectionFactory interface.
A JMS Destination is either a queue in PTP, or a topic in Pub/Sub approach. A JMS Connection implements Connection interface, and encapsulates connection information.
A JMS Session provides a single threaded context to produce and consume messages. Sessions create MessageProducer objects for a destination, queue or a topic object. These objects are used to send messages to the destination using send method. Session also creates MessageConsumer objects to receive messages from one of the source.
JMS Message Listener object implements MessageListener interface and provides an asynchronous event handler. It contains a method onMessage, which defines the actions to be taken. The listener object is registered with the consumer before it starts receiving the message.
A JMS Message comprises three parts: header (compulsory), properties and body. More information on this will be in subsequent parts as we start the actual coding.