/** * Obtain a RabbitMQ Channel that is synchronized with the current transaction, if any. * @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) { return getTransactionalResourceHolder(connectionFactory, synchedLocalTransactionAllowed, false); }
/** * Obtain a RabbitMQ Channel that is synchronized with the current transaction, if any. * @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) { return getTransactionalResourceHolder(connectionFactory, synchedLocalTransactionAllowed, false); }
protected RabbitResourceHolder getTransactionalResourceHolder() { return ConnectionFactoryUtils.getTransactionalResourceHolder(this.connectionFactory, isChannelTransacted()); }
protected RabbitResourceHolder getTransactionalResourceHolder() { return ConnectionFactoryUtils.getTransactionalResourceHolder(this.connectionFactory, isChannelTransacted()); }
public void start() throws AmqpException { if (logger.isDebugEnabled()) { logger.debug("Starting consumer " + this); } this.thread = Thread.currentThread(); try { this.resourceHolder = ConnectionFactoryUtils.getTransactionalResourceHolder(this.connectionFactory, this.transactional); this.channel = this.resourceHolder.getChannel(); ClosingRecoveryListener.addRecoveryListenerIfNecessary(this.channel); // NOSONAR never null here } catch (AmqpAuthenticationException e) { throw new FatalListenerStartupException("Authentication failure", e); } this.deliveryTags.clear(); this.activeObjectCounter.add(this); passiveDeclarations(); setQosAndreateConsumers(); }
public void start() throws AmqpException { if (logger.isDebugEnabled()) { logger.debug("Starting consumer " + this); } this.thread = Thread.currentThread(); try { this.resourceHolder = ConnectionFactoryUtils.getTransactionalResourceHolder(this.connectionFactory, this.transactional); this.channel = this.resourceHolder.getChannel(); ClosingRecoveryListener.addRecoveryListenerIfNecessary(this.channel); // NOSONAR never null here } catch (AmqpAuthenticationException e) { throw new FatalListenerStartupException("Authentication failure", e); } this.deliveryTags.clear(); this.activeObjectCounter.add(this); passiveDeclarations(); setQosAndreateConsumers(); }
resourceHolder = ConnectionFactoryUtils.getTransactionalResourceHolder(getConnectionFactory(), true); channel = resourceHolder.getChannel(); if (channel == null) {
if (isChannelTransacted()) { resourceHolder = ConnectionFactoryUtils. getTransactionalResourceHolder(connectionFactory, true, this.usePublisherConnection); channel = resourceHolder.getChannel(); if (channel == null) {
if (isChannelTransacted()) { resourceHolder = ConnectionFactoryUtils. getTransactionalResourceHolder(connectionFactory, true, this.usePublisherConnection); channel = resourceHolder.getChannel(); if (channel == null) {
resourceHolder = ConnectionFactoryUtils.getTransactionalResourceHolder(getConnectionFactory(), true); channel = resourceHolder.getChannel(); if (channel == null) {
@Override protected void doBegin(Object transaction, TransactionDefinition definition) { if (definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) { throw new InvalidIsolationLevelException("AMQP does not support an isolation level concept"); } RabbitTransactionObject txObject = (RabbitTransactionObject) transaction; RabbitResourceHolder resourceHolder = null; try { resourceHolder = ConnectionFactoryUtils.getTransactionalResourceHolder(getConnectionFactory(), true); if (logger.isDebugEnabled()) { logger.debug("Created AMQP transaction on channel [" + resourceHolder.getChannel() + "]"); } // resourceHolder.declareTransactional(); txObject.setResourceHolder(resourceHolder); txObject.getResourceHolder().setSynchronizedWithTransaction(true); int timeout = determineTimeout(definition); if (timeout != TransactionDefinition.TIMEOUT_DEFAULT) { txObject.getResourceHolder().setTimeoutInSeconds(timeout); } TransactionSynchronizationManager.bindResource(getConnectionFactory(), txObject.getResourceHolder()); } catch (AmqpException ex) { if (resourceHolder != null) { ConnectionFactoryUtils.releaseResources(resourceHolder); } throw new CannotCreateTransactionException("Could not create AMQP transaction", ex); } }
@Override protected void doBegin(Object transaction, TransactionDefinition definition) { if (definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) { throw new InvalidIsolationLevelException("AMQP does not support an isolation level concept"); } RabbitTransactionObject txObject = (RabbitTransactionObject) transaction; RabbitResourceHolder resourceHolder = null; try { resourceHolder = ConnectionFactoryUtils.getTransactionalResourceHolder(getConnectionFactory(), true); if (logger.isDebugEnabled()) { logger.debug("Created AMQP transaction on channel [" + resourceHolder.getChannel() + "]"); } // resourceHolder.declareTransactional(); txObject.setResourceHolder(resourceHolder); txObject.getResourceHolder().setSynchronizedWithTransaction(true); int timeout = determineTimeout(definition); if (timeout != TransactionDefinition.TIMEOUT_DEFAULT) { txObject.getResourceHolder().setTimeoutInSeconds(timeout); } TransactionSynchronizationManager.bindResource(getConnectionFactory(), txObject.getResourceHolder()); } catch (AmqpException ex) { if (resourceHolder != null) { ConnectionFactoryUtils.releaseResources(resourceHolder); } throw new CannotCreateTransactionException("Could not create AMQP transaction", ex); } }
@Test public void testReceiveBlockingGlobalTx() throws Exception { template.convertAndSend(ROUTE, "blockGTXNoTO"); RabbitResourceHolder resourceHolder = ConnectionFactoryUtils .getTransactionalResourceHolder(this.template.getConnectionFactory(), true); TransactionSynchronizationManager.setActualTransactionActive(true); ConnectionFactoryUtils.bindResourceToTransaction(resourceHolder, this.template.getConnectionFactory(), true); template.setReceiveTimeout(-1); template.setChannelTransacted(true); String out = (String) template.receiveAndConvert(ROUTE); resourceHolder.commitAll(); resourceHolder.closeAll(); assertSame(resourceHolder, TransactionSynchronizationManager.unbindResource(template.getConnectionFactory())); assertNotNull(out); assertEquals("blockGTXNoTO", out); this.template.setReceiveTimeout(0); assertNull(this.template.receive(ROUTE)); }