Spring AMQP

org.springframework.amqp.rabbit.connection
Class ConnectionFactoryUtils

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

public class ConnectionFactoryUtils
extends 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

Nested Class Summary
static interface ConnectionFactoryUtils.ResourceFactory
          Callback interface for resource creation.
 
Constructor Summary
ConnectionFactoryUtils()
           
 
Method Summary
static com.rabbitmq.client.Channel doGetTransactionalChannel(ConnectionFactory connectionFactory, ConnectionFactoryUtils.ResourceFactory resourceFactory)
          Obtain a RabbitMQ Channel that is synchronized with the current transaction, if any.
static com.rabbitmq.client.Channel getTransactionalChannel(ConnectionFactory cf, com.rabbitmq.client.Connection existingCon, boolean synchedLocalTransactionAllowed)
          Obtain a RabbitMQ Channel that is synchronized with the current transaction, if any.
static boolean isChannelTransactional(com.rabbitmq.client.Channel channel, ConnectionFactory cf)
          Determine whether the given RabbitMQ Channel is transactional, that is, bound to the current thread by Spring's transaction facilities.
static void releaseConnection(com.rabbitmq.client.Connection con, ConnectionFactory cf)
          Release the given Connection by closing it.
 
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

releaseConnection

public static void releaseConnection(com.rabbitmq.client.Connection con,
                                     ConnectionFactory cf)
Release the given Connection by closing it.


isChannelTransactional

public static boolean isChannelTransactional(com.rabbitmq.client.Channel channel,
                                             ConnectionFactory cf)
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
cf - the RabbitMQ ConnectionFactory that the Channel originated from
Returns:
whether the Channel is transactional

getTransactionalChannel

public static com.rabbitmq.client.Channel getTransactionalChannel(ConnectionFactory cf,
                                                                  com.rabbitmq.client.Connection existingCon,
                                                                  boolean synchedLocalTransactionAllowed)
                                                           throws IOException
Obtain a RabbitMQ Channel that is synchronized with the current transaction, if any.

Parameters:
cf - the ConnectionFactory to obtain a Channel for
existingCon - the existing RabbitMQ Connection to obtain a Channel for (may be null)
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
Throws:
IOException

doGetTransactionalChannel

public static com.rabbitmq.client.Channel doGetTransactionalChannel(ConnectionFactory connectionFactory,
                                                                    ConnectionFactoryUtils.ResourceFactory resourceFactory)
                                                             throws IOException
Obtain a RabbitMQ Channel that is synchronized with the current transaction, if any.

Parameters:
connectionFactory - the RabbitMQ ConnectionFactory to bind for (used as TransactionSynchronizationManager key)
resourceFactory - the ResourceFactory to use for extracting or creating RabbitMQ resources
Returns:
the transactional Channel, or null if none found
Throws:
IOException

Spring AMQP

Copyright © 2010. All Rights Reserved.