MassTransit-配置多个主题的RecectEndPoint

发布于 2025-01-21 02:41:58 字数 1820 浏览 1 评论 0原文

我正在研究以下实施:

有一个应用程序来管理一些实体,例如公司,客户等。 该数据需要由另一个应用程序消费才能做一些事情。 基本思想是通过 massTransit 使用消息传播(RabbitMq-aws)实现 Pub/sub 模型。 将消耗这些消息的应用程序是ASPNETCORE 6,我正在尝试弄清楚如何正确配置 receedEndpoints ,因为我是新的消息传递...

这是我到目前为止得到的。 ..

services.AddMassTransit(busCfg =>
{
    busCfg.AddConsumers(typeof(TheAssemblyThatContainsTheMessageSignatures).Assembly);
    
    busCfg.UsingRabbitMq((context, cfg) =>
    {
        // OPTION 1:
        // ONE ReceiveEndpoint (queue) for all messages.
        cfg.ReceiveEndpoint("MyCompany.MyServiceName", e =>
        {
            e.ConfigureConsumer<CompanyCreatedConsumer>(context);
            e.ConfigureConsumer<CompanyUpdatedConsumer>(context);

            e.ConfigureConsumer<ClientCreatedConsumer>(context);
            e.ConfigureConsumer<ClientUpdatedConsumer>(context);
            
            e.ConfigureConsumer<OtherEntityCreatedOrUpdatedConsumer>(context);
        });
        
        // OPTION 2:
        // A ReceiveEndpoint per entity-type.
        cfg.ReceiveEndpoint("MyCompany.MyServiceName.Company", e =>
        {
            e.ConfigureConsumer<CompanyCreatedConsumer>(context);
            e.ConfigureConsumer<CompanyUpdatedConsumer>(context);
        });
        cfg.ReceiveEndpoint("MyCompany.MyServiceName.Client", e =>
        {
            e.ConfigureConsumer<ClientCreatedConsumer>(context);
            e.ConfigureConsumer<ClientUpdatedConsumer>(context);
        });
        cfg.ReceiveEndpoint("MyCompany.MyServiceName.OtherEntityCreatedOrUpdated", e =>
        {
            e.ConfigureConsumer<OtherEntityCreatedOrUpdatedConsumer>(context);
        });
        
        // OPTION 3????
    });
});

I'm working on the following implementation:

There is an application for managing a few entities, such as Company, Client, etc.
This data needs to be consumed by another application in order to do some stuff.
The basic idea is to implement a Pub/Sub model using a message-broker (RabbitMq-AWS) through MassTransit.
The application that will consume those messages is an AspNetCore 6 and I'm trying to figure out how to properly configure ReceiveEndpoints as I'm kinnda new to messaging...

This is what I got so far...

services.AddMassTransit(busCfg =>
{
    busCfg.AddConsumers(typeof(TheAssemblyThatContainsTheMessageSignatures).Assembly);
    
    busCfg.UsingRabbitMq((context, cfg) =>
    {
        // OPTION 1:
        // ONE ReceiveEndpoint (queue) for all messages.
        cfg.ReceiveEndpoint("MyCompany.MyServiceName", e =>
        {
            e.ConfigureConsumer<CompanyCreatedConsumer>(context);
            e.ConfigureConsumer<CompanyUpdatedConsumer>(context);

            e.ConfigureConsumer<ClientCreatedConsumer>(context);
            e.ConfigureConsumer<ClientUpdatedConsumer>(context);
            
            e.ConfigureConsumer<OtherEntityCreatedOrUpdatedConsumer>(context);
        });
        
        // OPTION 2:
        // A ReceiveEndpoint per entity-type.
        cfg.ReceiveEndpoint("MyCompany.MyServiceName.Company", e =>
        {
            e.ConfigureConsumer<CompanyCreatedConsumer>(context);
            e.ConfigureConsumer<CompanyUpdatedConsumer>(context);
        });
        cfg.ReceiveEndpoint("MyCompany.MyServiceName.Client", e =>
        {
            e.ConfigureConsumer<ClientCreatedConsumer>(context);
            e.ConfigureConsumer<ClientUpdatedConsumer>(context);
        });
        cfg.ReceiveEndpoint("MyCompany.MyServiceName.OtherEntityCreatedOrUpdated", e =>
        {
            e.ConfigureConsumer<OtherEntityCreatedOrUpdatedConsumer>(context);
        });
        
        // OPTION 3????
    });
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟─花易冷 2025-01-28 02:41:58

请按照 documentation ,并且只使用configure> configureendpoints。您试图过度思考解决方案只会分散您的注意力。

MassTransit已经知道如何根据消费者名称配置接收端点,因此只需使用它即可。

Follow the documentation, and just use ConfigureEndpoints. Your attempt to over think a solution will just distract you.

MassTransit already knows how to configure receive endpoints based upon the consumer names, so just go with it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文