Search code examples
c#amazon-sqsamazon-snsmasstransit

ConcurrentMessageLimit in MassTransit ConsumerDefinition


I'm using ConsumerDefinition to define my consumer in MassTransit.

I've noticed there that it's possible to set ConcurrentMessageLimit 3 different ways, but I don't really understand the difference. Could you please advise where it's better to set it ?

Here's below is my code

public class MyConsumerDefinition: ConsumerDefinition<MyConsumer>
{
    protected override void ConfigureConsumer(IReceiveEndpointConfigurator endpointConfigurator, IConsumerConfigurator<MyConsumer> consumerConfigurator, IRegistrationContext context)
    {
        // 1
        ConcurrentMessageLimit = 20;

        // 2
        endpointConfigurator.ConcurrentMessageLimit = 20;

        // 3
        consumerConfigurator.ConcurrentMessageLimit = 20;
    }
}

Thanks, Evgeny.


Solution

    1. Should be set ONLY in the constructor, it has zero value at the point where that method is called.

    2. That's fine, as long as you only have a single consumer on the endpoint otherwise multiple consumers might set it to different values.

    3. Meh, I never use this but you could. I wouldn't, but then again I don't share a single endpoint with multiple consumers.