1

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

以下是我的模型中的步骤 -

  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. UserLogin Flow - 我对 UserLogin 有点困惑。

    我有两种方法:

    第一种方法 -

    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,所以我可以认为,它可能是正确的。

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

4

1 回答 1

3

我们不能在写入端使用读取端(正如我在 cqrs 架构中阅读和了解的那样)

这不太对。在计算写入时使用读取端数据没有任何问题——您只需要注意延迟即可。

我从未在任何架构图中看到读取端触发和事件并由写入端处理

这是一种足够常见的模式——订阅者监视读取模型的变化,并计算发送给写入模型的命令。如果您搜索“流程管理器”和“事件驱动架构”,您可能会找到您正在寻找的图表。

例如,Alice 下订单。因此,我们将其记录在订单簿中,并因此将消息发送到计费服务和履行服务。

那么你们建议哪种方法

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

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

于 2018-06-29T12:54:49.237 回答