Class SQSConnection
- All Implemented Interfaces:
jakarta.jms.Connection
,jakarta.jms.QueueConnection
,AutoCloseable
Supports concurrent use, but the session objects it creates do no support concurrent use.
The authentication does not take place with the creation of connection. It
takes place when the amazonSQSClient
is used to call any SQS
API.
The physical connections are handled by the underlying
amazonSQSClient
.
A JMS client typically creates a connection, one or more sessions, and a number of message producers and consumers. When a connection is created, it is in stopped mode. That means that no messages are being delivered, but message producer can send messages while a connection is stopped.
Although the connection can be started immediately, it is typical to leave
the connection in stopped mode until setup is complete (that is, until all
message consumers have been created). At that point, the client calls the
connection's start
method, and messages begin arriving at the
connection's consumers. This setup convention minimizes any client confusion
that may result from asynchronous message delivery while the client is still
in the process of setting itself up.
A connection can be started immediately, and the setup can be done afterwards. Clients that do this must be prepared to handle asynchronous message delivery while they are still in the process of setting up.
Transacted sessions are not supported.
Exception listener on connection is not supported.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Checks if the connection close is already completed.void
Checks if the connection close is in-progress or already completed.void
close()
Closes the connection.jakarta.jms.ConnectionConsumer
createConnectionConsumer
(jakarta.jms.Destination destination, String messageSelector, jakarta.jms.ServerSessionPool sessionPool, int maxMessages) This method is not supported.jakarta.jms.ConnectionConsumer
createConnectionConsumer
(jakarta.jms.Queue queue, String messageSelector, jakarta.jms.ServerSessionPool sessionPool, int maxMessages) This method is not supported.jakarta.jms.ConnectionConsumer
createDurableConnectionConsumer
(jakarta.jms.Topic topic, String subscriptionName, String messageSelector, jakarta.jms.ServerSessionPool sessionPool, int maxMessages) This method is not supported.jakarta.jms.QueueSession
createQueueSession
(boolean transacted, int acknowledgeMode) Creates aQueueSession
jakarta.jms.Session
jakarta.jms.Session
createSession
(boolean transacted, int acknowledgeMode) Creates aSession
jakarta.jms.Session
createSession
(int sessionMode) jakarta.jms.ConnectionConsumer
createSharedConnectionConsumer
(jakarta.jms.Topic topic, String subscriptionName, String messageSelector, jakarta.jms.ServerSessionPool sessionPool, int maxMessages) jakarta.jms.ConnectionConsumer
createSharedDurableConnectionConsumer
(jakarta.jms.Topic topic, String subscriptionName, String messageSelector, jakarta.jms.ServerSessionPool sessionPool, int maxMessages) software.amazon.awssdk.services.sqs.SqsClient
Get the AmazonSQSClient used by this connection.Gets the client identifier for this connection.jakarta.jms.ExceptionListener
jakarta.jms.ConnectionMetaData
Get the metadata for this connectionGet a wrapped version of the AmazonSQSClient used by this connection.void
setClientID
(String clientID) Sets the client identifier for this connection.void
setExceptionListener
(jakarta.jms.ExceptionListener listener) void
start()
Starts a connection's delivery of incoming messages.void
stop()
Stops a connection's delivery of incoming messages.
-
Method Details
-
getAmazonSQSClient
public software.amazon.awssdk.services.sqs.SqsClient getAmazonSQSClient()Get the AmazonSQSClient used by this connection. This can be used to do administrative operations that aren't included in the JMS specification, e.g. creating new queues.- Returns:
- the SqsClient used by this connection
-
getWrappedAmazonSQSClient
Get a wrapped version of the AmazonSQSClient used by this connection. The wrapper transforms all exceptions from the client into JMSExceptions so that it can more easily be used by existing code that already expects JMSExceptions. This client can be used to do administrative operations that aren't included in the JMS specification, e.g. creating new queues.- Returns:
- wrapped version of the AmazonSQSClient used by this connection
-
createQueueSession
public jakarta.jms.QueueSession createQueueSession(boolean transacted, int acknowledgeMode) throws jakarta.jms.JMSException Creates aQueueSession
- Specified by:
createQueueSession
in interfacejakarta.jms.QueueConnection
- Parameters:
transacted
- Only false is supported.acknowledgeMode
- Legal values areSession.AUTO_ACKNOWLEDGE
,Session.CLIENT_ACKNOWLEDGE
,Session.DUPS_OK_ACKNOWLEDGE
, andSQSSession.UNORDERED_ACKNOWLEDGE
- Returns:
- a new queue session.
- Throws:
jakarta.jms.JMSException
- If the QueueConnection object fails to create a session due to some internal error or lack of support for the specific transaction and acknowledge mode.
-
createSession
public jakarta.jms.Session createSession(boolean transacted, int acknowledgeMode) throws jakarta.jms.JMSException Creates aSession
- Specified by:
createSession
in interfacejakarta.jms.Connection
- Parameters:
transacted
- Only false is supported.acknowledgeMode
- Legal values areSession.AUTO_ACKNOWLEDGE
,Session.CLIENT_ACKNOWLEDGE
,Session.DUPS_OK_ACKNOWLEDGE
, andSQSSession.UNORDERED_ACKNOWLEDGE
- Returns:
- a new session.
- Throws:
jakarta.jms.JMSException
- If the QueueConnection object fails to create a session due to some internal error or lack of support for the specific transaction and acknowledge mode.
-
createSession
public jakarta.jms.Session createSession(int sessionMode) throws jakarta.jms.JMSException - Specified by:
createSession
in interfacejakarta.jms.Connection
- Throws:
jakarta.jms.JMSException
-
createSession
public jakarta.jms.Session createSession() throws jakarta.jms.JMSException- Specified by:
createSession
in interfacejakarta.jms.Connection
- Throws:
jakarta.jms.JMSException
-
getExceptionListener
public jakarta.jms.ExceptionListener getExceptionListener() throws jakarta.jms.JMSException- Specified by:
getExceptionListener
in interfacejakarta.jms.Connection
- Throws:
jakarta.jms.JMSException
-
setExceptionListener
public void setExceptionListener(jakarta.jms.ExceptionListener listener) throws jakarta.jms.JMSException - Specified by:
setExceptionListener
in interfacejakarta.jms.Connection
- Throws:
jakarta.jms.JMSException
-
checkClosing
public void checkClosing() throws jakarta.jms.IllegalStateExceptionChecks if the connection close is in-progress or already completed.- Throws:
jakarta.jms.IllegalStateException
- If the connection close is in-progress or already completed.
-
checkClosed
public void checkClosed() throws jakarta.jms.IllegalStateExceptionChecks if the connection close is already completed.- Throws:
jakarta.jms.IllegalStateException
- If the connection close is already completed.
-
start
public void start() throws jakarta.jms.JMSExceptionStarts a connection's delivery of incoming messages. A call tostart
on a connection that has already been started is ignored.This will not return until all the sessions start internally.
- Specified by:
start
in interfacejakarta.jms.Connection
- Throws:
jakarta.jms.JMSException
- On internal error
-
stop
public void stop() throws jakarta.jms.JMSExceptionStops a connection's delivery of incoming messages. A call tostop
on a connection that has already been stopped is ignored.This will not return until all the sessions stop internally, which blocks until receives and/or message listeners in progress have completed. While these message listeners are completing, they must have the full services of the connection available to them.
A call to stop must not return until delivery of messages has paused. This means that a client can rely on the fact that none of its message listeners will be called and that all threads of control waiting for receive calls to return will not return with a message until the connection is restarted. The received timers for a stopped connection continue to advance, so receives may time out while the connection is stopped.
A message listener must not attempt to stop its own connection; otherwise throws a IllegalStateException.
- Specified by:
stop
in interfacejakarta.jms.Connection
- Throws:
jakarta.jms.IllegalStateException
- If called by a message listener on its ownConnection
.jakarta.jms.JMSException
- On internal error or called if close is in progress.
-
close
public void close() throws jakarta.jms.JMSExceptionCloses the connection.This will not return until all the sessions close internally, which blocks until receives and/or message listeners in progress have completed.
The receives may return with a message or with null, depending on whether there was a message available at the time of the close. If one or more of the connection's sessions' message listeners is processing a message at the time when connection close is invoked, all the facilities of the connection and its sessions must remain available to those listeners until they return control to the JMS provider.
A message listener must not attempt to close its own connection; otherwise throws a IllegalStateException.
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfacejakarta.jms.Connection
- Throws:
jakarta.jms.IllegalStateException
- If called by a message listener on its ownConnection
.jakarta.jms.JMSException
- On internal error.
-
getClientID
Gets the client identifier for this connection.- Specified by:
getClientID
in interfacejakarta.jms.Connection
- Returns:
- client identifier
- Throws:
jakarta.jms.JMSException
- If the connection is being closed
-
setClientID
Sets the client identifier for this connection.Does not verify uniqueness of client ID, so does not detect if another connection is already using the same client ID
- Specified by:
setClientID
in interfacejakarta.jms.Connection
- Parameters:
clientID
- The client identifier- Throws:
jakarta.jms.JMSException
- If the connection is being closedjakarta.jms.InvalidClientIDException
- If empty or null client ID is usedjakarta.jms.IllegalStateException
- If the client ID is already set or attempted to set after an action on the connection already took place
-
getMetaData
public jakarta.jms.ConnectionMetaData getMetaData() throws jakarta.jms.JMSExceptionGet the metadata for this connection- Specified by:
getMetaData
in interfacejakarta.jms.Connection
- Returns:
- the connection metadata
- Throws:
jakarta.jms.JMSException
- If the connection is being closed
-
createConnectionConsumer
public jakarta.jms.ConnectionConsumer createConnectionConsumer(jakarta.jms.Destination destination, String messageSelector, jakarta.jms.ServerSessionPool sessionPool, int maxMessages) throws jakarta.jms.JMSException This method is not supported.- Specified by:
createConnectionConsumer
in interfacejakarta.jms.Connection
- Throws:
jakarta.jms.JMSException
-
createDurableConnectionConsumer
public jakarta.jms.ConnectionConsumer createDurableConnectionConsumer(jakarta.jms.Topic topic, String subscriptionName, String messageSelector, jakarta.jms.ServerSessionPool sessionPool, int maxMessages) throws jakarta.jms.JMSException This method is not supported.- Specified by:
createDurableConnectionConsumer
in interfacejakarta.jms.Connection
- Throws:
jakarta.jms.JMSException
-
createConnectionConsumer
public jakarta.jms.ConnectionConsumer createConnectionConsumer(jakarta.jms.Queue queue, String messageSelector, jakarta.jms.ServerSessionPool sessionPool, int maxMessages) throws jakarta.jms.JMSException This method is not supported.- Specified by:
createConnectionConsumer
in interfacejakarta.jms.QueueConnection
- Throws:
jakarta.jms.JMSException
-