Difference between command bus and command gateway


I wanted to know the difference between command bus and command gateway. Which one is preferred in Axon 3.
The reason I ask this question is both of them seem to provide the same functionality but in the documentation I notice Axon is suggesting to use Command Gateway.

But in many discussion I see other developers still using a Command Bus.


the command gateway simply provides a friendlier API to send commands. It doesn’t require you to wrap your payload in a CommandMessage, for example, and allows you to configure interceptors that only kick in for that specific gateway instance. In the end, Commands are always sent via the Command Bus. So it doesn’t really matter which one you use.



Ok got that point, is it the same case about eventhandler and eventsourcinghandler. I would suggest in future versions of Axon may be you can deprecate the components which seems to perform the same function.

Hi Ajinkya,

No, it’s not the same case with the @EventHandler and @EventSourcingHandler annotations.
The @EventSourcingHandler is by definition only used to source a model based on the events in your event store.
Currently, this is only allowed for the Command Model, aka the Aggregate, where the EventSourcingRepository fixes this functionality for you.
An @EventHandler is just a function which listens to a certain event with no sourcing capabilities behind it.

Additionally I don’t think we’ll deprecate the CommandGateway, since as Allard says it’s a convenience wrapper around a CommandBus; it’s thus not a duplicate implementation, as it uses the CommandBus, but adds a simplified interface for you.

Hope this helps.