如何确保一致的客户端读取在最终的一致系统中? [英] How do you ensure consistent client reads in an eventual consistent system?

查看:88
本文介绍了如何确保一致的客户端读取在最终的一致系统中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究CQRS,并且正在寻找有关如何在最终的一致系统中解决客户阅读问题的文章.例如,考虑一个网上商店,用户可以在其中将商品添加到他们的购物车中.如果命令"AddItemToCart"的实际处理是异步完成的,如何确保客户端显示购物车中的物品?我了解分派命令异步和基于域事件更新读取模型异步的原理,但是我无法从客户端的角度看这是如何处理的.

I'm digging into CQRS and I am looking for articles on how to solve client reads in an eventual consistent system. Consider for example a web shop where users can add items to their cart. How can you ensure that the client displays items in the cart if the actual processing of the command "AddItemToCart" is done async? I understand the principles of dispatching commands async and updating the read model async based on domain events, but I fail to see how this is handled from the clients perspective.

推荐答案

有几种不同的实现方式;

There are a few different ways of doing it;

只需轮询服务器,直到更新读取模型.这与本展示的相似.

Just poll the server until you get the read model updated. This is similar to what Ben showed.

您有一个支持DTC的队列;并且您的命令放在第一位.他们那时;已执行,已发送事件,已更新读取模型;全部都在一次交易中.但是,使用这种方法实际上并没有获得任何好处,因此请不要这样.

You have a queue that supports DTC; and your commands are put there first. They are then; executed, events sent, read model updated; all inside a single transaction. You have not actually gained anything with this method though, so don't do it this way.

将读取的模型放置在客户端的本地存储中,并在发送相应事件时对其进行更新-但由于您一直在期待此事件,因此您已经更新了购物车的javascript视图.

Place the read models in local storage at the client and update them when the corresponding event is sent -- but you were expecting this event anyway, so you had already updated the javascript view of the shopping cart.

这篇关于如何确保一致的客户端读取在最终的一致系统中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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