This is a question related to designing command handling with Axon 4.
Let say I've a domain that model the concept of a Payment
.
The actual payment will be done by an external Partner. I want to track it in my system via the following events: a Payment Request Was Issued followed by either Partner Agreed the Payment or Partner Declined the Payment.
Every events issued by the command should be enrolled in the same database transaction.
What would be the best practice to actually call my partner in Axon 4 ?
Here's what I've done so far:
- Have one command named
RequestPaymentCommand
- This command will be handled by a
Payment
Aggregate like this:- do some checks
- apply the event
PaymentRequestWasIssued
- and then, call the external partner and given the result it will apply either
PaymentAccepted
orPaymentRefused
In this answer from stackoverflow, it is said that
All the data that you need to apply the event should normally be available in the command
With this statement in mind, I understand that I should create as much Commands as Events ? But In this case, what is the point of all theses commands ? Should I end up with something like:
- My command
RequestPaymentCommand
will generate thePaymentRequestWasIssued
event. - Then from somewhere I call my partner and then send another command (how to name it ?) that will generate the event given the result from the partner ?