Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order of JMS TransactionSynchronizations should be sortable programmatically [SPR-16491] #21034

Open
spring-issuemaster opened this issue Feb 13, 2018 · 0 comments

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Feb 13, 2018

Ludovit Varga opened SPR-16491 and commented

Scenario:
I have application that consume message from JMS Server A, update row in database and produce messages to multiple JMS queues on different servers. This must be done in transaction and without JTA. Application is written with Spring Boot 2.0.0.M7 (with Spring 5.0.2) with data-jpa and jms starters.

Problem:
Application can't use JTA transactions (requirement from client), so I implemented Best effort 1PC pattern. It works nicely but client needs to have specific order of commit/rollback of JMS transactions. In my case he required that outbound messages are committed first and then are committed inbound message.

When i was reading thru code and documentation i found JmsResourceSynchronization and TransactionSynchronizationManager that are in middle of this functionality.

If i understand code correctly then while triggering afterCommit, JpaTransactionManager gets list of sorted TransactionSynchronization and sorting is done with AnnotationAwareOrderComparator.sort(). My observation is that order of commit/rollback is based on order in which JMS messages was send (and registered inside TransactionSynchronizationManager).

Because most methods are static and JmsResourceSynchronization is private, only what i can currently do is ugly and unreliable workaround like this:

List<TransactionSynchronization> synchronizations = TransactionSynchronizationManager.getSynchronizations();
TransactionSynchronizationManager.clearSynchronization();
TransactionSynchronizationManager.initSynchronization();
synchronizations = Lists.reverse(synchronizations);
synchronizations.forEach(TransactionSynchronizationManager::registerSynchronization);

If this sorting of same implementation of TransactionSynchronization (in my case JmsResourceSynchronization) can be done programmatically from @Configuration classes, that would be great.


Affects: 5.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.