Class SQSSession
- java.lang.Object
-
- com.amazon.sqs.javamessaging.SQSSession
-
- All Implemented Interfaces:
Runnable,javax.jms.QueueSession,javax.jms.Session
public class SQSSession extends Object implements javax.jms.Session, javax.jms.QueueSession
A session serves several purposes:- 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
Fields Modifier and Type Field Description static intUNORDERED_ACKNOWLEDGENon standard acknowledge mode.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcheckClosed()Check if session is closed.voidcheckClosing()Check if session is closed or closing.voidclose()Closes the session.voidcommit()This method is not supported.javax.jms.QueueBrowsercreateBrowser(javax.jms.Queue queue)This method is not supported.javax.jms.QueueBrowsercreateBrowser(javax.jms.Queue queue, String messageSelector)This method is not supported.javax.jms.BytesMessagecreateBytesMessage()Creates aBytesMessage.javax.jms.MessageConsumercreateConsumer(javax.jms.Destination destination)Creates aMessageConsumerfor the specified destination.javax.jms.MessageConsumercreateConsumer(javax.jms.Destination destination, String messageSelector)Creates aMessageConsumerfor the specified destination.javax.jms.MessageConsumercreateConsumer(javax.jms.Destination destination, String messageSelector, boolean NoLocal)Creates aMessageConsumerfor the specified destination.javax.jms.TopicSubscribercreateDurableSubscriber(javax.jms.Topic topic, String name)This method is not supported.javax.jms.TopicSubscribercreateDurableSubscriber(javax.jms.Topic topic, String name, String messageSelector, boolean noLocal)This method is not supported.javax.jms.MapMessagecreateMapMessage()This method is not supported.javax.jms.MessagecreateMessage()According to JMS specification, a message can be sent with only headers without any payload, SQS does not support messages with empty payload.javax.jms.ObjectMessagecreateObjectMessage()Creates aObjectMessage.javax.jms.ObjectMessagecreateObjectMessage(Serializable object)Creates an initializedObjectMessage.javax.jms.MessageProducercreateProducer(javax.jms.Destination destination)Creates aMessageProducerfor the specified destination.javax.jms.QueuecreateQueue(String queueName)This does not create SQS Queue.javax.jms.QueuecreateQueue(String queueName, String ownerAccountId)This does not create SQS Queue.javax.jms.QueueReceivercreateReceiver(javax.jms.Queue queue)Creates aQueueReceiverfor the specified queue.javax.jms.QueueReceivercreateReceiver(javax.jms.Queue queue, String messageSelector)Creates aQueueReceiverfor the specified queue.javax.jms.QueueSendercreateSender(javax.jms.Queue queue)Creates aQueueSenderfor the specified queue.javax.jms.StreamMessagecreateStreamMessage()This method is not supported.javax.jms.TemporaryQueuecreateTemporaryQueue()This method is not supported.javax.jms.TemporaryTopiccreateTemporaryTopic()This method is not supported.javax.jms.TextMessagecreateTextMessage()Creates aTextMessage.javax.jms.TextMessagecreateTextMessage(String text)Creates an initializedTextMessage.javax.jms.TopiccreateTopic(String topicName)This method is not supported.intgetAcknowledgeMode()Returns the acknowledge mode of the session.javax.jms.MessageListenergetMessageListener()This method is not supported.booleangetTransacted()SQS does not support transacted.voidrecover()Negative acknowledges all the messages on the session that is delivered but not acknowledged.voidrollback()This method is not supported.voidrun()voidsetMessageListener(javax.jms.MessageListener listener)This method is not supported.voidunsubscribe(String name)This method is not supported.
-
-
-
Field Detail
-
UNORDERED_ACKNOWLEDGE
public static final int UNORDERED_ACKNOWLEDGE
Non 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:
- Constant Field Values
-
-
Method Detail
-
createReceiver
public javax.jms.QueueReceiver createReceiver(javax.jms.Queue queue) throws javax.jms.JMSExceptionCreates aQueueReceiverfor the specified queue.- Specified by:
createReceiverin interfacejavax.jms.QueueSession- Parameters:
queue- a queue receiver- Returns:
- new message consumer
- Throws:
javax.jms.JMSException- If session is closed
-
createReceiver
public javax.jms.QueueReceiver createReceiver(javax.jms.Queue queue, String messageSelector) throws javax.jms.JMSExceptionCreates aQueueReceiverfor the specified queue. Does not support messageSelector. It will drop anything in messageSelector.- Specified by:
createReceiverin interfacejavax.jms.QueueSession- Parameters:
queue- a queue destinationmessageSelector-- Returns:
- new message receiver
- Throws:
javax.jms.JMSException- If session is closed
-
createSender
public javax.jms.QueueSender createSender(javax.jms.Queue queue) throws javax.jms.JMSExceptionCreates aQueueSenderfor the specified queue.- Specified by:
createSenderin interfacejavax.jms.QueueSession- Parameters:
queue- a queue destination- Returns:
- new message sender
- Throws:
javax.jms.JMSException- If session is closed
-
createBytesMessage
public javax.jms.BytesMessage createBytesMessage() throws javax.jms.JMSExceptionCreates aBytesMessage.- Specified by:
createBytesMessagein interfacejavax.jms.Session- Returns:
- new
BytesMessage - Throws:
javax.jms.JMSException- If session is closed or internal error
-
createMessage
public javax.jms.Message createMessage() throws javax.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:
createMessagein interfacejavax.jms.Session- Throws:
javax.jms.JMSException
-
createObjectMessage
public javax.jms.ObjectMessage createObjectMessage() throws javax.jms.JMSExceptionCreates aObjectMessage.- Specified by:
createObjectMessagein interfacejavax.jms.Session- Returns:
- new
ObjectMessage - Throws:
javax.jms.JMSException- If session is closed or internal error
-
createObjectMessage
public javax.jms.ObjectMessage createObjectMessage(Serializable object) throws javax.jms.JMSException
Creates an initializedObjectMessage.- Specified by:
createObjectMessagein interfacejavax.jms.Session- Parameters:
object- The initializedObjectMessage- Returns:
- new
ObjectMessage - Throws:
javax.jms.JMSException- If session is closed or internal error
-
createTextMessage
public javax.jms.TextMessage createTextMessage() throws javax.jms.JMSExceptionCreates aTextMessage.- Specified by:
createTextMessagein interfacejavax.jms.Session- Returns:
- new
TextMessage - Throws:
javax.jms.JMSException- If session is closed or internal error
-
createTextMessage
public javax.jms.TextMessage createTextMessage(String text) throws javax.jms.JMSException
Creates an initializedTextMessage.- Specified by:
createTextMessagein interfacejavax.jms.Session- Parameters:
text- The initializedTextMessage- Returns:
- new
TextMessage - Throws:
javax.jms.JMSException- If session is closed or internal error
-
getAcknowledgeMode
public int getAcknowledgeMode() throws javax.jms.JMSExceptionReturns the acknowledge mode of the session. The acknowledge mode is set at the time that the session is created.- Specified by:
getAcknowledgeModein interfacejavax.jms.Session- Returns:
- acknowledge mode
- Throws:
javax.jms.JMSException
-
close
public void close() throws javax.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:
closein interfacejavax.jms.Session- Throws:
javax.jms.IllegalStateException- If called by a message listener on its ownSession.javax.jms.JMSException- On internal error.
-
recover
public void recover() throws javax.jms.JMSExceptionNegative acknowledges all the messages on the session that is delivered but not acknowledged.- Specified by:
recoverin interfacejavax.jms.Session- Throws:
javax.jms.JMSException- If session is closed or on internal error.
-
run
public void run()
-
createProducer
public javax.jms.MessageProducer createProducer(javax.jms.Destination destination) throws javax.jms.JMSExceptionCreates aMessageProducerfor the specified destination. Only queue destinations are supported at this time.- Specified by:
createProducerin interfacejavax.jms.Session- Parameters:
destination- a queue destination- Returns:
- new message producer
- Throws:
javax.jms.JMSException- If session is closed or queue destination is not used
-
createConsumer
public javax.jms.MessageConsumer createConsumer(javax.jms.Destination destination) throws javax.jms.JMSExceptionCreates aMessageConsumerfor the specified destination. Only queue destinations are supported at this time.- Specified by:
createConsumerin interfacejavax.jms.Session- Parameters:
destination- a queue destination- Returns:
- new message consumer
- Throws:
javax.jms.JMSException- If session is closed or queue destination is not used
-
createConsumer
public javax.jms.MessageConsumer createConsumer(javax.jms.Destination destination, String messageSelector) throws javax.jms.JMSExceptionCreates aMessageConsumerfor the specified destination. Only queue destinations are supported at this time. It will ignore any argument in messageSelector.- Specified by:
createConsumerin interfacejavax.jms.Session- Parameters:
destination- a queue destinationmessageSelector-- Returns:
- new message consumer
- Throws:
javax.jms.JMSException- If session is closed or queue destination is not used
-
createConsumer
public javax.jms.MessageConsumer createConsumer(javax.jms.Destination destination, String messageSelector, boolean NoLocal) throws javax.jms.JMSExceptionCreates aMessageConsumerfor the specified destination. Only queue destinations are supported at this time. It will ignore any argument in messageSelector and NoLocal.- Specified by:
createConsumerin interfacejavax.jms.Session- Parameters:
destination- a queue destinationmessageSelector-NoLocal-- Returns:
- new message consumer
- Throws:
javax.jms.JMSException- If session is closed or queue destination is not used
-
createQueue
public javax.jms.Queue createQueue(String queueName) throws javax.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.- Specified by:
createQueuein interfacejavax.jms.QueueSession- Specified by:
createQueuein interfacejavax.jms.Session- Parameters:
queueName-- Returns:
- a queue destination
- Throws:
javax.jms.JMSException- If session is closed or invalid queue is provided
-
createQueue
public javax.jms.Queue createQueue(String queueName, String ownerAccountId) throws javax.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:
javax.jms.JMSException- If session is closed or invalid queue is provided
-
getTransacted
public boolean getTransacted() throws javax.jms.JMSExceptionSQS does not support transacted. Transacted will always be false.- Specified by:
getTransactedin interfacejavax.jms.Session- Throws:
javax.jms.JMSException
-
commit
public void commit() throws javax.jms.JMSExceptionThis method is not supported. This method is related to transaction which SQS doesn't support- Specified by:
commitin interfacejavax.jms.Session- Throws:
javax.jms.JMSException
-
rollback
public void rollback() throws javax.jms.JMSExceptionThis method is not supported. This method is related to transaction which SQS doesn't support- Specified by:
rollbackin interfacejavax.jms.Session- Throws:
javax.jms.JMSException
-
unsubscribe
public void unsubscribe(String name) throws javax.jms.JMSException
This method is not supported. This method is related to Topic which SQS doesn't support- Specified by:
unsubscribein interfacejavax.jms.Session- Throws:
javax.jms.JMSException
-
createTopic
public javax.jms.Topic createTopic(String topicName) throws javax.jms.JMSException
This method is not supported.- Specified by:
createTopicin interfacejavax.jms.Session- Throws:
javax.jms.JMSException
-
createDurableSubscriber
public javax.jms.TopicSubscriber createDurableSubscriber(javax.jms.Topic topic, String name) throws javax.jms.JMSExceptionThis method is not supported.- Specified by:
createDurableSubscriberin interfacejavax.jms.Session- Throws:
javax.jms.JMSException
-
createDurableSubscriber
public javax.jms.TopicSubscriber createDurableSubscriber(javax.jms.Topic topic, String name, String messageSelector, boolean noLocal) throws javax.jms.JMSExceptionThis method is not supported.- Specified by:
createDurableSubscriberin interfacejavax.jms.Session- Throws:
javax.jms.JMSException
-
createBrowser
public javax.jms.QueueBrowser createBrowser(javax.jms.Queue queue) throws javax.jms.JMSExceptionThis method is not supported.- Specified by:
createBrowserin interfacejavax.jms.QueueSession- Specified by:
createBrowserin interfacejavax.jms.Session- Throws:
javax.jms.JMSException
-
createBrowser
public javax.jms.QueueBrowser createBrowser(javax.jms.Queue queue, String messageSelector) throws javax.jms.JMSExceptionThis method is not supported.- Specified by:
createBrowserin interfacejavax.jms.QueueSession- Specified by:
createBrowserin interfacejavax.jms.Session- Throws:
javax.jms.JMSException
-
createTemporaryQueue
public javax.jms.TemporaryQueue createTemporaryQueue() throws javax.jms.JMSExceptionThis method is not supported.- Specified by:
createTemporaryQueuein interfacejavax.jms.QueueSession- Specified by:
createTemporaryQueuein interfacejavax.jms.Session- Throws:
javax.jms.JMSException
-
createTemporaryTopic
public javax.jms.TemporaryTopic createTemporaryTopic() throws javax.jms.JMSExceptionThis method is not supported.- Specified by:
createTemporaryTopicin interfacejavax.jms.Session- Throws:
javax.jms.JMSException
-
getMessageListener
public javax.jms.MessageListener getMessageListener() throws javax.jms.JMSExceptionThis method is not supported.- Specified by:
getMessageListenerin interfacejavax.jms.Session- Throws:
javax.jms.JMSException
-
setMessageListener
public void setMessageListener(javax.jms.MessageListener listener) throws javax.jms.JMSExceptionThis method is not supported.- Specified by:
setMessageListenerin interfacejavax.jms.Session- Throws:
javax.jms.JMSException
-
createStreamMessage
public javax.jms.StreamMessage createStreamMessage() throws javax.jms.JMSExceptionThis method is not supported.- Specified by:
createStreamMessagein interfacejavax.jms.Session- Throws:
javax.jms.JMSException
-
createMapMessage
public javax.jms.MapMessage createMapMessage() throws javax.jms.JMSExceptionThis method is not supported.- Specified by:
createMapMessagein interfacejavax.jms.Session- Throws:
javax.jms.JMSException
-
checkClosed
public void checkClosed() throws javax.jms.IllegalStateExceptionCheck if session is closed.- Throws:
javax.jms.IllegalStateException
-
checkClosing
public void checkClosing() throws javax.jms.IllegalStateExceptionCheck if session is closed or closing.- Throws:
javax.jms.IllegalStateException
-
-