Spring AMQP

org.springframework.amqp.rabbit.connection
Class ConnectionFactoryUtils

java.lang.Object
  extended by org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils

public class ConnectionFactoryUtils
extends java.lang.Object

Helper class for managing a Spring based Rabbit 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.

Author:
Mark Fisher, Dave Syer, Gary Russell

Nested Class Summary
static interface ConnectionFactoryUtils.ResourceFactory
          Callback interface for resource creation.
 
Constructor Summary
ConnectionFactoryUtils()
           
 
Method Summary
static void bindResourceToTransaction(RabbitResourceHolder resourceHolder, ConnectionFactory connectionFactory, boolean synched)
           
static com.rabbitmq.client.Channel getConsumerChannel()
          See registerConsumerChannel.
static RabbitResourceHolder getTransactionalResourceHolder(ConnectionFactory connectionFactory, boolean synchedLocalTransactionAllowed)
          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 registerConsumerChannel(com.rabbitmq.client.Channel channel)
          If a listener container is configured to use a RabbitTransactionManager, the consumer's channel is registered here so that it is used as the bound resource when the transaction actually starts.
static void registerDeliveryTag(ConnectionFactory connectionFactory, com.rabbitmq.client.Channel channel, java.lang.Long tag)
           
static void releaseResources(RabbitResourceHolder resourceHolder)
           
static void unRegisterConsumerChannel()
          See registerConsumerChannel.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionFactoryUtils

public ConnectionFactoryUtils()
Method Detail

registerConsumerChannel

public static void registerConsumerChannel(com.rabbitmq.client.Channel channel)
If a listener container is configured to use a RabbitTransactionManager, the consumer's channel is registered here so that it is used as the bound resource when the transaction actually starts. It is normally not necessary to use an external transaction manager because local transactions work the same in that the channel is bound to the thread. This is for the case when a user happens to wire in a RabbitTransactionManager.

Parameters:
channel -

unRegisterConsumerChannel

public static void unRegisterConsumerChannel()
See registerConsumerChannel. This method is called to unregister the channel when the consumer exits.


getConsumerChannel

public static com.rabbitmq.client.Channel getConsumerChannel()
See registerConsumerChannel. This method is called to retrieve the channel for this consumer.


isChannelTransactional

public 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.

Parameters:
channel - the RabbitMQ Channel to check
connectionFactory - the RabbitMQ ConnectionFactory that the Channel originated from
Returns:
whether the Channel is transactional

getTransactionalResourceHolder

public static RabbitResourceHolder getTransactionalResourceHolder(ConnectionFactory connectionFactory,
                                                                  boolean synchedLocalTransactionAllowed)
Obtain a RabbitMQ Channel that is synchronized with the current transaction, if any.

Parameters:
connectionFactory - the ConnectionFactory to obtain a Channel for
synchedLocalTransactionAllowed - 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.
Returns:
the transactional Channel, or null if none found

releaseResources

public static void releaseResources(RabbitResourceHolder resourceHolder)

bindResourceToTransaction

public static void bindResourceToTransaction(RabbitResourceHolder resourceHolder,
                                             ConnectionFactory connectionFactory,
                                             boolean synched)

registerDeliveryTag

public static void registerDeliveryTag(ConnectionFactory connectionFactory,
                                       com.rabbitmq.client.Channel channel,
                                       java.lang.Long tag)
                                throws java.io.IOException
Throws:
java.io.IOException

Spring AMQP