Using both Simple and Remote CommandBus

I can’t get the new claim “evolutionary microservices” out of my head … it seems to be a good and fitting idea to start with a monolith and later extract components as a separate system.
I understand that axon supports this by using the key busses/gateways (command/event/query) for communication in the monolith.

What I do not really get: Assume I have 3 Aggregates (A,B,C) as bounded contexts in my monolith that all use the Simple/Default busses.
In A spring boot application, how would I configure my busses/gateways so A and B stay on one system and C becomes a new one … when I do not want A and B communicate through a remote messaging, is there a way to configure the communication on a command/aggregate level so each command can be routed to either a remote or simple bus without forcing the publisher/sender dealing with the details?

Are there examples for this combination of distributed and local communication?


Hi Jan,

Great to hear the term ‘evolutionary microservices’ is sticking!
Hope you can achieve that to your liking as well, and I’m more then ready to help you with that.

What I think you should be having a look at is the RoutingStrategy interface.

The RoutingStrategy is a component Axon uses in the DistributedCommandBus to decide which nodes receives which commands.
By default, an AnnotationRoutingStrategy is provided, which decides which node gets which command based on the aggregate identifier in a command message, so the field annotated with @TargetAggregateIdentifier.

Additional note, if the RoutingStrategy decides the command should go to the local segmet (so the need that component is running on), the local CommandBus is used.

You can however provide your own implementation of a RoutingStrategy which could for example check to what aggregate a command should go and based on that provide some routing. It should thus be relatively straightforward to introduce the ideal routing form you’re looking for.

I hope this helps!


Hi Jan,

to briefly elaborate on Steven’s response:
Axon routes commands based on the capability of the nodes around it. If one component contains the handlers for commands for aggregate A and B, and another node those for C, Axon will automatically route commands for A and B to that node only. As Steven said, if that’s also the node sending the commands, then there doesn’t have to be remoting involved, if the CommandRouter indicates the destination is “local”.

If you have a distributed scenario, I’d recommend just using the DistributedCommandBus. Internally, it uses another command bus implementation as the “local segment”. The implementations are optimized to avoid unnecessary remote calls. Anything you manually add or work around this, is a risk in case you’d want to switch to a different implementation, such as AxonHub.