MassTransit - Middleware, Pipes and Filters
Why Stack Overflow recommends it
Stack Overflow users link it when they need to write MassTransit filters or understand how scopes and service providers are created along the pipeline.
Recommended by 2 people across 3 different months, 2020 to 2021.
What it is
A one-hour episode from MassTransit author Chris Patterson on writing middleware filters for the consume, send and publish pipes, plus the standard receive pipeline. It builds on the Trashlantis sample app to show how to add filters to the pipeline and resolve components from container providers.
What people said
Recommends Chris Patterson · 2020-06 · Stack Overflow · on “MassTransit v6 UseSendFilter”
They should be in the same scope, yes. The scope should be created at the first point in the pipeline where a scope is required, which in your case might be the filter. There is a video on middleware that covers how previous scopes were created on [this video] .
Recommends Adem Catamak · 2020-07 · Stack Overflow · on “putting Filter and Consumer in the same scope (MassTransit)”
Startup services.AddMassTransitHostedService(); services.AddMassTransit(x => { x.AddConsumer<OrderStateOrchestrator>( configurator => configurator .UseFilter(new CustomTransactionFilter<OrderStateOrchestrator>()) ) .Endpoint(configurator => { configurator.Name = $"{Program.STARTUP_PROJECT_NAME}.{nameof(OrderStateOrchestrator)}"; }); x.UsingRabbitMq((context, cfg) => { cfg.Host(massTransitOption.HostName, massTransitOption.VirtualHost, hst => { hst.Username(massTransitOption.UserName); hst.Password(massTransitOption.Password); }); cfg.ConfigureEndpoints(context); }); }); Filter public class CustomTransactionFilter<TConsumer> : IFilter<ConsumerConsumeContext<TConsumer>> where TConsumer : class
Recommends Chris Patterson · 2021-04 · Stack Overflow · on “MassTransit: Generic Consume Filters independent for each consumer”
If you have consumer specific filters, you have several options. You can create a filter that is either: Specific to a message type ConsumeContext<TMessage> Specific to a consumer type ConsumerConsumeContext<TConsumer> Specific to a consumer and message type ConsumerConsumeContext<TConsumer, TMessage> In the message-specific case, you can configure that on the receive endpoint. In this case, the filter executes before the consumer. In the consumer-specific cases, you can configure those on the consumer configurator (the second argument to Configure , in the ConsumerDefinition ). These would be invoked after the consumer has been created, but prior to dispatching the message to the Consume me
Cites benjamin · 2021-11 · Stack Overflow · on “MassTransit middleware - Getting instance of IServiceProvider”
I'm trying to create some FluentValidation middleware for my MassTransit pipeline. I thought it would be a suitably easy project for my first ever MassTransit middleware, but I'm afraid I've got in over my head. Can somebody rescue me please? Other than the MassTransit middleware documentation [LINK] I have been referring to this video [this video] for guidance: Here's my filter: public class FluentValidationFilter<TMessage> : IFilter<ConsumeContext<TMessage>> where TMessage : class { public void Probe(ProbeContext context) { context.CreateScope(nameof(FluentValidationFilter<TMessage>)); } public async Task Send( ConsumeContext<TMessage> context, IPipe<ConsumeContext<TMessage>> next) { var servic