Implementing CQRS with Axon : Multiple datasources and transaction managers

Hi,
I am new to Axon framework and working on an application using the framework. Following the CQRS tenants I would like to separate the Command and Query parts, the following is what I have implemented ,

Command App (DataStore A)

Hi Ranjit,

which EventBus implementation do you use?

With the SimpleEventBus, events are handled in the same transaction as the one that handles the command. If you query component requires another transaction for persisting the results in another store, you need to register a unit of work listener with the unit of work, to commit a transaction for the new data store during the commit phase.

Cheers,

Allard

Hi Allard,
I use the SimpleEventBus. Thanks for your suggestion regarding the use of unit of work listener. What is the mechanism for registering the unit of work listeners with the DefaulUnitOfWorkFactory? Do I need to implement my own UnitOfWorkFactory to attach the listeners to the UnitOfWork? I use spring to wire up this components.

Regards,
Ranjit N

Hi Ranjit,

you can always register listeners with the current Unit of Work by accessing it though the static CurrentUnitOfWork.get() method. It will throw an exception when no UnitOfWork is active, so be sure to check its existence using CurrentUnitOfWork.isStarted(). With the UnitOfWork reference, you can simply register a listener.

Cheers,

Allard