Session object is a single-threaded context for producing and consuming messages. Although it may allocate
provider resources outside the Java virtual machine (JVM), it is considered a lightweight Jakarta Messaging object.
A session serves several purposes:
TemporaryTopics and TemporaryQueues.
Queue or Topic objects for those clients that need to dynamically
manipulate provider-specific destination names.
QueueBrowsers.
A session can create and service multiple message producers and consumers.
One typical use is to have a thread block on a synchronous MessageConsumer until a message arrives. The
thread may then use one or more of the Session's MessageProducers.
If a client desires to have one thread produce messages while others consume them, the client should use a separate session for its producing thread.
Once a connection has been started, any session with one or more registered message listeners is dedicated to the
thread of control that delivers messages to it. It is erroneous for client code to use this session or any of its
constituent objects from another thread of control. The only exception to this rule is the use of the session or
message consumer close method.
It should be easy for most clients to partition their work naturally into sessions. This model allows clients to start simply and incrementally add message processing complexity as their need for concurrency grows.
The close method is the only session method that can be called while some other session method is being
executed in another thread.
A session may be specified as transacted. Each transacted session supports a single series of transactions. Each transaction groups a set of message sends and a set of message receives into an atomic unit of work. In effect, transactions organize a session's input message stream and output message stream into series of atomic units. When a transaction commits, its atomic unit of input is acknowledged and its associated atomic unit of output is sent. If a transaction rollback is done, the transaction's sent messages are destroyed and the session's input is automatically recovered.
The content of a transaction's input and output units is simply those messages that have been produced and consumed within the session's current transaction.
A transaction is completed using either its session's commit method or its session's rollback method.
The completion of a session's current transaction automatically begins the next. The result is that a transacted
session always has a current transaction within which its work is done.
The Java Transaction Service (JTS) or some other transaction monitor may be used to combine a session's transaction
with transactions on other resources (databases, other Jakarta Messaging sessions, etc.). Since Java distributed transactions are
controlled via the Java Transaction API (JTA), use of the session's commit and rollback methods in
this context is prohibited.
The Jakarta Messaging API does not require support for JTA; however, it does define how a provider supplies this support.
Although it is also possible for a Jakarta Messaging client to handle distributed transactions directly, it is unlikely that many Jakarta Messaging clients will do this. Support for JTA in the Jakarta Messaging API is targeted at systems vendors who will be integrating the Jakarta Messaging API into their application server products.
jakarta.jms.QueueSession, jakarta.jms.TopicSession, jakarta.jms.XASession
| Modifier and Type | Field and Description |
|---|---|
| public static final int | AUTO_ACKNOWLEDGE
With this acknowledgment mode, the 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 acknowledgment mode, the client acknowledges a consumed message by calling the message's
|
| public static final int | DUPS_OK_ACKNOWLEDGE
This acknowledgment mode instructs the session to lazily acknowledge the delivery of messages. |
| public static final int | SESSION_TRANSACTED
This value may be passed as the argument to the method |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public void | |
| public QueueBrowser | Returns: AQueueBrowser object to peek at the messages on the specified queue.the queue)queue to accessCreates a |
| public QueueBrowser | Returns: AQueueBrowser object to peek at the messages on the specified queue.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 MessageConsumer | Returns: AMessageConsumer for the specified destination.the destination)Destination to access.Creates a |
| public MessageConsumer | Returns: AMessageConsumer for the specified destination.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 message consumer. messageSelector)Creates a |
| public MessageConsumer | Returns: AMessageConsumer for the specified destination.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 message consumer. messageSelector, boolean - if true, and the destination is a topic, then the noLocal)MessageConsumer will not receive messages
published to the topic by its own connection.Creates a |
| public MessageConsumer | Returns: An unshared durable subscription on the specified topic.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 MessageConsumer | Returns: An unshared durable subscription on the specified topic.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 TopicSubscriber | Returns: An unshared durable subscription on the specified topic.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 TopicSubscriber | Returns: An unshared durable subscription on the specified topic.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: AObjectMessage object.the object to use to initialize this message object)Creates an initialized |
| public MessageProducer | Returns: AMessageProducer to send messages.the destination)Destination to send to, or null if this is a producer which does not have a specified
destination.Creates a |
| public Queue | Returns: a Queue object which encapsulates the specified nameA provider-specific queue name queueName)Creates a |
| public MessageConsumer | Returns: A shared non-durable subscription with the specified name on the specified topic.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 MessageConsumer | Returns: A shared non-durable subscription with the specified name on the specified topic.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 MessageConsumer | Returns: A shared durable subscription on the specified topic.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 the |
| public MessageConsumer | Returns: A shared durable subscription on the specified topic.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: ATextMessage 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 int | Returns: If the session is not transacted, returns the current acknowledgement mode for the session. If the session is transacted, returns SESSION_TRANSACTED.Returns the acknowledgement mode of the session. |
| public MessageListener | Returns: the distinguished message listener associated with this sessionReturns the session's distinguished message listener (optional). |
| public boolean | Returns: true if the session is in transacted modeIndicates whether the session is in transacted mode. |
| public void | recover()
Stops message delivery in this session, and restarts message delivery with the oldest unacknowledged message. |
| public void | |
| public void | run()
Redeclares java. Optional operation, intended to be used only by Application Servers, not by ordinary Jakarta Messaging clients. |
| public void | setMessageListener(MessageListener
the message listener to associate with this session listener)Sets the session's distinguished message listener (optional). |
| public void | unsubscribe(String
the name used to identify this subscription name)Unsubscribes a durable subscription that has been created by a client. |