adaumann
adaumann

Reputation: 31

Masstransit Auto Configure endpoints does not exclude manually added receive endpoints

In Masstransit for .NET (V7.3.0) I added a new consumers (UpdateFooConsumer) from assemblies and used Rabbit MQ for a specific endpoint to be configurated individually (by adding a consume filter). All other consumers should be automatically mapped, therefore I added busFactoryConfigurator.ConfigureEndpoints(context)

       _ = services.AddMassTransit(
        configure =>
        {
           [...]
           configure.AddConsumers(ConsumerBusFilter, assemblies.ToArray());
           [...]
           configure.UsingRabbitMq(context, configurator) =>
                 busFactoryConfigurator.ReceiveEndpoint("update-foo", x =>
                 { 
                       x.UseConsumeFilter(typeof(LoggingConsumeFilter<>), context);
                 });
           [...]
           configurator.ConfigureEndpoints(context)

I got an exception:

ConfigurationException: A receive endpoint with the same key was already added: update-foo

I remember from the docs that Endpoints configured before "ConfigureEndpoints" are not mapped automatically, this seems not the case.

Next I tried to exclude it:

        configurator.ConfigureEndpoints(context, x => x.Exclude<UpdateFooConsumer>());

But does not work... any ideas?

Upvotes: 0

Views: 2671

Answers (1)

Chris Patterson
Chris Patterson

Reputation: 33565

Configuring a receive endpoint doesn't actually configure the consumer. If you want to exclude a consumer, saga, etc. from configuration, you need to configure it.

I updated your configuration so that it should work as you expect:

_ = services.AddMassTransit(configure =>
{
      [...]

      configure.AddConsumers(ConsumerBusFilter, assemblies.ToArray());

      [...]

      configure.UsingRabbitMq(context, configurator) =>
           busFactoryConfigurator.ReceiveEndpoint("update-foo", x =>
           { 
                 x.UseConsumeFilter(typeof(LoggingConsumeFilter<>), context);
                 
                 x.ConfigureConsumer<UpdateFooConsumer>(context);
           });

      [...]

      configurator.ConfigureEndpoints(context);
});

As you can see, the ConfigureConsumer call is significant, vs. calling Consumer or nothing at all (which is never right, since it would just dump every message into _skipped).

Upvotes: 2

Related Questions