How do I set different concurrency limits using Autofac and multiple consumers?

86 views
Skip to first unread message

Adam Schaible

unread,
Jan 20, 2017, 1:27:59 PM1/20/17
to masstransit-discuss
Hello!

Any help would be appreciated ... I found the AutofacConsumerFactory but I'm not sure how that should be used in the cleanest way.

Let's say I use LoadFromContext() and then want to adjust the concurrency limit of a single consumer - is that possible?

If not, what would be the best way to register consumers individually using Autofac?

Thanks!

Chris Patterson

unread,
Jan 20, 2017, 1:43:48 PM1/20/17
to masstrans...@googlegroups.com
Concurrency is configured before the consumer, so it shouldn't matter. If you're loading from the container, and using the Autofac assembly, just do the following:

containerBuilder.RegisterType<MyConsumer>();

var container = containerBuilder.Build();

cfg.ReceiveEndpoint("input-queue", x =>
{
    x.UseConcurrencyLimit(1);
    x.UseConsumer<MyConsumer>(container);
});

By passing the container, it will automatically configure the AutofacConsumerFactory<MyConsumer>() for you.


--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsub...@googlegroups.com.
To post to this group, send email to masstransit-discuss@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/masstransit-discuss/8ebef314-b573-49a2-884d-3d0a12999720%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Adam Schaible

unread,
Jan 20, 2017, 2:06:06 PM1/20/17
to masstransit-discuss
OK This is helpful, thanks a lot!  Is there a way to do this with builder instead of container?

Thanks,
-Adam


On Friday, January 20, 2017 at 1:43:48 PM UTC-5, Chris Patterson wrote:
Concurrency is configured before the consumer, so it shouldn't matter. If you're loading from the container, and using the Autofac assembly, just do the following:

containerBuilder.RegisterType<MyConsumer>();

var container = containerBuilder.Build();

cfg.ReceiveEndpoint("input-queue", x =>
{
    x.UseConcurrencyLimit(1);
    x.UseConsumer<MyConsumer>(container);
});

By passing the container, it will automatically configure the AutofacConsumerFactory<MyConsumer>() for you.

On Fri, Jan 20, 2017 at 10:27 AM, Adam Schaible <adam.s...@gmail.com> wrote:
Hello!

Any help would be appreciated ... I found the AutofacConsumerFactory but I'm not sure how that should be used in the cleanest way.

Let's say I use LoadFromContext() and then want to adjust the concurrency limit of a single consumer - is that possible?

If not, what would be the best way to register consumers individually using Autofac?

Thanks!

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsub...@googlegroups.com.
To post to this group, send email to masstrans...@googlegroups.com.

Shadow Fox

unread,
Jan 20, 2017, 3:06:30 PM1/20/17
to masstransit-discuss
This is kinda what you're talking about right?

using GreenPipes;
...

builder
.RegisterType<ProcessFileMessageHandler>().AsSelf();

builder
.Register(c => Bus.Factory.CreateUsingRabbitMq(sbc =>
{
   
var host = //host configuration
    sbc
.ReceiveEndpoint(host, "queueName", ep =>
   
{
        ep
.UseConcurrencyLimit(1); //Syntactically OK, but not sure if it will work
        ep
.LoadFrom(c);
   
});
}


Elsewhere in the same assembly, I have created consumers by implementing IConsumer<MyPayloadType>.

The thing is, I'm not sure this is really what you're looking for.

Not using the UseConcurrencyLimit above, an option to kind of hack the framework could be using some sort of wait handle/signaler/whatever inside your consumer to control how many hands (threads) are in that cookie jar (consumer code). If you don't issue an await inside your Consume(ConsumeContext<T> context) method [Doing something like await Task.Yield();], MT will dole worker threads out one at a time. Perhaps you can use this to your advantage?

Adam Schaible

unread,
Jan 20, 2017, 3:43:23 PM1/20/17
to masstransit-discuss
Thanks for the reply!

I understand that level of concurrency limiting -- however in my case I have other consumers attached to the same queue that I do not wish to limit.

So for Consumer 1, I would like to have a concurrency limit of 1.  For consumer 2, 3, and 4 I'd like to have unrestricted concurrency.

Thanks!

 
Reply all
Reply to author
Forward
0 new messages