Home > front end >  MassTransit - Configure ReceiveEndpoint for multiple Topics
MassTransit - Configure ReceiveEndpoint for multiple Topics

Time:04-17

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????
    });
});

CodePudding user response:

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.

  • Related