Java Reference
In-Depth Information
All relevant shipping information, such as the item number, shipping address, shipping
method, and insurance amount, is packed into a message and sent out to the
Ship-
pingRequestQueue
.
Listing 4.1. JMS code that sends out shipping requests from ActionBazaar
As we explain each step of this code in the following sections, we'll go through a larger
subset of the JMS API and note usage patterns. For simplicity, the code for exception hand-
ling has been removed.
Retrieving the connection factory and destination
In JMS, message server resources are similar to JDBC
javax.sql.DataSource
ob-
jects. These resources are created and configured outside the code and stored in the server
JNDI registry, usually through XML or an administrative console. JMS has two primary
types of resources:
javax.jms.JMSContext
and
javax.jms.Destination
injection with the CDI
@Inject
annotation and configure the
JMSContext
to
connect to a connection factory with the
@JMSConnectionFactory
annotation.
The
JMSContext
wraps a
javax.jmx.ConnectionFactory
and
javax.jmx.Session
in one object. The
JMSContext
was introduced with EE 7
to simplify JMS operations and also to make it easier to stick to the one-session-per-
connection restriction in EE environments (this isn't a restriction in SE applications).