Is Distributed Command Bus mandatory having multiple instances of the same microservice?


I have two instances of the same microservice. Currently I’m using default command bus and I’m not sure if this is ok.
I know that there is some aggregate locking and I guess that it works only having a single instance.

I’m worried about processing two commands concurrently in two instances.
Should I use a Distributed Command Bus?

Other microservices don’t use axon.


Hi Filip,

you probably don’t have to. When not using a Distributed Command Bus, you effectively handle commands on the node where they are also dispatched. If your level of concurrency is low, you’re unlikely to be handling commands for the same Aggregate simultaneously on different nodes. However, if you do, Axon will detect this when attempting to append events (or if you use GenericJpaRepository, make sure you have optimistic locking configured on your JPA entities). In this case one of attempts to save an Aggregate will result in a org.axonframework.commandhandling.model.ConcurrencyException, and force the transaction to roll back.

You can use a RetryScheduler on the CommandGateway to automatically retry commands that failed this way.

So you don’t need to use a DistributedCommandBus, but it does allow you to prevent these ConcurrencyExceptions, making your application more efficient when running in a highly concurrent environment.

Hope this helps.


Thanks, you helped me a lot.


W dniu czwartek, 28 grudnia 2017 12:30:44 UTC+1 użytkownik Filip napisał: