Please sign in to comment.
AMQP-274 Local Transaction Issues
When running a listener container with local transactions (channelTransacted, and no external transaction manager), the consumer's channel is bound to the thread for use by downstream RabbitTemplates. However, the syncronizedWithTransaction boolean was not set so the RabbitTemplate closed the channel after its operation. We should never close the consumer's channel. The solution is to set the boolean when binding the resource. In addition, when using a RabbitTransactionManager, the RabbitResourceHolder.closeAll() method would close the consumer's channel. Previously, the consumer's channel was registered with a ThreadLocal in the ConnectionFactoryUtils. This enabled the doGetTransactionalResourceHolder method to bind the consumer's channel. The RabbitResourceHolder.closeAll() now examines the channels is it closing and skips the close for the consumer's channel. Added tests to the Local and External transaction test cases to ensure the appropriate channel.close() calls are executed, depending on the scenario. e.g. a local transaction with exposeListenerChannel=false should close() the exposed channel but not the consumer's channel.
- Loading branch information...
Showing with 78 additions and 15 deletions.
- +8 −0 spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/ConnectionFactoryUtils.java
- +8 −1 spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/RabbitResourceHolder.java
- +11 −2 ...bbit/src/main/java/org/springframework/amqp/rabbit/listener/AbstractMessageListenerContainer.java
- +29 −6 spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/ExternalTxManagerTests.java
- +22 −6 spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/LocallyTransactedTests.java