Hi Fredrik, Faik,
Fredrik, typically, your command handlers are set on Aggregates.
What Axon does when it loads an Aggregate from the repository, is to place a lock on it. Hence, if you’d send an Aggregate a ‘DownloadThisCommand’, it will lock the Aggregate for handling other commands until it has finished it’s operation. This, to me, sounds a little off, having an Aggregate download stuff, but then again, I am not familiar with your domain at all.
What I will recommend though is to move away from the default SimpleCommandBus, as command handling will block this bus from receiving other commands.
Instead, you can use the AsynchronousCommandBus, which will create separate threads for publishing and handling the commands.
Additionally, from the small domain-portion I get from your description, I think I’d put such a command handler on a singleton rather than on an aggregate.
You can also take the route Faik is suggestion. So, have a saga perform the download and send compensating action if it fails.
This could be a valid use case, but this depends on what you’re actually trying to do here.
When you’d offload the downloading process to the saga however, I think your message would look something like ‘RequestToDownloadCommand’ —in-aggregate—> ‘DownloadRequestedEvent’ —in-saga—> ‘Actual-Download’. The ‘…RequestedEvents’ are typically a suggestion the modelling process is taking some weird turns, hence why I wasn’t starting of with a Saga/Event Handler explanation for this.
Hope this helps you out.
Cheers
Steven