I upgraded to MassTransit 5.2.0 and existing code is complaining LoadFrom is now obsolete.

Viewed 968

The warning does suggest reading the documentation but the current documentation recommends using LoadFrom when configuring a consumer that requires DI support. Currently using .net Core Dependency Injection. Can't find a Consumer method that allows DI.

This continues to work. Just makes me nervous going forward.

cfg.ReceiveEndpoint(host, "adjudication-api", e => 
{
   e.PrefetchCount = 16;

   e.UseMessageRetry(x => x.Interval(2, 100));

   e.LoadFrom(provider);

 });

Guidance would be appreciated.

1 Answers

While the use of LoadFrom is still supported, it's discouraged because it actually promotes a very bad practice, putting all of your eggs in one basket. Too often I've come across developers who have dozens of consumers on a single queue, all of them unrelated. It's important to spread consumers across multiple queues to avoid bottlenecks, separate traffic on the broker, and get better visibility into the system.

Instead of using LoadFrom, consider the following approach instead:

cfg.ReceiveEndpoint(host, "adjudication-api", e => 
{
   e.PrefetchCount = 16;

   e.UseMessageRetry(x => x.Interval(2, 100));

   e.Consumer<AdjudicationConsumer>(provider);
 });

Then, if you have another consumer that handles reimbursement, create a separate endpoint for it:

cfg.ReceiveEndpoint(host, "reimbursement-api", e => 
{
   e.PrefetchCount = 16;

   e.UseMessageRetry(x => x.Interval(2, 100));

   e.Consumer<ReimbursementConsumer>(provider);
 });

Using this approach, consumers are spread out across multiple queues (receive endpoints).

Related