After upgrading to MassTransit 8.1, I got a list of warnings. In this post I'll walk you through the list of warnings and how I fixed them. Let's get started...
ConsumerDefinition warning
The first warning I got was the following:
'ConsumerDefinition<T>.ConfigureConsumer(IReceiveEndpointConfigurator, IConsumerConfigurator<T>)' is obsolete: 'Use the IRegistrationContext overload instead. Visit https://masstransit.io/obsolete for details.'
That is an easy one to fix, I had to rewrite my original ConsumerDefinition:
public class BaseConsumerDefinition<T> : ConsumerDefinition<T> where T : class, MassTransit.IConsumer | |
{ | |
protected override void ConfigureConsumer(IReceiveEndpointConfigurator endpointConfigurator, IConsumerConfigurator<T> consumerConfigurator) | |
{ | |
consumerConfigurator.UseFilter(new ReadUserHeaderFilter<T>()); | |
base.ConfigureConsumer(endpointConfigurator, consumerConfigurator); | |
} | |
} |
To a version that uses the IRegistrationContext as one of the parameters:
public class BaseConsumerDefinition<T> : ConsumerDefinition<T> where T : class, MassTransit.IConsumer | |
{ | |
protected override void ConfigureConsumer(IReceiveEndpointConfigurator endpointConfigurator, IConsumerConfigurator<T> consumerConfigurator, IRegistrationContext registrationContext) | |
{ | |
consumerConfigurator.UseFilter(new ReadUserHeaderFilter<T>()); | |
base.ConfigureConsumer(endpointConfigurator, consumerConfigurator,registrationContext); | |
} | |
} |
InMemory Outbox warning
A second warning was related to the usage of the InMemoryOutbox:
'InMemoryOutboxConfigurationExtensions.UseInMemoryOutbox(IConsumePipeConfigurator, Action<IOutboxConfigurator>)' is obsolete: 'Use the IRegistrationContext overload instead. Visit https://masstransit.io/obsolete for details.'
Here is the original consumerdefinition that caused the warning:
public class ShopOrderConsumerDefinition : ConsumerDefinition<ShopOrderConsumer> | |
{ | |
public ShopOrderConsumerDefinition() | |
{ | |
// limit the number of messages consumed concurrently | |
// this applies to the consumer only, not the endpoint | |
ConcurrentMessageLimit = 4; | |
} | |
protected override void ConfigureConsumer(IReceiveEndpointConfigurator endpointConfigurator, | |
IConsumerConfigurator<ShopOrderConsumer> consumerConfigurator) | |
{ | |
endpointConfigurator.UseMessageRetry(r => r.Interval(5, 1000)); | |
endpointConfigurator.UseInMemoryOutbox(); | |
} | |
} |
And here is the updated code:
public class ShopOrderConsumerDefinition : ConsumerDefinition<ShopOrderConsumer> | |
{ | |
public ShopOrderConsumerDefinition() | |
{ | |
// limit the number of messages consumed concurrently | |
// this applies to the consumer only, not the endpoint | |
ConcurrentMessageLimit = 4; | |
} | |
protected override void ConfigureConsumer(IReceiveEndpointConfigurator endpointConfigurator, | |
IConsumerConfigurator<ShopOrderConsumer> consumerConfigurator, IRegistrationContext registrationContext) | |
{ | |
endpointConfigurator.UseMessageRetry(r => r.Interval(5, 1000)); | |
endpointConfigurator.UseInMemoryOutbox(registrationContext); | |
} | |
} |
Job Consumers warning
A last warning was related to the Job consumers configuration:
'RegistrationContextExtensions.ConfigureEndpoints<T>(IServiceInstanceConfigurator<T>, IBusRegistrationContext, IEndpointNameFormatter)' is obsolete: 'Job Consumers no longer require a service instance. Visit https://masstransit.io/obsolete for details.'
My original configuration looked like this:
services.AddMassTransit(x => | |
{ | |
x.UsingRabbitMq((context, cfg) => | |
{ | |
cfg.ServiceInstance(instance => | |
{ | |
instance.ConfigureJobServiceEndpoints(); | |
instance.ConfigureEndpoints(context); | |
}); | |
}); | |
}); |
Now I can remove the ConfigureJobServiceEndpoints line:
services.AddMassTransit(x => | |
{ | |
x.UsingRabbitMq((context, cfg) => | |
{ | |
cfg.ServiceInstance(instance => | |
{ | |
instance.ConfigureEndpoints(context); | |
}); | |
}); | |
}); |