在与Axon 4处理外部合作伙伴时设计命令和事件 [英] Design Commands And Events while Handling External partner with Axon 4
问题描述
这是与使用Axon 4设计命令处理有关的问题。
This is a question related to designing command handling with Axon 4.
让我说我有一个模拟概念的域付款
。
实际付款将由外部合作伙伴完成。我想通过以下事件在我的系统中对其进行跟踪:发出付款请求,然后是
合作伙伴同意付款或合作伙伴拒绝了付款。
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.
在Axon 4中实际给我的伴侣打电话的最佳做法是什么?
What would be the best practice to actually call my partner in Axon 4 ?
这是我到目前为止所做的:
Here's what I've done so far:
- 已一个命令名为
RequestPaymentCommand
- 此命令将由
付款
处理,如下所示:
- 进行一些检查
- 应用事件
PaymentRequestWasIssued
- ,然后致电外部合作伙伴,并根据结果将应用
PaymentAccepted
或PaymentRefused
- 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
事件通常应该在命令中可用
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:
- 我的命令
RequestPaymentCommand
将生成PaymentRequestWasIssued
事件。 - 然后从我打电话给我的伴侣的地方,然后发送另一个命令(如何命名) ?)将根据合作伙伴的结果生成事件?
- 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 ?
推荐答案
实际付款将由外部合作伙伴完成
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.
在本地复制远程事件之后,您的系统可能会对它们做出反应。这可能意味着Saga在收到
合作伙伴同意付款
后,会向本地汇总发送UnlockFeature
命令(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 aUnlockFeature
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 ?
这表明这些事件不是您的事件:您不应从代码中发出它们;在最坏的情况下,您存储它们并对它们做出反应(在Saga / Process Manager中)。这意味着您应该发现本地业务流程并对其进行建模:它们通过发送命令对事件做出反应。
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.
这篇关于在与Axon 4处理外部合作伙伴时设计命令和事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!