@Test public void testResourceHolder() { RabbitResourceHolder h1 = new RabbitResourceHolder(); RabbitResourceHolder h2 = new RabbitResourceHolder(); ConnectionFactory connectionFactory = mock(ConnectionFactory.class); TransactionSynchronizationManager.setActualTransactionActive(true); ConnectionFactoryUtils.bindResourceToTransaction(h1, connectionFactory, true); assertSame(h1, ConnectionFactoryUtils.bindResourceToTransaction(h2, connectionFactory, true)); TransactionSynchronizationManager.clear(); }
private void executeListenerInTransaction(Message message, long deliveryTag) { if (this.isRabbitTxManager) { ConsumerChannelRegistry.registerConsumerChannel(getChannel(), this.connectionFactory); } if (this.transactionTemplate == null) { this.transactionTemplate = new TransactionTemplate(this.transactionManager, this.transactionAttribute); } this.transactionTemplate.execute(s -> { RabbitResourceHolder resourceHolder = ConnectionFactoryUtils.bindResourceToTransaction( new RabbitResourceHolder(getChannel(), false), this.connectionFactory, true); if (resourceHolder != null) { resourceHolder.addDeliveryTag(getChannel(), deliveryTag); } // unbound in ResourceHolderSynchronization.beforeCompletion() try { callExecuteListener(message, deliveryTag); } catch (RuntimeException e1) { prepareHolderForRollback(resourceHolder, e1); throw e1; } catch (Throwable e2) { //NOSONAR ok to catch Throwable here because we re-throw it below throw new WrappedTransactionException(e2); } return null; }); }
private void executeListenerInTransaction(Message message, long deliveryTag) { if (this.isRabbitTxManager) { ConsumerChannelRegistry.registerConsumerChannel(getChannel(), this.connectionFactory); } if (this.transactionTemplate == null) { this.transactionTemplate = new TransactionTemplate(this.transactionManager, this.transactionAttribute); } this.transactionTemplate.execute(s -> { RabbitResourceHolder resourceHolder = ConnectionFactoryUtils.bindResourceToTransaction( new RabbitResourceHolder(getChannel(), false), this.connectionFactory, true); if (resourceHolder != null) { resourceHolder.addDeliveryTag(getChannel(), deliveryTag); } // unbound in ResourceHolderSynchronization.beforeCompletion() try { callExecuteListener(message, deliveryTag); } catch (RuntimeException e1) { prepareHolderForRollback(resourceHolder, e1); throw e1; } catch (Throwable e2) { //NOSONAR ok to catch Throwable here because we re-throw it below throw new WrappedTransactionException(e2); } return null; }); }
RabbitResourceHolder resourceHolder = ConnectionFactoryUtils.bindResourceToTransaction( new RabbitResourceHolder(consumer.getChannel(), false), getConnectionFactory(), true);
RabbitResourceHolder resourceHolder = ConnectionFactoryUtils.bindResourceToTransaction( new RabbitResourceHolder(consumer.getChannel(), false), getConnectionFactory(), true);
bindResourceToTransaction(resourceHolderToUse, connectionFactory, resourceFactory.isSynchedLocalTransactionAllowed());
bindResourceToTransaction(resourceHolderToUse, connectionFactory, resourceFactory.isSynchedLocalTransactionAllowed());
@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)); }