Spring AMQP/RabbitMQ transaction rollback in EJB3 CMT -
i trying test rollback of transaction initiated ejb3 container, involves spring jpa repository call , message sender rabbitmq using spring amqp integration. after cmt rollback see db transaction gets rolled back, message getting delivered queue.
i injecting spring bean ejb makes call rabbit template , has @transactional annotation. see transactioninterceptor committing transaction after spring bean send message call. hoping delegate commit container.
any suggestions/workarounds appreciated. wasn't able figure out how initialize transactionsynchronizationmanager without using @transactional annotation.
here code committing transaction when spring bean proxy executes transactioninterceptor code:
resourceholdersynchronization @override public void aftercommit() { if (!shouldreleasebeforecompletion()){ -- method returns false processresourceaftercommit(this.resourceholder); -- calling commitall } } connectionfactoryutils/rabbitresourcesynchronization @override protected boolean shouldreleasebeforecompletion() { return !this.transacted; -- transacted true (channeltransacted) } rabbitresourceholder public void commitall() throws amqpexception { try { (channel channel : this.channels) { if (deliverytags.containskey(channel)) { (long deliverytag : deliverytags.get(channel)) { channel.basicack(deliverytag, false); } } channel.txcommit(); } } catch (ioexception e) { throw new amqpexception("failed commit rabbitmq transaction", e); } }
here spring configuration:
<tx:jta-transaction-manager/> <tx:annotation-driven /> <rabbit:connection-factory id="rabbitconnectionfactory" addresses="node01:5672,node02:5672" username="user.." password="pwd..." /> <bean id="rabbittemplate" class="org.arbfile.monitor.message.broker.api.rabbitmq.customrabbittemplate" > <property name="connectionfactory" ref="rabbitconnectionfactory" /> <property name="retrytemplate" ref="retrytemplate" /> <property name="exchange" value="user.example.exchange" /> <property name="queue" value="user.example.queue" /> <property name="routingkey" value="user.example.queue" /> <property name="channeltransacted" value="true" /> </bean>
Comments
Post a Comment