I have the following situation:
My application contains three modules: ModuleA, ModuleB and Dashboard. (Starts like a joke, hmm? )
The Dashboard module handles a TaskCreated even which can be emitted by moduleA or moduleB.
The Dashboard itself handles a ClaimTask-Command to claim a task for a certain user. The actual claiming is not performed by the Dashboard module but needs to be delegated to the module which emitted the corresponding TaskCreated event initially.
Actually we don’t know how to achieve this.
A generic ClaimTask command is not possible as Axon needs a single CommandHandler for each command type.
Having specific commands for each module (ClaimTaskInModuleA and ClaimTaskInModuleB) is an option, but the Dashboard shouldn’t be aware of the other modules and shouldn’t know which other modules exist.
We ended up in adding a claimCommandQueryName to the TaskCreated event. The emitting module tells the Dashboard which Query it has to call to obtain the command which can be used to claim the task. moduleA provides a QueryHandler for moduleAClaimCommandQuery and returns a ClaimTaskInModuleA command instance.
Dashboard calls this query by using the event’s claimCommandQueryName, gets back a specific command and sends this command using the CommandGateway in order to invoke the command handler of the module which emitted the TaskCreated event initially.
That’s somehow cumbersome and I wonder if there is a better way to implement this.
Thanks for your ideas!