Class SQSSession
- All Implemented Interfaces:
jakarta.jms.QueueSession
,jakarta.jms.Session
,AutoCloseable
,Runnable
- It is a factory for its message producers and consumers.
- It provides a way to create Queue objects for those clients that need to dynamically manipulate provider-specific destination names.
- It retains messages it consumes until they have been acknowledged.
- It serializes execution of message listeners registered with its message consumers.
Not safe for concurrent use.
This session object does not support:
- (Temporary)Topic
- Temporary Queue
- Browser
- MapMessage
- StreamMessage
- MessageSelector
- Transactions
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Non standard acknowledge mode.Fields inherited from interface jakarta.jms.Session
AUTO_ACKNOWLEDGE, CLIENT_ACKNOWLEDGE, DUPS_OK_ACKNOWLEDGE, SESSION_TRANSACTED
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Check if session is closed.void
Check if session is closed or closing.void
close()
Closes the session.void
commit()
This method is not supported.jakarta.jms.QueueBrowser
createBrowser
(jakarta.jms.Queue queue) This method is not supported.jakarta.jms.QueueBrowser
createBrowser
(jakarta.jms.Queue queue, String messageSelector) This method is not supported.jakarta.jms.BytesMessage
Creates aBytesMessage
.jakarta.jms.MessageConsumer
createConsumer
(jakarta.jms.Destination destination) Creates aMessageConsumer
for the specified destination.jakarta.jms.MessageConsumer
createConsumer
(jakarta.jms.Destination destination, String messageSelector) Creates aMessageConsumer
for the specified destination.jakarta.jms.MessageConsumer
createConsumer
(jakarta.jms.Destination destination, String messageSelector, boolean NoLocal) Creates aMessageConsumer
for the specified destination.jakarta.jms.MessageConsumer
createDurableConsumer
(jakarta.jms.Topic topic, String name) jakarta.jms.MessageConsumer
createDurableConsumer
(jakarta.jms.Topic topic, String name, String messageSelector, boolean noLocal) jakarta.jms.TopicSubscriber
createDurableSubscriber
(jakarta.jms.Topic topic, String name) This method is not supported.jakarta.jms.TopicSubscriber
createDurableSubscriber
(jakarta.jms.Topic topic, String name, String messageSelector, boolean noLocal) This method is not supported.jakarta.jms.MapMessage
This method is not supported.jakarta.jms.Message
According to JMS specification, a message can be sent with only headers without any payload, SQS does not support messages with empty payload.jakarta.jms.ObjectMessage
Creates aObjectMessage
.jakarta.jms.ObjectMessage
createObjectMessage
(Serializable object) Creates an initializedObjectMessage
.jakarta.jms.MessageProducer
createProducer
(jakarta.jms.Destination destination) Creates aMessageProducer
for the specified destination.jakarta.jms.Queue
createQueue
(String queueName) This does not create SQS Queue.jakarta.jms.Queue
createQueue
(String queueName, String ownerAccountId) This does not create SQS Queue.jakarta.jms.QueueReceiver
createReceiver
(jakarta.jms.Queue queue) Creates aQueueReceiver
for the specified queue.jakarta.jms.QueueReceiver
createReceiver
(jakarta.jms.Queue queue, String messageSelector) Creates aQueueReceiver
for the specified queue.jakarta.jms.QueueSender
createSender
(jakarta.jms.Queue queue) Creates aQueueSender
for the specified queue.jakarta.jms.MessageConsumer
createSharedConsumer
(jakarta.jms.Topic topic, String sharedSubscriptionName) jakarta.jms.MessageConsumer
createSharedConsumer
(jakarta.jms.Topic topic, String sharedSubscriptionName, String messageSelector) jakarta.jms.MessageConsumer
createSharedDurableConsumer
(jakarta.jms.Topic topic, String name) jakarta.jms.MessageConsumer
createSharedDurableConsumer
(jakarta.jms.Topic topic, String name, String messageSelector) jakarta.jms.StreamMessage
This method is not supported.jakarta.jms.TemporaryQueue
This method is not supported.jakarta.jms.TemporaryTopic
This method is not supported.jakarta.jms.TextMessage
Creates aTextMessage
.jakarta.jms.TextMessage
createTextMessage
(String text) Creates an initializedTextMessage
.jakarta.jms.Topic
createTopic
(String topicName) This method is not supported.int
Returns the acknowledge mode of the session.jakarta.jms.MessageListener
This method is not supported.boolean
SQS does not support transacted.void
recover()
Negative acknowledges all the messages on the session that is delivered but not acknowledged.void
rollback()
This method is not supported.void
run()
void
setMessageListener
(jakarta.jms.MessageListener listener) This method is not supported.void
unsubscribe
(String name) This method is not supported.
-
Field Details
-
UNORDERED_ACKNOWLEDGE
public static final int UNORDERED_ACKNOWLEDGENon standard acknowledge mode. This is a variation of CLIENT_ACKNOWLEDGE where Clients need to remember to call acknowledge on message. Difference is that calling acknowledge on a message only acknowledge the message being called.- See Also:
-
-
Method Details
-
createReceiver
public jakarta.jms.QueueReceiver createReceiver(jakarta.jms.Queue queue) throws jakarta.jms.JMSException Creates aQueueReceiver
for the specified queue.- Specified by:
createReceiver
in interfacejakarta.jms.QueueSession
- Parameters:
queue
- a queue receiver- Returns:
- new message consumer
- Throws:
jakarta.jms.JMSException
- If session is closed
-
createReceiver
public jakarta.jms.QueueReceiver createReceiver(jakarta.jms.Queue queue, String messageSelector) throws jakarta.jms.JMSException Creates aQueueReceiver
for the specified queue. Does not support messageSelector. It will drop anything in messageSelector.- Specified by:
createReceiver
in interfacejakarta.jms.QueueSession
- Parameters:
queue
- a queue destinationmessageSelector
-- Returns:
- new message receiver
- Throws:
jakarta.jms.JMSException
- If session is closed
-
createSender
public jakarta.jms.QueueSender createSender(jakarta.jms.Queue queue) throws jakarta.jms.JMSException Creates aQueueSender
for the specified queue.- Specified by:
createSender
in interfacejakarta.jms.QueueSession
- Parameters:
queue
- a queue destination- Returns:
- new message sender
- Throws:
jakarta.jms.JMSException
- If session is closed
-
createBytesMessage
public jakarta.jms.BytesMessage createBytesMessage() throws jakarta.jms.JMSExceptionCreates aBytesMessage
.- Specified by:
createBytesMessage
in interfacejakarta.jms.Session
- Returns:
- new
BytesMessage
- Throws:
jakarta.jms.JMSException
- If session is closed or internal error
-
createMessage
public jakarta.jms.Message createMessage() throws jakarta.jms.JMSExceptionAccording to JMS specification, a message can be sent with only headers without any payload, SQS does not support messages with empty payload. so this method is not supported- Specified by:
createMessage
in interfacejakarta.jms.Session
- Throws:
jakarta.jms.JMSException
-
createObjectMessage
public jakarta.jms.ObjectMessage createObjectMessage() throws jakarta.jms.JMSExceptionCreates aObjectMessage
.- Specified by:
createObjectMessage
in interfacejakarta.jms.Session
- Returns:
- new
ObjectMessage
- Throws:
jakarta.jms.JMSException
- If session is closed or internal error
-
createObjectMessage
public jakarta.jms.ObjectMessage createObjectMessage(Serializable object) throws jakarta.jms.JMSException Creates an initializedObjectMessage
.- Specified by:
createObjectMessage
in interfacejakarta.jms.Session
- Parameters:
object
- The initializedObjectMessage
- Returns:
- new
ObjectMessage
- Throws:
jakarta.jms.JMSException
- If session is closed or internal error
-
createTextMessage
public jakarta.jms.TextMessage createTextMessage() throws jakarta.jms.JMSExceptionCreates aTextMessage
.- Specified by:
createTextMessage
in interfacejakarta.jms.Session
- Returns:
- new
TextMessage
- Throws:
jakarta.jms.JMSException
- If session is closed or internal error
-
createTextMessage
Creates an initializedTextMessage
.- Specified by:
createTextMessage
in interfacejakarta.jms.Session
- Parameters:
text
- The initializedTextMessage
- Returns:
- new
TextMessage
- Throws:
jakarta.jms.JMSException
- If session is closed or internal error
-
getAcknowledgeMode
public int getAcknowledgeMode() throws jakarta.jms.JMSExceptionReturns the acknowledge mode of the session. The acknowledge mode is set at the time that the session is created.- Specified by:
getAcknowledgeMode
in interfacejakarta.jms.Session
- Returns:
- acknowledge mode
- Throws:
jakarta.jms.JMSException
-
close
public void close() throws jakarta.jms.JMSExceptionCloses the session.This will not return until all the message consumers and producers close internally, which blocks until receives and/or message listeners in progress have completed. A blocked message consumer receive call returns null when this session is closed.
Since consumer prefetch threads use SQS long-poll feature with 20 seconds timeout, closing each consumer prefetch thread can take up to 20 seconds, which in-turn will impact the time on session close.
This method is safe for concurrent use.
A message listener must not attempt to close its own session; otherwise throws a IllegalStateException.
Invoking any other session method on a closed session must throw a
IllegalStateException
.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfacejakarta.jms.Session
- Throws:
jakarta.jms.IllegalStateException
- If called by a message listener on its ownSession
.jakarta.jms.JMSException
- On internal error.
-
recover
public void recover() throws jakarta.jms.JMSExceptionNegative acknowledges all the messages on the session that is delivered but not acknowledged.- Specified by:
recover
in interfacejakarta.jms.Session
- Throws:
jakarta.jms.JMSException
- If session is closed or on internal error.
-
run
public void run() -
createProducer
public jakarta.jms.MessageProducer createProducer(jakarta.jms.Destination destination) throws jakarta.jms.JMSException Creates aMessageProducer
for the specified destination. Only queue destinations are supported at this time.- Specified by:
createProducer
in interfacejakarta.jms.Session
- Parameters:
destination
- a queue destination- Returns:
- new message producer
- Throws:
jakarta.jms.JMSException
- If session is closed or queue destination is not used
-
createConsumer
public jakarta.jms.MessageConsumer createConsumer(jakarta.jms.Destination destination) throws jakarta.jms.JMSException Creates aMessageConsumer
for the specified destination. Only queue destinations are supported at this time.- Specified by:
createConsumer
in interfacejakarta.jms.Session
- Parameters:
destination
- a queue destination- Returns:
- new message consumer
- Throws:
jakarta.jms.JMSException
- If session is closed or queue destination is not used
-
createConsumer
public jakarta.jms.MessageConsumer createConsumer(jakarta.jms.Destination destination, String messageSelector) throws jakarta.jms.JMSException Creates aMessageConsumer
for the specified destination. Only queue destinations are supported at this time. It will ignore any argument in messageSelector.- Specified by:
createConsumer
in interfacejakarta.jms.Session
- Parameters:
destination
- a queue destinationmessageSelector
-- Returns:
- new message consumer
- Throws:
jakarta.jms.JMSException
- If session is closed or queue destination is not used
-
createConsumer
public jakarta.jms.MessageConsumer createConsumer(jakarta.jms.Destination destination, String messageSelector, boolean NoLocal) throws jakarta.jms.JMSException Creates aMessageConsumer
for the specified destination. Only queue destinations are supported at this time. It will ignore any argument in messageSelector and NoLocal.- Specified by:
createConsumer
in interfacejakarta.jms.Session
- Parameters:
destination
- a queue destinationmessageSelector
-NoLocal
-- Returns:
- new message consumer
- Throws:
jakarta.jms.JMSException
- If session is closed or queue destination is not used
-
createQueue
This does not create SQS Queue. This method is only to create JMS Queue Object. Make sure the queue exists corresponding to the queueName.- Specified by:
createQueue
in interfacejakarta.jms.QueueSession
- Specified by:
createQueue
in interfacejakarta.jms.Session
- Parameters:
queueName
-- Returns:
- a queue destination
- Throws:
jakarta.jms.JMSException
- If session is closed or invalid queue is provided
-
createQueue
public jakarta.jms.Queue createQueue(String queueName, String ownerAccountId) throws jakarta.jms.JMSException This does not create SQS Queue. This method is only to create JMS Queue Object. Make sure the queue exists corresponding to the queueName and ownerAccountId.- Parameters:
queueName
-ownerAccountId
- the account id, which originally created the queue on SQS- Returns:
- a queue destination
- Throws:
jakarta.jms.JMSException
- If session is closed or invalid queue is provided
-
getTransacted
public boolean getTransacted() throws jakarta.jms.JMSExceptionSQS does not support transacted. Transacted will always be false.- Specified by:
getTransacted
in interfacejakarta.jms.Session
- Throws:
jakarta.jms.JMSException
-
commit
public void commit() throws jakarta.jms.JMSExceptionThis method is not supported. This method is related to transaction which SQS doesn't support- Specified by:
commit
in interfacejakarta.jms.Session
- Throws:
jakarta.jms.JMSException
-
rollback
public void rollback() throws jakarta.jms.JMSExceptionThis method is not supported. This method is related to transaction which SQS doesn't support- Specified by:
rollback
in interfacejakarta.jms.Session
- Throws:
jakarta.jms.JMSException
-
unsubscribe
This method is not supported. This method is related to Topic which SQS doesn't support- Specified by:
unsubscribe
in interfacejakarta.jms.Session
- Throws:
jakarta.jms.JMSException
-
createTopic
This method is not supported.- Specified by:
createTopic
in interfacejakarta.jms.Session
- Throws:
jakarta.jms.JMSException
-
createDurableSubscriber
public jakarta.jms.TopicSubscriber createDurableSubscriber(jakarta.jms.Topic topic, String name) throws jakarta.jms.JMSException This method is not supported.- Specified by:
createDurableSubscriber
in interfacejakarta.jms.Session
- Throws:
jakarta.jms.JMSException
-
createDurableSubscriber
public jakarta.jms.TopicSubscriber createDurableSubscriber(jakarta.jms.Topic topic, String name, String messageSelector, boolean noLocal) throws jakarta.jms.JMSException This method is not supported.- Specified by:
createDurableSubscriber
in interfacejakarta.jms.Session
- Throws:
jakarta.jms.JMSException
-
createDurableConsumer
public jakarta.jms.MessageConsumer createDurableConsumer(jakarta.jms.Topic topic, String name) throws jakarta.jms.JMSException - Specified by:
createDurableConsumer
in interfacejakarta.jms.Session
- Throws:
jakarta.jms.JMSException
-
createDurableConsumer
public jakarta.jms.MessageConsumer createDurableConsumer(jakarta.jms.Topic topic, String name, String messageSelector, boolean noLocal) throws jakarta.jms.JMSException - Specified by:
createDurableConsumer
in interfacejakarta.jms.Session
- Throws:
jakarta.jms.JMSException
-
createBrowser
public jakarta.jms.QueueBrowser createBrowser(jakarta.jms.Queue queue) throws jakarta.jms.JMSException This method is not supported.- Specified by:
createBrowser
in interfacejakarta.jms.QueueSession
- Specified by:
createBrowser
in interfacejakarta.jms.Session
- Throws:
jakarta.jms.JMSException
-
createBrowser
public jakarta.jms.QueueBrowser createBrowser(jakarta.jms.Queue queue, String messageSelector) throws jakarta.jms.JMSException This method is not supported.- Specified by:
createBrowser
in interfacejakarta.jms.QueueSession
- Specified by:
createBrowser
in interfacejakarta.jms.Session
- Throws:
jakarta.jms.JMSException
-
createTemporaryQueue
public jakarta.jms.TemporaryQueue createTemporaryQueue() throws jakarta.jms.JMSExceptionThis method is not supported.- Specified by:
createTemporaryQueue
in interfacejakarta.jms.QueueSession
- Specified by:
createTemporaryQueue
in interfacejakarta.jms.Session
- Throws:
jakarta.jms.JMSException
-
createTemporaryTopic
public jakarta.jms.TemporaryTopic createTemporaryTopic() throws jakarta.jms.JMSExceptionThis method is not supported.- Specified by:
createTemporaryTopic
in interfacejakarta.jms.Session
- Throws:
jakarta.jms.JMSException
-
getMessageListener
public jakarta.jms.MessageListener getMessageListener() throws jakarta.jms.JMSExceptionThis method is not supported.- Specified by:
getMessageListener
in interfacejakarta.jms.Session
- Throws:
jakarta.jms.JMSException
-
setMessageListener
public void setMessageListener(jakarta.jms.MessageListener listener) throws jakarta.jms.JMSException This method is not supported.- Specified by:
setMessageListener
in interfacejakarta.jms.Session
- Throws:
jakarta.jms.JMSException
-
createStreamMessage
public jakarta.jms.StreamMessage createStreamMessage() throws jakarta.jms.JMSExceptionThis method is not supported.- Specified by:
createStreamMessage
in interfacejakarta.jms.Session
- Throws:
jakarta.jms.JMSException
-
createMapMessage
public jakarta.jms.MapMessage createMapMessage() throws jakarta.jms.JMSExceptionThis method is not supported.- Specified by:
createMapMessage
in interfacejakarta.jms.Session
- Throws:
jakarta.jms.JMSException
-
checkClosed
public void checkClosed() throws jakarta.jms.IllegalStateExceptionCheck if session is closed.- Throws:
jakarta.jms.IllegalStateException
-
checkClosing
public void checkClosing() throws jakarta.jms.IllegalStateExceptionCheck if session is closed or closing.- Throws:
jakarta.jms.IllegalStateException
-