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

CQRS/ES - User Login from Read Or From Write Side

我正在使用事件源在 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 有点困惑。

    我有两种方法:

    第一种方法 -

    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 架构)。 但是由于我使用的是读取端的public API,所以我想,可能是 正确。

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

we cannot use the read side in write side (as I read and know in cqrs architecture)

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

I have never seen in any architecture diagram that read side fires and event and handle by write side

这是一个足够常见的模式 - 订阅者观察读取模型的变化,并计算命令以发送到写入模型。如果您搜索 "process manager" 和 "event driven architecture",您可能会找到您正在寻找的图表。

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

So which approach you guys suggest

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

但如果您要自己动手,我认为您需要认真了解您的实际延迟要求,然后从那里着手。