Communication between aggregates

I want to know can I send a command C via Command Gateway from Aggregate A and handle that command C in another Aggregate B without using Saga!.

If you can?: Yes
Should you?: Most likely No

you can of course inject the commandgateway like any other bean but remember that whenever your aggregate is loaded with eventsourcing your events are replayed and the commands will then be issued again as well. You can use external eventhandlers if its not a businessprocess that should be handled in a saga.

I tried to inject the command Gateway via @Autowired and send the command to be handled by another aggregate via its command handler but i get this org.axonframework.axonserver.connector.command.AxonServerRemoteCommandHandlingException(An exception was thrown by the remote message handling component.).

Hi Nouha,

To further deduce what the problem is in your scenario, it would be beneficial if you could share the entire stack trace with us.
An “AxonServerRemoteCommandHandlingException” can be thrown on several occasions, so just stating it happened is not sufficient to help you out.

By the way, what Nils is saying is definitely a recommendation.
You’d ideally wouldn’t lock your first aggregate by dispatching a command to another.
You might accidentally cause a deadlock if the command circles back in for example.
Hence I’d recommend having a simple event handler reacting to the command handled by the first aggregate, which in turn dispatches a command to the other.

That’s my two cents.