JMSContext is the main interface in the simplified Jakarta Messaging API introduced for Jakarta Messaging 2.0. This combines in a
single object the functionality of two separate objects from the Java Message Service 1.1 API: a Connection and a
Session.
When an application needs to send messages it use the createProducer method to create a JMSProducer
which provides 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 createConsumer or
createDurableConsumer methods to create a JMSConsumer . A JMSConsumer provides methods to
receive messages either synchronously or asynchronously.
In terms of the Java Message Service 1.1 API a JMSContext should be thought of as representing both a Connection and a
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 Jakarta Messaging server and a session
represents a single-threaded context for sending and receiving messages.
A JMSContext may be created by calling one of several createContext methods on a
ConnectionFactory. A JMSContext that is created in this way is described as being
application-managed. An application-managed JMSContext must be closed when no longer needed by calling
its close method.
Applications running in the Jakarta EE web and EJB containers may alternatively inject a JMSContext into their
application using the @Inject annotation. A JMSContext that is created in this way is described as
being container-managed. A container-managed JMSContext will be closed automatically by the container.
Applications running in the Jakarta 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 Jakarta 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 createContext methods on the ConnectionFactory to create the first
JMSContext and then use the createContext method on JMSContext to create additional
JMSContext objects that use the same connection. All these JMSContext objects are application-managed
and must be closed when no longer needed by calling their close method.
| Modifier and Type | Field and Description |
|---|---|
| public static final int | AUTO_ACKNOWLEDGE
With this session mode, the JMSContext's session automatically acknowledges a client's receipt of a message either
when the session has successfully returned from a call to |
| public static final int | CLIENT_ACKNOWLEDGE
With this session mode, the client acknowledges a consumed message by calling the message's |
| public static final int | DUPS_OK_ACKNOWLEDGE
This session mode instructs the JMSContext's session to lazily acknowledge the delivery of messages. |
| public static final int | SESSION_TRANSACTED
This session mode instructs the JMSContext's session to deliver and consume messages in a local transaction which
will be subsequently committed by calling |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public void | close()
Redeclares java. This closes the underlying session and any underlying producers and consumers. |
| public void | |
| public QueueBrowser | Returns: The createdQueueBrowser object.the queue)queue to accessCreates a |
| public QueueBrowser | Returns: The createdQueueBrowser object.the queue, String queue to accessonly messages with properties matching the message selector expression are delivered. A value
of null or an empty string indicates that there is no message selector for the message consumer. messageSelector)Creates a |
| public BytesMessage | |
| public JMSConsumer | Returns: The createdJMSConsumer object.the destination)Destination to access.Creates a |
| public JMSConsumer | Returns: The createdJMSConsumer object.the destination, String Destination to accessonly messages with properties matching the message selector expression are delivered. A value
of null or an empty string indicates that there is no message selector for the messageSelector)JMSConsumer.Creates a |
| public JMSConsumer | Returns: The createdJMSConsumer object.the destination, String Destination to accessonly messages with properties matching the message selector expression are delivered. A value
of null or an empty string indicates that there is no message selector for the messageSelector, boolean JMSConsumer.if true, and the destination is a topic, then the noLocal)JMSConsumer will not receive messages
published to the topic by its own connectionCreates a |
| public JMSContext | Returns: a newly created JMSContextindicates which of four possible session modes will be used. The permitted values are
sessionMode)JMSContext.SESSION_TRANSACTED, JMSContext.CLIENT_ACKNOWLEDGE, JMSContext.AUTO_ACKNOWLEDGE and
JMSContext.DUPS_OK_ACKNOWLEDGE.Creates a new |
| public JMSConsumer | Returns: The createdJMSConsumer object.the non-temporary topic, String Topic to subscribe tothe name used to identify this subscription name)Creates an unshared durable subscription on the specified topic (if one does not already exist) and creates a consumer on that durable subscription. |
| public JMSConsumer | Returns: The createdJMSConsumer object.the non-temporary topic, String Topic to subscribe tothe name used to identify this subscription name, String only messages with properties matching the message selector expression are added to the
durable subscription. A value of null or an empty string indicates that there is no message selector for the durable
subscription. messageSelector, boolean if true then any messages published to the topic using this session's connection, or any other
connection with the same client identifier, will not be added to the durable subscription. noLocal)Creates an unshared durable subscription on the specified topic (if one does not already exist), specifying a message
selector and the |
| public MapMessage | |
| public Message | |
| public ObjectMessage | |
| public ObjectMessage | Returns: The createdObjectMessage object.the object to use to initialize this message object)Creates an initialized |
| public JMSProducer | Returns: A newJMSProducer objectCreates a new |
| public Queue | Returns: a Queue object which encapsulates the specified nameA provider-specific queue name queueName)Creates a |
| public JMSConsumer | Returns: The createdJMSConsumer object.the topic, String Topic to subscribe tothe name used to identify the shared non-durable subscription sharedSubscriptionName)Creates a shared non-durable subscription with the specified name on the specified topic (if one does not already exist) and creates a consumer on that subscription. |
| public JMSConsumer | Returns: The createdJMSConsumer object.the topic, String Topic to subscribe tothe name used to identify the shared non-durable subscription sharedSubscriptionName, String only messages with properties matching the message selector expression are added to the shared
non-durable subscription. A value of null or an empty string indicates that there is no message selector for the
shared non-durable subscription. messageSelector)Creates a shared non-durable subscription with the specified name on the specified topic (if one does not already exist) specifying a message selector, and creates a consumer on that subscription. |
| public JMSConsumer | Returns: The createdJMSConsumer object.the non-temporary topic, String Topic to subscribe tothe name used to identify this subscription name)Creates a shared durable subscription on the specified topic (if one does not already exist), specifying a message selector, and creates a consumer on that durable subscription. |
| public JMSConsumer | Returns: The createdJMSConsumer object.the non-temporary topic, String Topic to subscribe tothe name used to identify this subscription name, String only messages with properties matching the message selector expression are added to the
durable subscription. A value of null or an empty string indicates that there is no message selector for the durable
subscription. messageSelector)Creates a shared durable subscription on the specified topic (if one does not already exist), specifying a message selector, and creates a consumer on that durable subscription. |
| public StreamMessage | |
| public TemporaryQueue | |
| public TemporaryTopic | |
| public TextMessage | |
| public TextMessage | Returns: The createdTextMessage object.the string used to initialize this message text)Creates an initialized |
| public Topic | Returns: a Topic object which encapsulates the specified nameA provider-specific topic name topicName)Creates a |
| public boolean | Returns: whether the underlying connection used by thisJMSContext will be started automatically when a
consumer is created.Returns whether the underlying connection used by this |
| public String | Returns: the unique client identifierGets the client identifier for the JMSContext's connection. |
| public ExceptionListener | Returns: theExceptionListener for the JMSContext's connection, or null if no ExceptionListener is
associated with that connection.Gets the |
| public ConnectionMetaData | Returns: the connection metadataGets the connection metadata for the JMSContext's connection. |
| public int | Returns: the session mode of the JMSContext's sessionReturns the session mode of the JMSContext's session. |
| public boolean | Returns: true if the session is in transacted modeIndicates whether the JMSContext's session is in transacted mode. |
| public void | recover()
Stops message delivery in the JMSContext's session, and restarts message delivery with the oldest unacknowledged message. |
| public void | |
| public void | setAutoStart(boolean
Whether the underlying connection used by this autoStart)JMSContext will be automatically started when
a consumer is created.Specifies whether the underlying connection used by this |
| public void | setClientID(String
the unique client identifier clientID)Sets the client identifier for the JMSContext's connection. |
| public void | setExceptionListener(ExceptionListener
the exception listener listener)Sets an exception listener for the JMSContext's connection. |
| public void | |
| public void | |
| public void | unsubscribe(String
the name used to identify this subscription name)Unsubscribes a durable subscription that has been created by a client. |