本文介绍了CQRS-最终一致性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下情况需要按照CQRS模式实施:

I have the following scenario which I need to implement following the CQRS pattern:

  1. 用户登录
  2. 用户输入一些保险详细信息
  3. 用户要求应用决定
  4. 用户查看决策结果

这似乎很简单,但是我的问题是在步骤3和4之间,在步骤3中,我发送了ApplyForDecision命令,该命令将从承保服务获得决定,然后将具有该决定结果的事件发送给读取存储区的BUS,以后再使用它,并用决策结果更新视图表.

This seems fairly straightforward, however my problem is between step 3 and 4, on step 3 I send a ApplyForDecision command which will get a decision from a underwriting service, an event with the result of that decision is then sent to the BUS for the read store to later consume it and update the view tables with the decision result.

问题出在UI上,我如何让用户知道正在应用该决定,因为在CQRS中读取模型没有直接"更新,我如何使UI显示正在执行一项决定,以及会很快到达吗?

The problem is on the UI, how do I let the user know that the decision is being applied, since in CQRS the read model is not updated 'straightaway' how do I make the UI show that a decision is in progress and will 'soon' arrive?

我还需要使用户能够注销并重新登录,因为可能尚未应用该决定,如何使UI显示待决决定屏幕"?

I also need to give the user the ability to log out and log back in, since the decision may not have been applied yet, how do I make the UI show the 'pending decision screen'?

推荐答案

答案是立即引发一个事件,指示已申请该决策,更新读取的DB并直接重定向到您的待决决策屏幕,无论到那时读取的数据库已经更新.静态文字正在等待您与您联系的决定"或类似内容.它们可以刷新或稍后再返回,并且很有可能获得真实数据.然后,在做出决定后,您将遇到DecisionMade事件并更新读取的数据库,并在任何情况下相应地发送电子邮件.

The answer is to immediately raise an event indicating the decision has been applied for, update the read DB and redirect straight away to your pending decision screen whether or not the read DB has been updated by that time. Static text 'Pending decision you will be contacted' or something along those lines. They can refresh or come back later and more than likely will get the real data. Then when the decision has been decided, you have a DecisionMade event and update the read DB, send emails out, whatever the case, accordingly.

这是您必须在CQRS中处理的最终一致性的折衷方案.通常,当我对表单上的域对象属性进行了更改时,我会在后端处理杂项的同时,立即得到用户的反馈,从而使它变得虚假.是的,有点难看,但是用户不知道.

That's the trade off with eventual consistency you have to deal with in CQRS. Often when I've made changes to domain object properties on a form, I fake it in the immediate feedback the user gets while the back end does its chores. Yes, a little ugly but the users don't know that.

这篇关于CQRS-最终一致性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 04:57