Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Design Commands And Events while Handling External partner with Axon 4

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 or PaymentRefused

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 the PaymentRequestWasIssued 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 ?
like image 222
Sylvain Avatar asked Mar 04 '23 16:03

Sylvain


1 Answers

The actual payment will be done by an external Partner

This means that your application is not the source of truth and it should not try to behave like one. This means that it should only observe what is happening in the remote system and possible react to remote events. To "observe" could mean to duplicate/copy the remote events in local databases, without modifications, just for cache reasons or for display reasons. Your system should not directly give other interpretations to these events, other than those given by their source.

After the remote events are copied locally, your system could react to them. This could mean that a Saga, after receives the Partner Agreed the Payment it sends a UnlockFeature command to a local Aggregate (see DDD).

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 ?

This is an indication that those are not your events: you should not emit them from your code; in the worst case you store them and react to them (in a Saga/Process manager). This means that you should discover the local business processes and model them as such: they react to events by sending commands.

like image 74
Constantin Galbenu Avatar answered Apr 06 '23 01:04

Constantin Galbenu