If you really wouldn’t want to use Axon’s CommandBus
and QueryBus
with their respective message, you are indeed inclined to construct and manage the UnitOfWork
yourself. This would also mean you are inclined to attach Axon Framework’s TransactionManager
to the UnitOfWork
you construct yourself to keep the transactionality of the Aggregate-Repository.
However, with that in place, you could invoke the Repository
from within your controller if you like.
Granted, the above is all boilerplate Axon Framework resolves for you, if you just dispatch a command message.
Although I agree JPMS helps for modularization, it does not streamline the communication between your modules directly. Using Commands, Events, and Queries for this (thus, CQRS) is just an additional helper to clarify the communication.
Furthermore, by using message buses, you are free to have these modules in a single unit now and break them apart in the future. All you would have to do is change the message bus configuration from a local to a distributed version in that case.
Let me dive into another point you’re sharing, @Nicolas_Fedou:
The SimpleCommandBus
is nothing more than a direct invocation on the same thread. The bus just abstracts the handler away from you, making the messages your API instead of a set of interfaces.
To stick to the protection of your consistency boundary in a distributed environment, you would want to ensure operations dedicated to a given model are routed to the same instance consistently. Doing so eliminates the need for a distributed transaction or dealing with the exception of a concurrency exception. In that frame of thought, you would require either (1) Axon Server or (2) a DistributedCommandBus
using
Axon Framework’s Spring Cloud or JGroups extension
Even when you are taking this route, Axon Framework will ensure that if the message can be routed locally, it will be acted upon locally. In both the case of Axon Server and the DistributedCommandBus
, there is indeed an Executor
that constructs a new thread for the actual invocation. I think a small price to pay not to have to deal with distributed transactions.
Conclusion
Long story short, you could go without using Axon Frameworks message buses. However, I think it will make things a lot easier for you, without coming with the drawbacks you’re assuming. I’ll be looking forward to additional drawbacks you may have, @Nicolas_Fedou!