MQSession
public class MQSession
extends Object
implements SessionJMSAcknowledgePointJMSDestinationFactory
java.lang.Object
|
+----com.ibm.mq.jms.MQSession
A JMS session is a single-threaded context for producing and consuming
messages.
Methods
close
public void close() throws JMSException;
Closes the session.
- Exceptions
-
- JMSException - with one of the following reasons:
- MQJMS_EXCEPTION_BAD_STATE_TRANSITION
- MQJMS_E_CLOSE_FAILED
- MQJMS_EXCEPTION_QMDISC_FAILED
commit
public void commit() throws JMSException;
Commits all messages done in this transaction and releases any locks currently
held. This always throws a JMSException when you have a direct connection
to a broker.
- Exceptions
-
- JMSException - with one of the following reasons:
- MQJMS_E_SESSION_CLOSED
- MQJMS_E_SESSION_NOT_TRANSACTED
- MQJMS_EXCEPTION_MQ_NULL_QMGR
- MQJMS_EXCEPTION_TRANSACTION_ROLLED_BACK
- MQJMS_EXCEPTION_MQ_QM_COMMIT_FAILED
createBrowser
public QueueBrowser createBrowser(Queue queue) throws JMSException;
Creates a QueueBrowser object to peek at the messages on the specified
queue.
- Parameters
-
- queue - the queue to access.
- Returns
-
- QueueBrowser - a newly created QueueBrowser.
- Exceptions
-
- JMSException - with one of the following reasons:
- MQJMS_E_SESSION_CLOSED
- MQJMS_EXCEPTION_INVALID_DESTINATION
- MQJMS_E_NON_LOCAL_RXQ
createBrowser
public QueueBrowser createBrowser(Queue queue, String messageSelector)
throws JMSException;
Creates a QueueBrowser object to peek at the messages on the specified
queue using a message selector.
- Parameters
-
- queue - the queue to access
- messageSelector - only 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.
- Returns
-
- QueueBrowser - a newly create QueueBrowser
- Exceptions
-
- JMSException - with one of the following reasons:
- MQJMS_E_SESSION_CLOSED
- MQJMS_EXCEPTION_INVALID_DESTINATION
- MQJMS_E_NON_LOCAL_RXQ
createBytesMessage
public BytesMessage createBytesMessage() throws JMSException;
Creates a BytesMessage object.
- Returns
-
- Exceptions
-
- JMSException - if JMS fails due to some internal JMS error.
- JMSException - with reason MQJMS_E_SESSION_CLOSED
.
createConsumer
public MessageConsumer createConsumer(Destination destination)
throws JMSException;
Creates a MessageConsumer for the specified Destination. Since Queue and
Topic both inherit from Destination, they can be used in the destination parameter
to create a MessageConsumer.
- Parameters
-
- destination - the Destination to access.
- Returns
-
- Exceptions
-
- JMSException - if the command fails due to some internal JMS error.
createConsumer
public MessageConsumer createConsumer(Destination destination,
String messageSelector)
throws JMSException;
Creates a MessageConsumer for the specified destination, using a message
selector.
- Parameters
-
- destination - the Destination to access.
- messageSelector - the message selector
- Returns
-
- Exceptions
-
- JMSException - if the command fails due to some internal JMS error.
createConsumer
public MessageConsumer createConsumer(Destination destination,
String messageSelector,
boolean noLocal)
throws JMSException;
Creates MessageConsumer for the specified Destination, using a message
selector.
- Parameters
-
- destination - the Destination to access.
- messageSelector - the message selector
- noLocal - when the destination is a topic, true inhibits
the delivery of messages published by its own connection. The behavior for
NoLocal is ignored if the destination is a queue.
- Returns
-
- Exceptions
-
- JMSException - if the command fails due to some internal JMS error.
createDurableSubscriber
public TopicSubscriber createDurableSubscriber(Topic topic, String name)
throws JMSException;
Creates a durable Subscriber to the specified topic.
- Parameters
-
- topic - the topic to subscribe to
- name - the name used to identify this subscription.
- Returns
-
- Exceptions
-
- IllegalStateException - if the session has been closed.
- InvalidDestinationException - if the topic specified is not valid.
- JMSException - if the Session fails to create a subscriber due to an internal
error.
createDurableSubscriber
public TopicSubscriber createDurableSubscriber(Topic topic, String name,
String selector,
boolean noLocal)
throws JMSException;
Creates a durable Subscriber to the specified topic.
- Parameters
-
- topic - the topic to subscribe to
- name - the name used to identify this subscription.
- selector - only messages with properties matching the message selector
expression are delivered. This value may be null.
- noLocal - trueinhibits the delivery of messages
published by its own connection.
- Exceptions
-
- IllegalStateException - if the session has been closed.
- InvalidDestinationException - if the topic specified is not valid.
- JMSException - if the Session fails to create a subscriber due to an internal
error.
createMapMessage
public MapMessage createMapMessage() throws JMSException;
Creates a MapMessage. A MapMessage is used to send a self-defining set
of name-value pairs where names are Strings and values are Java primitive
types.
- Returns
-
- Exceptions
-
- JMSException - with reason MQJMS_E_SESSION_CLOSED
createMessage
public Message createMessage() throws JMSException;
Creates a Message. The Message interface is the root interface of all JMS
messages. It holds all the standard message header information. It can be
sent when a message containing only header information is sufficient.
- Returns
-
- Exceptions
-
- JMSException - with reason MQJMS_E_SESSION_CLOSED
.
createObjectMessage
public ObjectMessage createObjectMessage() throws JMSException;
Creates an ObjectMessage. An ObjectMessage is used to send a message that
contains a serializable Java object.
- Returns
-
- Exceptions
-
- IllegalStateException - with reason MQJMS_E_SESSION_CLOSED
.
createObjectMessage
public ObjectMessage createObjectMessage(Serializable object)
throws JMSException;
Creates an initialized ObjectMessage. An ObjectMessage is used to send
a message that containing a serializable Java object.
- Parameters
-
- object - the object to use to initialize this message.
- Returns
-
- Exceptions
-
- IllegalStateException - with reason MQJMS_E_SESSION_CLOSED
.
createProducer
public MessageProducer createProducer(Destination destination)
throws JMSException;
Creates a MessageProducer to send messages to the specified destination.
- Parameters
-
- destination - the Destination to send to, or null if this is a producer
which does not have a specified destination.
- Exceptions
-
- JMSException - with reason MQJMS_EXCEPTION_MQ_NULL_QMGR
- JMSException - with reason MQJMS_EXCEPTION_MQ_Q_OPEN_FAILED
- InvalidDestinationException - If the topic specified is not valid.
- JMSException - if the Session fails to create a producer because of an
internal error.
createQueue
public Queue createQueue(String queueName) throws JMSException;
Creates a Queue object given a queue name.
- Parameters
-
- queueName - the name of this Queue
- Returns
-
- a Queue with the given name
- Exceptions
-
- JMSException - with one of the following reasons:
- MQJMS_E_SESSION_CLOSED.
- MQJMS_EXCEPTION_INVALID_DESTINATION
createStreamMessage
public StreamMessage createStreamMessage() throws JMSException;
Creates a StreamMessage object. A StreamMessage is used to send a self-defining
stream of Java primitives.
- Returns
-
- Exceptions
-
- JMSException - IllegalStateException with reason
MQJMS_E_SESSION_CLOSED.
createTemporaryQueue
public TemporaryQueue createTemporaryQueue() throws JMSException;
Creates a JMS temporary queue. The temporary queue remains until the connection
ends or the queue is explicitly deleted, whichever is the sooner.
- Returns
-
- Exceptions
-
- JMSException - IllegalStateException with
one of the following reasons:
- MQJMS_E_SESSION_CLOSED
- MQJMS_E_NULL_CONNECTION
- MQJMS_E_TMPQ_FAILED
createTemporaryTopic
public TemporaryTopic createTemporaryTopic() throws JMSException;
Creates a temporary topic. The temporary topic remains until the connection
ends or the topic is explicitly deleted, whichever is the sooner.
- Returns
-
- Exceptions
-
- JMSException - if the Session fails to create a temporary topic due to
an internal error.
- IllegalStateException - if the Session object has been closed.
createTextMessage
public TextMessage createTextMessage() throws JMSException;
Creates a TextMessage. A TextMessage is used to send a message containing
a StringBuffer.
- Returns
-
- Exceptions
-
- JMSException - IllegalStateException with reason
MQJMS_E_SESSION_CLOSED.
createTextMessage
public TextMessage createTextMessage(String string) throws JMSException;
Creates an initialized TextMessage.
- Parameters
-
- string - the string used to initialize this message.
- Returns
-
- Exceptions
-
- JMSException - IllegalStateException with key
MQJMS_E_SESSION_CLOSED.
createTopic
public Topic createTopic(String topicName) throws JMSException;
Creates a Topic given a Topic name.
- Parameters
-
- topicName - the name of this topic
- Returns
-
- a Topic with the given name.
- Exceptions
-
- JMSException - if a Session fails to create a Topic due to an internal
error.
- IllegalStateException - if the Session object has been closed.
getAcknowledgeMode
public int getAcknowledgeMode() throws JMSException;
Gets the acknowledgement mode of the session. The acknowledgement mode
is set at the time that the session is created. If the session is transacted,
the acknowledgement mode is ignored.
- Returns
-
- the current acknowledgement mode for the session if the session is not
transacted. Otherwise returns SESSION_TRANSACTED.
getMessageListener
public MessageListener getMessageListener() throws JMSException;
Gets the session's distinguished message listener.
- Returns
-
- Exceptions
-
- JMSException - with reason MQJMS_E_SESSION_CLOSED
.
getTransacted
public boolean getTransacted() throws JMSException;
Indicates whether the session is in transacted mode. Always returns false
when you have a direct connection to a broker.
- Returns
-
- true if in transacted mode
- Exceptions
-
- JMSException - with one of the following reasons:
- MQJMS_E_SESSION_CLOSED
- MQJMS_E_INTERNAL_ERROR
recover
public void recover() throws JMSException;
Stops message delivery in this session and restarts message delivery with
the oldest unacknowledged message. This always throws a JMSException when
you have a direct connection to a broker.
- Exceptions
-
- JMSException - with one of the following reasons:
- MQJMS_E_SESSION_CLOSED
- MQJMS_E_SESSION_IS_TRANSACTED
- MQJMS_EXCEPTION_MQ_NULL_QMGR
- MQJMS_E_RECOVER_BO_FAILED
rollback
public void rollback() throws JMSException;
Rolls back any messages processed in this transaction and releases any
locks currently held. This always throws a JMSException when you have a direct
connection to a broker.
- Exceptions
-
- JMSException - with one of the following reasons:
- MQJMS_E_SESSION_CLOSED
- MQJMS_E_SESSION_NOT_TRANSACTED
- MQJMS_EXCEPTION_MQ_NULL_QMGR
- MQJMS_E_ROLLBACK_FAILED
setMessageListener
public void setMessageListener(MessageListener listener)
throws JMSException;
Sets the session's distinguished message listener.
- Parameters
-
- Exceptions
-
- JMSException - with one of the following reasons:
- MQJMS_E_SESSION_CLOSED
- MQJMS_E_SESSION_ASYNC
unsubscribe
public void unsubscribe(String name) throws JMSException;
Unsubscribes a durable subscription that has been created by a client.
For a direct connection to WebSphere MQ Event Broker, WebSphere Business
Integration Event Broker, or WebSphere Business Integration Message Broker,
this method throws a JMSException.
- Exceptions
-
- JMSException - if the Session fails to unsubscribe to the durable subscription
due to an internal error.