CQRS 中的验证和错误修复
我了解了 CQRS 的一般概念,但在超越示例代码和幻灯片来处理现实世界问题时,我有一些问题。
验证
当您需要验证涉及检查数据库中的值的命令时,您会做什么? 注册一项服务时,我必须输入一个唯一的电子邮件地址。我听到的一个论点是,用户不太可能输入重复的电子邮件地址,因此只需在处理命令时处理它并向他们发送一封电子邮件说“抱歉”,或者建议他们重置密码。因此,此过程避免了为了验证而使用读取模型。但是如何处理命令处理程序中的重复情况呢?那么你怎么知道它是重复的?检查读取模型?您不妨首先使用它以获得更好的可用性。
功能更改/修复错误
当您需要更改命令的工作方式或修复错误时会发生什么?在仅附加哲学中,我该如何处理所有旧命令和命令处理程序?我无法将它们重命名为 _legacy 并将它们隐藏起来,否则我的事件反序列化将无法工作。有哪些优雅的解决方案可以解决这个问题?
谢谢
I get the general concept of CQRS, but I've got a few questions when it comes to moving beyond the example code and slide decks that are out there to dealing with real world problems.
Validation
When you need to do validation of a command that involves checking values from the database, what do you do?
Take registration for a service, I must enter a unique email address. One argument i've heard is that its very unlikely that the user will enter a duplicate email address, so just handle it when processing the command and send them an email saying "sorry", or perhaps suggesting they reset their password. This process therefore avoids having a readmodel for the sake of the validation. But how do you deal with the duplicate case in the command handler? how do you know THEN that its a duplicate? check a readmodel? you might as well have used that in the first place for better usability.Changes to functionality/fixing bugs
What happens when you need to change the way a command works, or fix a bug? In the append-only philosophy, what do I do with all the old commands and command handlers? I can't rename them to _legacy and hide them away otherwise my event deserialization won't work. What elegant solutions are there to dealing with this?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一个警告!不要太轻视事件溯源。您只需使用 CQRS 就可以了。我看到人们在大多数情况下使用 CQRS 就可以切换到 CQRS+ES。
因此,请访问 groups.google.com/group/dddcqrs 并获取帮助。另一个有用的资源是 cqrsinfo.com
One warning! Don't take on event sourcing too lightly. You can get by with just CQRS. I see people switching over to CQRS+ES when most of the time CQRS will do.
So come on over to groups.google.com/group/dddcqrs and get help. Another useful resource is cqrsinfo.com