发送命令时,CQRS事件源检查用户名在EventStore中是否唯一 [英] CQRS Event Sourcing check username is unique or not from EventStore while sending command

查看:140
本文介绍了发送命令时,CQRS事件源检查用户名在EventStore中是否唯一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们具有特定的唯一EntityID时,EventSourcing可以完美地工作,但是当我尝试从除特定EntityId之外的eventStore中获取信息时,我遇到了困难。

EventSourcing works perfectly when we have particular unique EntityID but when I am trying to get information from eventStore other than particular EntityId i am having tough time.

我正在使用具有EventSourcing的CQRS。作为事件源的一部分,我们将事件作为列(EntityID(uniqueKey),EventType,EventObject(例如,UserAdded))存储在SQL表中。

I am using CQRS with EventSourcing. As part of event-sourcing we are storing the events in SQL table as columns(EntityID (uniqueKey),EventType,EventObject(eg. UserAdded)).

因此,在存储时EventObject我们只是序列化DotNet对象并将其存储在SQL中,因此,与UserAdded事件有关的所有详细信息都将为xml格式。我的担心是我想确保db中存在的userName应该唯一。

So while storing EventObject we are just serializing the DotNet object and storing it in SQL, So, All the details related to UserAdded event will be in xml format. My concern is I want to make sure the userName which is present in db Should be unique.

因此,在执行AddUser命令时,我必须查询EventStore( sql db)事件存储中是否已经存在特定的用户名。为此,我需要序列化事件存储中的所有UserAdded / UserEdited事件,并检查事件存储中是否存在所请求的用户名。

So, while making command of AddUser I have to query EventStore(sql db) whether the particular userName is already present in eventStore. So for doing that I need to serialize all the UserAdded/UserEdited events in Event store and check if requested username is present in eventStore.

但是由于种族条件,不允许查询CQRS命令。

<因此,我在发送AddUser命令之前尝试过,只是查询eventStore并通过序列化所有事件(UserAdded)并获取用户名来获取所有用户名,如果请求的用户名是唯一的,则请使用Shoot命令,否则抛出该用户名已经存在的异常。

So, I tried before sending the AddUser command just query the eventStore and get all the UserNames by serializing all events(UserAdded) and fetch usernames and if requested username is unique then shoot command else throwing exception that userName already exist.

与上述方法一样,我们需要查询整个数据库,每天可能有数十万个事件。因此执行查询/反序列化将花费大量时间。会导致性能问题的ime。

As with above approach ,we need to query entire db and we may have hundreds of thousands of events/day.So the execution of query/deserialization will take much time which will lead to performance issue.

我正在寻找通过从eventStore或所有其他方法获取所有用户名来保持用户名唯一的更好方法/建议

推荐答案

因此,您的客户端(发出命令的对象)应该完全相信它发送的命令将被执行,并且必须通过确保在发送RegisterUserCommand之前,没有其他用户使用该电子邮件地址注册来执行此操作。换句话说,您的客户必须执行验证,而不是您的域甚至是域周围的应用程序服务。

So, your client (the thing that issues the commands) should have full faith that the command it sends will be executed, and it must do this by ensuring that, before it sends the RegisterUserCommand, that no other user is registered with that email address. In other words, your client must perform the validation, not your domain or even the application services that surround the domain.

来自 http://cqrs.nu/Faq


出现问题,因为我们显然没有
在写端执行交叉聚合操作。我们确实有
,但有很多选择:

This is a commonly occurring question since we're explicitly not performing cross-aggregate operations on the write side. We do, however, have a number of options:

创建已分配用户名的读取端。

Create a read-side of already allocated user names. Make the client query the read-side interactively as the user types in a name.

创建一个反应式的传奇来标记和停用$ b的帐户,从而使客户端
以交互方式查询用户的读取端。

Create a reactive saga to flag down and inactivate accounts that were nevertheless created with a duplicate user name. (Whether by extreme coincidence or maliciously or because of a faulty client.)

如果最终的一致性对您而言不够快,请考虑添加
写入侧的表,它是一个很小的本地读取侧,已经分配了
个名称。使总交易包括插入到该表中的

If eventual consistency is not fast enough for you, consider adding a table on the write side, a small local read-side as it were, of already allocated names. Make the aggregate transaction include inserting into that table.

这篇关于发送命令时,CQRS事件源检查用户名在EventStore中是否唯一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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