Axon SpringTransactionManager Clarification

105 views
Skip to first unread message

Jebuselwyn Martin

unread,
Jun 13, 2015, 6:54:30 AM6/13/15
to axonfr...@googlegroups.com
Hi,


Scenario:
- Simple CommandBus
- RabbitMQ backed Event Bus
- Oracle RDBMS (Aggregates - JPAStore)
- No EventSource Repo

TransactionManager injection: (Spring's PlatformTxnMgr)

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
primary="true">
<property name ="dataSource" ref="dataSource"/>
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
<constructor-arg ref="transactionManager"/>
</bean>
<bean id="axonTransactionManager" class="org.axonframework.unitofwork.SpringTransactionManager">
@Inject
private SpringTransactionManager transactionManager;

//Relevant CommandHandler Code
 
UnitOfWork unitOfWork = DefaultUnitOfWork.startAndGet(transactionManager);
try{
//Business Logic
// JPA Persistence of Aggregates (no eventSourcingRepo enabled)
eventBus.publish(asEventMessage(objectFromMetadata));
unitOfWork.commit();
}
catch (AnyException){
unitOfWork.rollback(e);
}
 
For the above scenario, is there a need for XATransactionManager when deployed in non-JEE (read-Tomcat) container? As per our initial tests, the UOW.rollback is working quite fine in the scenarios 

- DB service down (during insert or commit)
- RabbitMQ service down (during insert or commit)

Is there any missing scenario which requires XATxnmanager? Any best-practices to be followed to have a atomic txn within the CommandHandler?

Thanks,
Jebu.


Allard Buijze

unread,
Jun 13, 2015, 3:03:04 PM6/13/15
to axonfr...@googlegroups.com
Hi Jebu,

to be slightly safer, it's better to use unitOfWork.publish(...) instead of publishing directly to the event bus. That will ensure publication to the event bus is done at the correct time. 
My personaly experience is that there is no need for 2PC in this case. Appending events into the event store is the only thing that can fail for functional reasons. Therefore, it that succeeds, only technical issues can cause true problems. There is a very small window of opportunity between the event publication commit and the commit to the database for errors to occur. But I'm pretty sure this window of opportunity also exists with 2PC.

Cheers,

Allard

--
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to axonframewor...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages