public final class ConnectionFactoryUtils extends Object
ConnectionFactory
,
in particular for obtaining transactional Rabbit resources for a given ConnectionFactory.
Mainly for internal use within the framework. Used by RabbitTemplate
as
well as SimpleMessageListenerContainer
.
Modifier and Type | Class and Description |
---|---|
static interface |
ConnectionFactoryUtils.ResourceFactory
Callback interface for resource creation.
|
Modifier and Type | Method and Description |
---|---|
static RabbitResourceHolder |
bindResourceToTransaction(RabbitResourceHolder resourceHolder,
ConnectionFactory connectionFactory,
boolean synched) |
static void |
checkAfterCompletion()
When using transaction synchronization, call this method after the transaction commits to
verify that the RabbitMQ transaction committed.
|
static Connection |
createConnection(ConnectionFactory connectionFactory,
boolean publisherConnectionIfPossible)
Create a connection with this connection factory and/or its publisher factory.
|
static void |
enableAfterCompletionFailureCapture(boolean enable)
Call this method to enable capturing
AfterCompletionFailedException s
when using transaction synchronization. |
static RabbitResourceHolder |
getTransactionalResourceHolder(ConnectionFactory connectionFactory,
boolean synchedLocalTransactionAllowed)
Obtain a RabbitMQ Channel that is synchronized with the current transaction, if any.
|
static RabbitResourceHolder |
getTransactionalResourceHolder(ConnectionFactory connectionFactory,
boolean synchedLocalTransactionAllowed,
boolean publisherConnectionIfPossible)
Obtain a RabbitMQ Channel that is synchronized with the current transaction, if any.
|
static boolean |
isChannelTransactional(com.rabbitmq.client.Channel channel,
ConnectionFactory connectionFactory)
Determine whether the given RabbitMQ Channel is transactional, that is, bound to the current thread by Spring's
transaction facilities.
|
static void |
registerDeliveryTag(ConnectionFactory connectionFactory,
com.rabbitmq.client.Channel channel,
Long tag) |
static void |
releaseResources(RabbitResourceHolder resourceHolder) |
public static boolean isChannelTransactional(com.rabbitmq.client.Channel channel, ConnectionFactory connectionFactory)
channel
- the RabbitMQ Channel to checkconnectionFactory
- the RabbitMQ ConnectionFactory that the Channel originated frompublic static RabbitResourceHolder getTransactionalResourceHolder(ConnectionFactory connectionFactory, boolean synchedLocalTransactionAllowed)
connectionFactory
- the ConnectionFactory to obtain a Channel forsynchedLocalTransactionAllowed
- whether to allow for a local RabbitMQ 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 RabbitMQ transaction committing right after the main transaction. If not allowed, the given
ConnectionFactory needs to handle transaction enlistment underneath the covers.null
if none foundpublic static RabbitResourceHolder getTransactionalResourceHolder(ConnectionFactory connectionFactory, boolean synchedLocalTransactionAllowed, boolean publisherConnectionIfPossible)
connectionFactory
- the ConnectionFactory to obtain a Channel forsynchedLocalTransactionAllowed
- whether to allow for a local RabbitMQ 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 RabbitMQ transaction committing right after the main transaction. If not allowed, the given
ConnectionFactory needs to handle transaction enlistment underneath the covers.publisherConnectionIfPossible
- obtain a connection from a separate publisher connection
if possible.null
if none foundpublic static void releaseResources(@Nullable RabbitResourceHolder resourceHolder)
public static RabbitResourceHolder bindResourceToTransaction(RabbitResourceHolder resourceHolder, ConnectionFactory connectionFactory, boolean synched)
public static void enableAfterCompletionFailureCapture(boolean enable)
AfterCompletionFailedException
s
when using transaction synchronization. Exceptions are stored in a ThreadLocal
which must be cleared by calling checkAfterCompletion()
after the transaction
has completed.enable
- true to enable capture.public static void checkAfterCompletion()
AfterCompletionFailedException
- if synchronization failed.public static void registerDeliveryTag(ConnectionFactory connectionFactory, com.rabbitmq.client.Channel channel, Long tag)
public static Connection createConnection(ConnectionFactory connectionFactory, boolean publisherConnectionIfPossible)
connectionFactory
- the connection factory.publisherConnectionIfPossible
- true to use the publisher factory, if present.