List of usage examples for org.springframework.amqp.rabbit.connection RabbitResourceHolder getConnection
@Nullable
public Connection getConnection()
From source file:org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.java
/** * Obtain a RabbitMQ Channel that is synchronized with the current * transaction, if any.//from www .j a v a2 s.c o m * * @param connectionFactory * the ConnectionFactory to obtain a Channel for * @param 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. * @return the transactional Channel, or <code>null</code> if none found */ public static RabbitResourceHolder getTransactionalResourceHolder(final ConnectionFactory connectionFactory, final boolean synchedLocalTransactionAllowed) { RabbitResourceHolder holder = doGetTransactionalResourceHolder(connectionFactory, new ResourceFactory() { public Channel getChannel(RabbitResourceHolder holder) { return holder.getChannel(); } public Connection getConnection(RabbitResourceHolder holder) { return holder.getConnection(); } public Connection createConnection() throws IOException { return connectionFactory.createConnection(); } public Channel createChannel(Connection con) throws IOException { return con.createChannel(synchedLocalTransactionAllowed); } public boolean isSynchedLocalTransactionAllowed() { return synchedLocalTransactionAllowed; } }); return holder; }
From source file:org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.java
public static void releaseResources(RabbitResourceHolder resourceHolder) { if (resourceHolder == null || resourceHolder.isSynchronizedWithTransaction()) { return;/*from w w w. j a v a 2 s . c o m*/ } RabbitUtils.closeChannel(resourceHolder.getChannel()); RabbitUtils.closeConnection(resourceHolder.getConnection()); }
From source file:org.springframework.amqp.rabbit.connection.RabbitAccessor.java
/** * Fetch an appropriate Connection from the given RabbitResourceHolder. * * @param holder the RabbitResourceHolder * @return an appropriate Connection fetched from the holder, or <code>null</code> if none found *//* w ww . j a v a 2 s . c o m*/ protected Connection getConnection(RabbitResourceHolder holder) { return holder.getConnection(); }