## JMS Basics

### JMS components

Java Message Service (JMS) is a Java Message Oriented Middleware (MOM) API for sending messages between two or more clients.

If you are unfamiliar with JMS, you may want to read the Java Message Service API section of Sun Microsystems' J2EE 1.4 Tutorial

A JMS system is comprised of the following components:

- Providers

- Messages

- Clients

- Destinations

### Providers

The JMS provider is a messaging system that implements the JMS interfaces. Message broker such as Apache ActiveMQ and FUSE Message Broker are examples of providers.

### Messages

A messages is an object that contains the data being transferred between JMS clients.

### Clients

A client is an application that uses the services of the message broker. There are two types of client in a JMS system:

Producer

  Producers create messages and send them to the broker for delivery to a particular destination.

Consumer

  Consumers retrieve messages from a destination.

### Destinations

Destinations are maintained by the message broker. They can be either queues or topics.

### Queues

A queue is a destination that contains messages that have been sent and are waiting to be read. Messages are delivered in the order sent.A message is removed from the queue once it has been read.

Queues are used for point-to-point or one-to-one messaging.

Figure 2.1. Point-to-point Messaging

### Topics

Topics are used to send messages to one or more consumers. Producers publish messages to a topic and one or more consumers subscribe to the topic

In this one-to-many messaging scenario, producers are also referred to as publishers and consumers as subscribers.

Figure 2.2. Publish-Subscribe Messaging