Axon Framework:具有两个或三个微服务之间的补偿事件的Saga项目 [英] Axon Framework: Saga project with compensation events between two or three microservices

查看:231
本文介绍了Axon Framework:具有两个或三个微服务之间的补偿事件的Saga项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Axon Saga有疑问.我有一个项目,其中有三个微服务,每个微服务都有自己的数据库,但是两个从"微服务必须将其数据共享给主"微服务,因此我想使用Axon Saga.我已经问过有关补偿的问题,当出现问题时,我必须自己处理补偿,这是可以的,但并不理想.当前,我正在使用DistributedCommandBus在微服务之间进行通信,这是否有益?我正在使用Choreography Saga模型,所以现在是这样:

I have a question about Axon Saga. I have a project where I have three microservices, each microservice has his own database, but the two "Slave" microservice has to share his data to the "Master" microservice, for that I want to use the Axon Saga. I already asked a question about the compensation, when something goes wrong, and I have to deal with the compensation by myself, it is ok, but not ideal. Currently I am using the DistributedCommandBus to communicate between the microservices, is it good for that? I am using the Choreography Saga model, so here is what it is look like now:

  1. 主->发送命令->从1->处理事件
  2. 从站1->发送命令->主站->处理事件
  3. 主->发送命令->从2->处理事件
  4. 从站2->发送命令->主站->处理事件

如果出了什么问题,那么补偿命令/事件就会倒退.

If something went wrong then comes the compensating Commands/Events backwards.

我的问题是,有人在薪酬方面对Axon做过这样的事情吗,最佳做法是什么?如何重试Saga流程?使用RetryScheduler?如果可以的话,添加一个github仓库.

My question is has anybody did something like this with Axon, with compensation, what the best practices for that? How can I retry the Saga process? With the RetryScheduler? Add a github repo if you can.

谢谢,玛特

推荐答案

首先,让我回答您的主要问题:

First and foremost, let me answer your main question:

我的问题是有人用Axon做过类似的事情吗?

My question is has anybody did something like this with Axon?

很快,是的,因为这是Sagas的主要用例之一. 根据经验,我想说明Saga可用于协调以下之间的复杂业务交易:

Shortly, yes, as this is one of the main use cases of for Sagas. As a rule of thumb, I'd like to state a Saga can be used to coordinate a complex business transaction between:

  1. 几个不同的聚合实例
  2. 几个有限的上下文

从表面上看,您似乎已经进入了委派复杂业务交易的第二种选择.

On face value, it seems you've landed in option two of delegating a complex business transaction.

请注意,在使用Sagas时,您应该非常有意识地处理任何异常和/或命令调度结果.

It is important to note that when you are using Sagas, you should very consciously deal with any exceptions and/or command dispatching results.

因此,如果您从主服务器"向从属服务器1"发送命令,而后者却无法执行操作,则此结果将返回到Saga中. 因此,这为您提供了重试操作的第一个选项,我建议使用补偿动作进行操作. 最后,通过补偿动作,我正在谈论调度命令来触发它.

Thus, if you dispatch a command from the "Master" to "Slave 1" and the latter fails the operation, this result will come back in to the Saga. This thus gives you the first option to retry an operation, which I would suggest to do with a compensating action. Lastly, with a compensating action, I am talking about dispatching a command to trigger it.

如果您不能依靠调度命令的直接响应,那么在Saga中重试/重新调度消息将是合理的第二选择.

If you can not rely on the direct response from dispatching the command, retrying/rescheduling a message within the Saga would be a reasonable second option.

为此,Axon具有EventSchedulerDeadlineManager. 请注意,两者中的前者会发布事件供所有人观看. 后者在单个Saga实例的上下文中安排DeadlineMessage,因此限制了可以看到重试发生的人员的范围.

To that end, Axon has the EventScheduler and DeadlineManager. Note that the former of the two publishes an event for everyone to see. The latter schedules a DeadlineMessage within the context of that single Saga instance, thus limiting the scope of who can see a retry is occurring.

通常,DeadlineManager是我的首选操作方式,除非您要求每个人都可以看到此重新安排动作". 仅供参考,请检查 EventScheduler信息页面和页面>信息.

Typically, the DeadlineManager would be my preferred mode of operation for thus, unless you require this 'rescheduling action' to be seen by everybody. FYI, check this page for EventScheduler information and this page for DeadlineManager info.

这篇关于Axon Framework:具有两个或三个微服务之间的补偿事件的Saga项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆