Java Message Service
The Java Message Service (JMS) is an API that allows software to create, edit, read, and send messages among other
software applications or components. The API allows resources to be created within an application server that
facilitate messaging capability in various contexts. The application server creates, houses, and maintains Connection
Factory and Destination resources. That being said, different application server implementations may have minor
differences in their JMS implementations.
In addition to the basic messaging facilities, JMS also provides the ability to send messages to destinations and
publish messages to subscriptions. This chapter contains examples that focus on basic concepts of JMS, as well as
some advanced techniques and new additions with Java EE 7. When following along with the examples, it should be
noted that JMS could be used in various situations for creating many different types of messages. That being said,
many of the examples in this chapter will be invoked using JSF view actions, although in real-life applications there
are many different ways to implement the sending and receiving of messages. From internal message invocation,
to scheduled tasks via an Enterprise JavaBean (EJB) timer, and even implementation of JMS messaging with EJB
message-driven beans, JMS can be utilized in many different contexts. After reading through the examples, you should
be able to apply the strategies utilized within the recipes in order to create the messaging system of your needs.
New to JMS 2.0 is a simplified API for sending and receiving messages. In this chapter, you will see the standard
API in comparison with the simplified API. The updated API also includes enhancements to message subscriptions,
delivery delay, and more. This chapter will touch upon these new features, providing examples to get you started for
using them within your own applications.
JMS provides a facility for applications to send and receive messages in a loosely coupled manner. Senders
can publish messages to a JMS destination, and consumers can retrieve messages from those destinations via
subscription. Utilizing this messaging model, the sender and receiver do not need to know about each other; they only
need to know the types of messages being sent and consumed, along with the destination.
JMS offers a couple of different messaging domains that can be used, each providing different features so that
an application can utilize the one that makes the most sense for the particular solution. The two types are Point-To-
Point (PTP) and Publish/Subscribe (pub/sub). PTP messaging involves message queues, in which publishers can
send messages to a specific queue, and receivers extract messages from a specific queue. Queues have the following
Messages sent to a queue can have only one consumer.
Senders and receivers do not have to coordinate the sending/receiving process. The sender
publishes the message and the receiver consumes it, when available.
Receivers acknowledge a successful processing once they have consumed a message.