(四)MMA(事件通知/模块间数据状态迁移/Meterialized Views/Saga Pattern)



项目地址

  • 教程作者:
  • 教程地址:
  • 代码仓库地址:
  • 所用到的框架和插件:
dbt 
airflow

一、事件通知

二、数据状态迁移

在这里插入图片描述

  • 模块下的IntegrationEvents这个模块是专门用来负责数据状态迁移,一般是用来,同步到CRM系统或是邮件系统

2.1 UserRegisteredIntegrationEvent

1. 创建UserRegisteredIntegrationEvent(Users)

  • 这个类是用来定义该行为的对象
namespace Evently.Modules.Users.IntegrationEvents;
public sealed class UserRegisteredIntegrationEvent
 : IntegrationEvent
{
   
   
    public UserRegisteredIntegrationEvent(
        Guid id,
        DateTime occurredOnUtc,
        Guid userId,
        string email,
        string firstName,
        string lastName)
        : base(id, occurredOnUtc)
    {
   
   
        UserId = userId;
        Email = email;
        FirstName = firstName;
        LastName = lastName;
    }
    public Guid UserId {
   
    get; init; }
    public string Email {
   
    get; init; }
    public string FirstName {
   
    get; init; }
    public string LastName {
   
    get; init; }
}

2. UserRegisteredIntegrationEvent进行发布(Users)

  • 这里发布的是上面的UserRegisteredIntegrationEvent
    在这里插入图片描述

3. UserRegisteredIntegrationEventHandler(消费者模块)

  • 所有需要用到该数据的模块,都需要创建UserRegisteredIntegrationEventHandler,该系统中Ticketing和
namespace Evently.Modules.Ticketing.Presentation.Customers;
internal sealed class UserRegisteredIntegrationEventHandler(ISender sender)
    : IntegrationEventHandler<UserRegisteredIntegrationEvent>
{
   
   
    public override async Task Handle(
        UserRegisteredIntegrationEvent integrationEvent,
        CancellationToken cancellationToken = default)
    {
   
   
        Result result = await sender.Send(
            new CreateCustomerCommand(
                integrationEvent.UserId,
                integrationEvent.Email,
                integrationEvent.FirstName,
                integrationEvent.LastName),
            cancellationToken);
        if (result.IsFailure)
        {
   
   
            throw new EventlyException(nameof(CreateCustomerCommand), result.Error);
        }
    }
}
  • Attendance 模块
namespace Evently.Modules.Attendance.Presentation.Attendees;
internal sealed class UserRegisteredIntegrationEventHandler(ISender sender)
    : IntegrationEventHandler<UserRegistere
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值