jakarta.jms.ConnectionFactory , adding awareness of
Spring-managed transactions. Similar to a transactional JNDI ConnectionFactory
as provided by a Jakarta EE application server.
Messaging code which should remain unaware of Spring's JMS support can work with
this proxy to seamlessly participate in Spring-managed transactions. Note that the
transaction manager, for example JmsTransactionManager, still needs to work
with the underlying ConnectionFactory, not with this proxy.
Make sure that TransactionAwareConnectionFactoryProxy is the outermost
ConnectionFactory of a chain of ConnectionFactory proxies/adapters.
TransactionAwareConnectionFactoryProxy can delegate either directly to the
target factory or to some intermediary adapter like
UserCredentialsConnectionFactoryAdapter.
Delegates to ConnectionFactoryUtils for automatically participating
in thread-bound transactions, for example managed by JmsTransactionManager.
createSession calls and close calls on returned Sessions
will behave properly within a transaction, that is, always work on the transactional
Session. If not within a transaction, normal ConnectionFactory behavior applies.
Note that transactional JMS Sessions will be registered on a per-Connection
basis. To share the same JMS Session across a transaction, make sure that you
operate on the same JMS Connection handle - either through reusing the handle
or through configuring a SingleConnectionFactory underneath.
Returned transactional Session proxies will implement the SessionProxy
interface to allow for access to the underlying target Session. This is only
intended for accessing vendor-specific Session API or for testing purposes
(e.g. to perform manual transaction control). For typical application purposes,
simply use the standard JMS Session interface.
As of Spring Framework 5, this class delegates JMS 2.0 JMSContext
calls and therefore requires the JMS 2.0 API to be present at runtime.
It may nevertheless run against a JMS 1.1 driver (bound to the JMS 2.0 API)
as long as no actual JMS 2.0 calls are triggered by the application's setup.
UserCredentialsConnectionFactoryAdapter, SingleConnectionFactory
| Modifier and Type | Class and Description |
|---|---|
| private static class | TransactionAwareConnectionFactoryProxy.
Invocation handler that suppresses close calls for a transactional JMS Session. |
| private class | TransactionAwareConnectionFactoryProxy.
Invocation handler that exposes transactional Sessions for the underlying Connection. |
| Modifier and Type | Field and Description |
|---|---|
| private boolean | |
| private ConnectionFactory |
| Access | Constructor and Description |
|---|---|
| public | |
| public | TransactionAwareConnectionFactoryProxy(ConnectionFactory
the target ConnectionFactory targetConnectionFactory)Create a new TransactionAwareConnectionFactoryProxy. |
| Modifier and Type | Method and Description |
|---|---|
| public Connection | createConnection()
Implements jakarta. Creates a connection with the default user identity. |
| public Connection | createConnection(String
the caller's user name username, String the caller's password password)Implements jakarta. Creates a connection with the specified user identity. |
| public JMSContext | createContext()
Implements jakarta. Creates a JMSContext with the default user identity and an unspecified sessionMode. |
| public JMSContext | createContext(String
the caller's user name userName, String the caller's password password)Implements jakarta. Creates a JMSContext with the specified user identity and an unspecified sessionMode. |
| public JMSContext | createContext(String
the caller's user name userName, String the caller's password password, int indicates which of four possible session modes will be used.
sessionMode)
Implements jakarta. Creates a JMSContext with the specified user identity and the specified session mode. |
| public JMSContext | createContext(int
indicates which of four possible session modes will be used.
sessionMode)
Implements jakarta. Creates a JMSContext with the default user identity and the specified session mode. |
| public QueueConnection | createQueueConnection()
Implements jakarta. Creates a queue connection with the default user identity. |
| public QueueConnection | createQueueConnection(String
the caller's user name username, String the caller's password password)Implements jakarta. Creates a queue connection with the specified user identity. |
| public TopicConnection | createTopicConnection()
Implements jakarta. Creates a topic connection with the default user identity. |
| public TopicConnection | createTopicConnection(String
the caller's user name username, String the caller's password password)Implements jakarta. Creates a topic connection with the specified user identity. |
| protected ConnectionFactory | getTargetConnectionFactory()
Return the target ConnectionFactory that this ConnectionFactory should delegate to. |
| protected Connection | Returns: the wrapped Connectionthe original Connection to wrap target)Wrap the given Connection with a proxy that delegates every method call to it but handles Session lookup in a transaction-aware fashion. |
| protected boolean | isSynchedLocalTransactionAllowed()
Return whether to allow for a local JMS transaction that is synchronized with a Spring-managed transaction. |
| public void | setSynchedLocalTransactionAllowed(boolean synchedLocalTransactionAllowed)
Set whether to allow for a local JMS transaction that is synchronized with a Spring-managed transaction (where the main transaction might be a JDBC-based one for a specific DataSource, for example), with the JMS transaction committing right after the main transaction. |
| public final void | setTargetConnectionFactory(ConnectionFactory targetConnectionFactory)
Set the target ConnectionFactory that this ConnectionFactory should delegate to. |
| synchedLocalTransactionAllowed | back to summary |
|---|---|
| private boolean synchedLocalTransactionAllowed | |
| targetConnectionFactory | back to summary |
|---|---|
| private ConnectionFactory targetConnectionFactory
| |
| TransactionAwareConnectionFactoryProxy | back to summary |
|---|---|
| public TransactionAwareConnectionFactoryProxy() Create a new TransactionAwareConnectionFactoryProxy. | |
| TransactionAwareConnectionFactoryProxy | back to summary |
|---|---|
| public TransactionAwareConnectionFactoryProxy(ConnectionFactory targetConnectionFactory) Create a new TransactionAwareConnectionFactoryProxy.
| |
| createConnection | back to summary |
|---|---|
| public Connection createConnection() throws JMSException Implements jakarta. Doc from jakarta. Creates a connection with the default user identity. The connection is created in stopped mode. No messages will be
delivered until the
| |
| createConnection | back to summary |
|---|---|
| public Connection createConnection(String username, String password) throws JMSException Implements jakarta. Doc from jakarta. Creates a connection with the specified user identity. The connection is created in stopped mode. No messages will be
delivered until the
| |
| createContext | back to summary |
|---|---|
| public JMSContext createContext() Implements jakarta. Doc from jakarta. Creates a JMSContext with the default user identity and an unspecified sessionMode. A connection and session are created for use by the new JMSContext. The connection is created in stopped mode but will be automatically started when a JMSConsumer is created. The behaviour of the session that is created depends on whether this method is called in a Java SE environment, in the Jakarta EE application client container, or in the Jakarta EE web or EJB container. If this method is called in the Jakarta EE web or EJB container then the behaviour of the session also depends on whether or not there is an active JTA transaction in progress. In a Java SE environment or in the Jakarta EE application client container:
In a Jakarta EE web or EJB container, when there is an active JTA transaction in progress:
In the Jakarta EE web or EJB container, when there is no active JTA transaction in progress:
| |
| createContext | back to summary |
|---|---|
| public JMSContext createContext(String userName, String password) Implements jakarta. Doc from jakarta. Creates a JMSContext with the specified user identity and an unspecified sessionMode. A connection and session are created for use by the new JMSContext. The connection is created in stopped mode but will be automatically started when a JMSConsumer. The behaviour of the session that is created depends on whether this method is called in a Java SE environment, in the Jakarta EE application client container, or in the Jakarta EE web or EJB container. If this method is called in the Jakarta EE web or EJB container then the behaviour of the session also depends on whether or not there is an active JTA transaction in progress. In a Java SE environment or in the Jakarta EE application client container:
In a Jakarta EE web or EJB container, when there is an active JTA transaction in progress:
In the Jakarta EE web or EJB container, when there is no active JTA transaction in progress:
| |
| createContext | back to summary |
|---|---|
| public JMSContext createContext(String userName, String password, int sessionMode) Implements jakarta. Doc from jakarta. Creates a JMSContext with the specified user identity and the specified session mode. A connection and session are created for use by the new JMSContext. The JMSContext is created in stopped mode but will be automatically started when a JMSConsumer is created.
The effect of setting the In a Java SE environment or in the Jakarta EE application client container:
In a Jakarta EE web or EJB container, when there is an active JTA transaction in progress:
In the Jakarta EE web or EJB container, when there is no active JTA transaction in progress:
| |
| createContext | back to summary |
|---|---|
| public JMSContext createContext(int sessionMode) Implements jakarta. Doc from jakarta. Creates a JMSContext with the default user identity and the specified session mode. A connection and session are created for use by the new JMSContext. The JMSContext is created in stopped mode but will be automatically started when a JMSConsumer is created.
The effect of setting the In a Java SE environment or in the Jakarta EE application client container:
In a Jakarta EE web or EJB container, when there is an active JTA transaction in progress:
In the Jakarta EE web or EJB container, when there is no active JTA transaction in progress:
| |
| createQueueConnection | back to summary |
|---|---|
| public QueueConnection createQueueConnection() throws JMSException Implements jakarta. Doc from jakarta. Creates a queue connection with the default user identity. The connection is created in stopped mode. No messages
will be delivered until the
| |
| createQueueConnection | back to summary |
|---|---|
| public QueueConnection createQueueConnection(String username, String password) throws JMSException Implements jakarta. Doc from jakarta. Creates a queue connection with the specified user identity. The connection is created in stopped mode. No messages
will be delivered until the
| |
| createTopicConnection | back to summary |
|---|---|
| public TopicConnection createTopicConnection() throws JMSException Implements jakarta. Doc from jakarta. Creates a topic connection with the default user identity. The connection is created in stopped mode. No messages
will be delivered until the
| |
| createTopicConnection | back to summary |
|---|---|
| public TopicConnection createTopicConnection(String username, String password) throws JMSException Implements jakarta. Doc from jakarta. Creates a topic connection with the specified user identity. The connection is created in stopped mode. No messages
will be delivered until the
| |
| getTargetConnectionFactory | back to summary |
|---|---|
| protected ConnectionFactory getTargetConnectionFactory() Return the target ConnectionFactory that this ConnectionFactory should delegate to. | |
| getTransactionAwareConnectionProxy | back to summary |
|---|---|
| protected Connection getTransactionAwareConnectionProxy(Connection target) Wrap the given Connection with a proxy that delegates every method call to it but handles Session lookup in a transaction-aware fashion.
| |
| isSynchedLocalTransactionAllowed | back to summary |
|---|---|
| protected boolean isSynchedLocalTransactionAllowed() Return whether to allow for a local JMS transaction that is synchronized with a Spring-managed transaction. | |
| setSynchedLocalTransactionAllowed | back to summary |
|---|---|
| public void setSynchedLocalTransactionAllowed(boolean synchedLocalTransactionAllowed) Set whether to allow for a local JMS transaction that is synchronized with a Spring-managed transaction (where the main transaction might be a JDBC-based one for a specific DataSource, for example), with the JMS transaction committing right after the main transaction. If not allowed, the given ConnectionFactory needs to handle transaction enlistment underneath the covers. Default is "false": If not within a managed transaction that encompasses the underlying JMS ConnectionFactory, standard Sessions will be returned. Turn this flag on to allow participation in any Spring-managed transaction, with a local JMS transaction synchronized with the main transaction. | |
| setTargetConnectionFactory | back to summary |
|---|---|
| public final void setTargetConnectionFactory(ConnectionFactory targetConnectionFactory) Set the target ConnectionFactory that this ConnectionFactory should delegate to. | |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public Object | invoke(Object
the proxy instance that the method was invoked on proxy, Method the method, Object[] Method instance corresponding to
the interface method invoked on the proxy instance. The declaring
class of the Method object will be the interface that
the method was declared in, which may be a superinterface of the
proxy interface that the proxy class inherits the method through.an array of objects containing the values of the
arguments passed in the method invocation on the proxy instance,
or args)null if interface method takes no arguments.
Arguments of primitive types are wrapped in instances of the
appropriate primitive wrapper class, such as
java.lang.Integer or java.lang.Boolean.Implements java. Processes a method invocation on a proxy instance and returns the result. |
| target | back to summary |
|---|---|
| private final Session target | |
| CloseSuppressingSessionInvocationHandler | back to summary |
|---|---|
| public CloseSuppressingSessionInvocationHandler(Session target) | |
| invoke | back to summary |
|---|---|
| public Object invoke(Object proxy, Method method, Object[] args) throws Throwable Implements java. Doc from java. Processes a method invocation on a proxy instance and returns the result. This method will be invoked on an invocation handler when a method is invoked on a proxy instance that it is associated with.
| |
| Modifier and Type | Field and Description |
|---|---|
| private final Connection |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| private Session | |
| public Object | invoke(Object
the proxy instance that the method was invoked on proxy, Method the method, Object[] Method instance corresponding to
the interface method invoked on the proxy instance. The declaring
class of the Method object will be the interface that
the method was declared in, which may be a superinterface of the
proxy interface that the proxy class inherits the method through.an array of objects containing the values of the
arguments passed in the method invocation on the proxy instance,
or args)null if interface method takes no arguments.
Arguments of primitive types are wrapped in instances of the
appropriate primitive wrapper class, such as
java.lang.Integer or java.lang.Boolean.Implements java. Processes a method invocation on a proxy instance and returns the result. |
| target | back to summary |
|---|---|
| private final Connection target | |
| TransactionAwareConnectionInvocationHandler | back to summary |
|---|---|
| public TransactionAwareConnectionInvocationHandler(Connection target) | |
| getCloseSuppressingSessionProxy | back to summary |
|---|---|
| private Session getCloseSuppressingSessionProxy(Session target) | |
| invoke | back to summary |
|---|---|
| public Object invoke(Object proxy, Method method, Object[] args) throws Throwable Implements java. Doc from java. Processes a method invocation on a proxy instance and returns the result. This method will be invoked on an invocation handler when a method is invoked on a proxy instance that it is associated with.
| |