When an application needs to send messages it use the {@code createProducer} method to create a {@code JMSProducer} whichprovides methods to configure and send messages. Messages may be sent either synchronously or asynchronously.
When an application needs to receive messages it uses one of several {@code createConsumer} or {@code createDurableConsumer} methods tocreate a {@code JMSConsumer} . A {@code JMSConsumer} providesmethods to receive messages either synchronously or asynchronously.
In terms of the JMS 1.1 API a {@code JMSContext} should be thought of asrepresenting both a {@code Connection} and a {@code Session}. Although the simplified API removes the need for applications to use those objects, the concepts of connection and session remain important. A connection represents a physical link to the JMS server and a session represents a single-threaded context for sending and receiving messages.
A {@code JMSContext} may be created by calling one of several{@code createContext} methods on a {@code ConnectionFactory}. A {@code JMSContext} that is created in this way is described as beingapplication-managed. An application-managed {@code JMSContext}must be closed when no longer needed by calling its {@code close}method.
Applications running in the Java EE web and EJB containers may alternatively inject a {@code JMSContext} into their application using the{@code @Inject} annotation. A {@code JMSContext} that is created inthis way is described as being container-managed. A container-managed {@code JMSContext} will be closed automatically bythe container.
Applications running in the Java EE web and EJB containers are not permitted to create more than one active session on a connection so combining them in a single object takes advantage of this restriction to offer a simpler API.
However applications running in a Java SE environment or in the Java EE application client container are permitted to create multiple active sessions on the same connection. This allows the same physical connection to be used in multiple threads simultaneously. Such applications which require multiple sessions to be created on the same connection should use one of the {@code createContext} methods on the {@code ConnectionFactory} tocreate the first {@code JMSContext} and then use the{@code createContext} method on {@code JMSContext} to createadditional {@code JMSContext} objects that use the same connection. Allthese {@code JMSContext} objects are application-managed and must beclosed when no longer needed by calling their {@code close} method. @version 2.0 @since 2.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|