MassTransit: UseConsumeFilter throws nullreference exception on startup if I have batch consumers
MassTransit config
Batch Consumer:
Program runs when I comment out the
services.AddMassTransit(config =>
{
config.AddConsumers(typeof(MyNonBatchConsumer).Assembly);
config.UsingAmazonSqs((context, cfg) =>
{
cfg.UsePublishFilter(typeof(LoggingPublishFilter<>), provider);
cfg.UseConsumeFilter(typeof(LoggingConsumeFilter<>), provider);
cfg.ReceiveEndpoint($"{typeof(Startup).Namespace?.Replace(".", "_")}_{environment.EnvironmentName}", receiveEndpointConfig =>
{
//tried registering the filter here as well, didn't work
receiveEndpointConfig.ConfigureConsumer<MyNonBatchConsumer>(context);
//Batch consumer
receiveEndpointConfig.ConfigureConsumer<MyBatchConsumer>(context);
});
}));
});
services.AddScoped(typeof(LoggingPublishFilter<>));
services.AddScoped(typeof(LoggingConsumeFilter<>));services.AddMassTransit(config =>
{
config.AddConsumers(typeof(MyNonBatchConsumer).Assembly);
config.UsingAmazonSqs((context, cfg) =>
{
cfg.UsePublishFilter(typeof(LoggingPublishFilter<>), provider);
cfg.UseConsumeFilter(typeof(LoggingConsumeFilter<>), provider);
cfg.ReceiveEndpoint($"{typeof(Startup).Namespace?.Replace(".", "_")}_{environment.EnvironmentName}", receiveEndpointConfig =>
{
//tried registering the filter here as well, didn't work
receiveEndpointConfig.ConfigureConsumer<MyNonBatchConsumer>(context);
//Batch consumer
receiveEndpointConfig.ConfigureConsumer<MyBatchConsumer>(context);
});
}));
});
services.AddScoped(typeof(LoggingPublishFilter<>));
services.AddScoped(typeof(LoggingConsumeFilter<>));Batch Consumer:
csharp
public class MyBatchConsumerHandler :
IIntegrationEventBatchHandler<MyBatchConsumer>
{
private readonly IMediator _mediator;
public MyBatchConsumerHandler(IMediator mediator)
{
_mediator = mediator;
}
public async Task Consume(ConsumeContext<Batch<MyBatchConsumer>> context)
{
//removed for brevity
}
}csharp
public class MyBatchConsumerHandler :
IIntegrationEventBatchHandler<MyBatchConsumer>
{
private readonly IMediator _mediator;
public MyBatchConsumerHandler(IMediator mediator)
{
_mediator = mediator;
}
public async Task Consume(ConsumeContext<Batch<MyBatchConsumer>> context)
{
//removed for brevity
}
}Program runs when I comment out the
receiveEndpointConfig.ConfigureConsumer<MyBatchConsumer>(context);receiveEndpointConfig.ConfigureConsumer<MyBatchConsumer>(context);. I need filters for logging purposes. Has anyone else ran into this issue?