This article provides an example of how to do this when configuring an endpoint manually.
Just like this:
cfg.ReceiveEndpoint("input-queue", ec =>
{
ec.DiscardFaultedMessages();
});
But I've got a lot of consumers and I don't want to configure each of them manually, so I use methods AddConsumers
and ConfigureEndpoints
.
Like this:
services.AddMassTransit(cfg =>
{
cfg.AddConsumers(Assembly.GetExecutingAssembly());
cfg.AddBus(sp => Bus.Factory.CreateUsingRabbitMq(x => x.ConfigureEndpoints(sp)));
});
If I additionally call the ReceiveEndPoint
method (before or after calling ConfigureEndpoints
), the exception "A receive endpoint with the same key was already added" is thrown.
Is there a way to configure a specific endpoint when using ConfigureEndpoints method?
When using ConfigureEndpoints
, consumers, sagas, and activites are configured on receive endpoints automatically. To configure the receive endpoint for a specific consumer, create a consumer definition . If scanning an assembly for consumers, matching consumer definitions will also be discovered.
public class SubmitOrderConsumerDefinition :
ConsumerDefinition<SubmitOrderConsumer>
{
protected override void ConfigureConsumer(IReceiveEndpointConfigurator endpointConfigurator,
IConsumerConfigurator<SubmitOrderConsumer> consumerConfigurator)
{
endpointConfigurator.DiscardFaultedMessage();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.