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 int
UNORDERED_ACKNOWLEDGE
Non standard acknowledge mode.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
checkClosed()
Check if session is closed.void
checkClosing()
Check if session is closed or closing.void
close()
Closes the session.void
commit()
This method is not supported.javax.jms.QueueBrowser
createBrowser(javax.jms.Queue queue)
This method is not supported.javax.jms.QueueBrowser
createBrowser(javax.jms.Queue queue, String messageSelector)
This method is not supported.javax.jms.BytesMessage
createBytesMessage()
Creates aBytesMessage
.javax.jms.MessageConsumer
createConsumer(javax.jms.Destination destination)
Creates aMessageConsumer
for the specified destination.javax.jms.MessageConsumer
createConsumer(javax.jms.Destination destination, String messageSelector)
Creates aMessageConsumer
for the specified destination.javax.jms.MessageConsumer
createConsumer(javax.jms.Destination destination, String messageSelector, boolean NoLocal)
Creates aMessageConsumer
for the specified destination.javax.jms.TopicSubscriber
createDurableSubscriber(javax.jms.Topic topic, String name)
This method is not supported.javax.jms.TopicSubscriber
createDurableSubscriber(javax.jms.Topic topic, String name, String messageSelector, boolean noLocal)
This method is not supported.javax.jms.MapMessage
createMapMessage()
This method is not supported.javax.jms.Message
createMessage()
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.ObjectMessage
createObjectMessage()
Creates aObjectMessage
.javax.jms.ObjectMessage
createObjectMessage(Serializable object)
Creates an initializedObjectMessage
.javax.jms.MessageProducer
createProducer(javax.jms.Destination destination)
Creates aMessageProducer
for the specified destination.javax.jms.Queue
createQueue(String queueName)
This does not create SQS Queue.javax.jms.Queue
createQueue(String queueName, String ownerAccountId)
This does not create SQS Queue.javax.jms.QueueReceiver
createReceiver(javax.jms.Queue queue)
Creates aQueueReceiver
for the specified queue.javax.jms.QueueReceiver
createReceiver(javax.jms.Queue queue, String messageSelector)
Creates aQueueReceiver
for the specified queue.javax.jms.QueueSender
createSender(javax.jms.Queue queue)
Creates aQueueSender
for the specified queue.javax.jms.StreamMessage
createStreamMessage()
This method is not supported.javax.jms.TemporaryQueue
createTemporaryQueue()
This method is not supported.javax.jms.TemporaryTopic
createTemporaryTopic()
This method is not supported.javax.jms.TextMessage
createTextMessage()
Creates aTextMessage
.javax.jms.TextMessage
createTextMessage(String text)
Creates an initializedTextMessage
.javax.jms.Topic
createTopic(String topicName)
This method is not supported.int
getAcknowledgeMode()
Returns the acknowledge mode of the session.javax.jms.MessageListener
getMessageListener()
This method is not supported.boolean
getTransacted()
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(javax.jms.MessageListener listener)
This method is not supported.void
unsubscribe(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.JMSException
Creates aQueueReceiver
for the specified queue.- Specified by:
createReceiver
in 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.JMSException
Creates aQueueReceiver
for the specified queue. Does not support messageSelector. It will drop anything in messageSelector.- Specified by:
createReceiver
in 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.JMSException
Creates aQueueSender
for the specified queue.- Specified by:
createSender
in 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.JMSException
Creates aBytesMessage
.- Specified by:
createBytesMessage
in 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.JMSException
According 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 interfacejavax.jms.Session
- Throws:
javax.jms.JMSException
-
createObjectMessage
public javax.jms.ObjectMessage createObjectMessage() throws javax.jms.JMSException
Creates aObjectMessage
.- Specified by:
createObjectMessage
in 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:
createObjectMessage
in 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.JMSException
Creates aTextMessage
.- Specified by:
createTextMessage
in 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:
createTextMessage
in 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.JMSException
Returns the acknowledge mode of the session. The acknowledge mode is set at the time that the session is created.- Specified by:
getAcknowledgeMode
in interfacejavax.jms.Session
- Returns:
- acknowledge mode
- Throws:
javax.jms.JMSException
-
close
public void close() throws javax.jms.JMSException
Closes 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 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.JMSException
Negative acknowledges all the messages on the session that is delivered but not acknowledged.- Specified by:
recover
in 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.JMSException
Creates aMessageProducer
for the specified destination. Only queue destinations are supported at this time.- Specified by:
createProducer
in 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.JMSException
Creates aMessageConsumer
for the specified destination. Only queue destinations are supported at this time.- Specified by:
createConsumer
in 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.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 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.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 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:
createQueue
in interfacejavax.jms.QueueSession
- Specified by:
createQueue
in 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.JMSException
SQS does not support transacted. Transacted will always be false.- Specified by:
getTransacted
in interfacejavax.jms.Session
- Throws:
javax.jms.JMSException
-
commit
public void commit() throws javax.jms.JMSException
This method is not supported. This method is related to transaction which SQS doesn't support- Specified by:
commit
in interfacejavax.jms.Session
- Throws:
javax.jms.JMSException
-
rollback
public void rollback() throws javax.jms.JMSException
This method is not supported. This method is related to transaction which SQS doesn't support- Specified by:
rollback
in 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:
unsubscribe
in 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:
createTopic
in interfacejavax.jms.Session
- Throws:
javax.jms.JMSException
-
createDurableSubscriber
public javax.jms.TopicSubscriber createDurableSubscriber(javax.jms.Topic topic, String name) throws javax.jms.JMSException
This method is not supported.- Specified by:
createDurableSubscriber
in 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.JMSException
This method is not supported.- Specified by:
createDurableSubscriber
in interfacejavax.jms.Session
- Throws:
javax.jms.JMSException
-
createBrowser
public javax.jms.QueueBrowser createBrowser(javax.jms.Queue queue) throws javax.jms.JMSException
This method is not supported.- Specified by:
createBrowser
in interfacejavax.jms.QueueSession
- Specified by:
createBrowser
in interfacejavax.jms.Session
- Throws:
javax.jms.JMSException
-
createBrowser
public javax.jms.QueueBrowser createBrowser(javax.jms.Queue queue, String messageSelector) throws javax.jms.JMSException
This method is not supported.- Specified by:
createBrowser
in interfacejavax.jms.QueueSession
- Specified by:
createBrowser
in interfacejavax.jms.Session
- Throws:
javax.jms.JMSException
-
createTemporaryQueue
public javax.jms.TemporaryQueue createTemporaryQueue() throws javax.jms.JMSException
This method is not supported.- Specified by:
createTemporaryQueue
in interfacejavax.jms.QueueSession
- Specified by:
createTemporaryQueue
in interfacejavax.jms.Session
- Throws:
javax.jms.JMSException
-
createTemporaryTopic
public javax.jms.TemporaryTopic createTemporaryTopic() throws javax.jms.JMSException
This method is not supported.- Specified by:
createTemporaryTopic
in interfacejavax.jms.Session
- Throws:
javax.jms.JMSException
-
getMessageListener
public javax.jms.MessageListener getMessageListener() throws javax.jms.JMSException
This method is not supported.- Specified by:
getMessageListener
in interfacejavax.jms.Session
- Throws:
javax.jms.JMSException
-
setMessageListener
public void setMessageListener(javax.jms.MessageListener listener) throws javax.jms.JMSException
This method is not supported.- Specified by:
setMessageListener
in interfacejavax.jms.Session
- Throws:
javax.jms.JMSException
-
createStreamMessage
public javax.jms.StreamMessage createStreamMessage() throws javax.jms.JMSException
This method is not supported.- Specified by:
createStreamMessage
in interfacejavax.jms.Session
- Throws:
javax.jms.JMSException
-
createMapMessage
public javax.jms.MapMessage createMapMessage() throws javax.jms.JMSException
This method is not supported.- Specified by:
createMapMessage
in interfacejavax.jms.Session
- Throws:
javax.jms.JMSException
-
checkClosed
public void checkClosed() throws javax.jms.IllegalStateException
Check if session is closed.- Throws:
javax.jms.IllegalStateException
-
checkClosing
public void checkClosing() throws javax.jms.IllegalStateException
Check if session is closed or closing.- Throws:
javax.jms.IllegalStateException
-
-