spring-framework / org.springframework.jms.connection / TransactionAwareConnectionFactoryProxy

TransactionAwareConnectionFactoryProxy

open class TransactionAwareConnectionFactoryProxy : ConnectionFactory, QueueConnectionFactory, TopicConnectionFactory

Proxy for a target JMS javax.jms.ConnectionFactory, adding awareness of Spring-managed transactions. Similar to a transactional JNDI ConnectionFactory as provided by a Java 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.

Author
Juergen Hoeller

Since
2.0

See Also
UserCredentialsConnectionFactoryAdapterSingleConnectionFactory

Constructors

<init>

TransactionAwareConnectionFactoryProxy()
TransactionAwareConnectionFactoryProxy(targetConnectionFactory: ConnectionFactory)

Create a new TransactionAwareConnectionFactoryProxy.

Functions

createConnection

open fun createConnection(): Connection
open fun createConnection(username: String, password: String): Connection

createContext

open fun createContext(): JMSContext
open fun createContext(userName: String, password: String): JMSContext
open fun createContext(userName: String, password: String, sessionMode: Int): JMSContext
open fun createContext(sessionMode: Int): JMSContext

createQueueConnection

open fun createQueueConnection(): QueueConnection
open fun createQueueConnection(username: String, password: String): QueueConnection

createTopicConnection

open fun createTopicConnection(): TopicConnection
open fun createTopicConnection(username: String, password: String): TopicConnection

setSynchedLocalTransactionAllowed

open fun setSynchedLocalTransactionAllowed(synchedLocalTransactionAllowed: Boolean): Unit

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

fun setTargetConnectionFactory(targetConnectionFactory: ConnectionFactory): Unit

Set the target ConnectionFactory that this ConnectionFactory should delegate to.