CQRS/ES - 用户从读取端或写入端登录



我正在使用事件源在 CQRS 中构建用户登录和身份验证。与AXON框架(

Follwing是我的模型中的步骤 -

  1. 用户注册流程-

    UserRegistrationCommand handles the user registration , since the 
    application makes the uniqueness between users using email , means only one 
    user can register with one email. (For this I was maintaining the table on 
    read side , which contains the registered email address. So when user tries 
    to register ,We query the read side for the validation of email address 
    from client side (not from the write side),and show a message "This email 
    is already register").
    When the client validation passes ,the UserRegistrationCommand is issued and 
    handled by the command handler , which then fires an event called 
    UserRegistredEvent , and this event is handled by the event handler on read 
    side and updates the read side DB.
    

    2. 用户登录流程 - 我对用户登录有点困惑。

    我脑子里有两种方法:

    第一种方法 -

    User login using the read side, means user enters the username and 
    password. And this username and password is validated from read side, and   
    UserLogedInEvent is fired from the read side and catched by the write side and is
    saved in event store.
    

但我从未在任何架构图中看到读取侧火和事件并通过写入端处理。

那么我能做到吗?

第二种方法 -

User login using write side , means the user issues UserLogingCommand 
and before the command dispatch to command handler , we validate the 
username and password using the read side by accessing the same public api 
of read side (which was used in first approach). 

但问题是,我们不能在写入端使用读取端(正如我读的那样 并了解 CQRS 架构(。 但是由于我使用的是读取端的公共API,所以我可以认为,它可能是 正确。

那么你们建议哪种方法,或者还有其他方法可以做到这一点

我们不能在写入端使用读取端(正如我在 CQRS 架构中阅读和知道的那样(

这不太对。 在计算写入时使用读取端数据并没有错——你只需要注意延迟

我从未在任何架构图中看到读取侧火和事件并通过写入端处理

这是一种足够常见的模式 - 订阅者监视读取模型中的更改,并计算要发送到写入模型的命令。 如果您搜索"流程管理器"和"事件驱动架构",您可能会找到所需的图表。

例如,爱丽丝下订单。 因此,我们将其写在订单簿中,因此会向计费服务和履行服务发送消息。

那么你们建议哪种方法

真诚地?购买用于登录和身份验证的商品解决方案,然后继续解决对核心业务有价值的问题。

但是,如果您要自己滚动,我认为您需要认真查看您的延迟要求实际上是什么,并从那里开始工作。

相关内容

最新更新