1

The EndpointName property in a ConsumerDefinition file seems to be ignored by MassTransit. I know the ConsumerDefinition is being used because the retry logic works. How do I get different commands to go to a different queue? It seems that I can get them all to go through one central queue but I don't think this is best practice for commands.

Here is my app configuration that executes on startup when creating the MassTransit bus.

        Bus.Factory.CreateUsingAzureServiceBus(cfg =>
        {
            cfg.Host(_config.ServiceBusUri, host => {
                host.SharedAccessSignature(s =>
                {
                    s.KeyName = _config.KeyName;
                    s.SharedAccessKey = _config.SharedAccessKey;
                    s.TokenTimeToLive = TimeSpan.FromDays(1);
                    s.TokenScope = TokenScope.Namespace;
                });
            });

            cfg.ReceiveEndpoint("publish", ec =>
            {
                // this is done to register all consumers in the assembly and to use their definition files
                ec.ConfigureConsumers(provider);
            });

And my handler definition in the consumer (an azure worker service)

public class CreateAccessPointCommandHandlerDef : ConsumerDefinition<CreateAccessPointCommandHandler>
{
    public CreateAccessPointCommandHandlerDef()
    {
        EndpointName = "specific";
        ConcurrentMessageLimit = 4;
    }

    protected override void ConfigureConsumer(
        IReceiveEndpointConfigurator endpointConfigurator,
        IConsumerConfigurator<CreateAccessPointCommandHandler> consumerConfigurator
    )
    {
        endpointConfigurator.UseMessageRetry(r =>
        {
            r.Immediate(2);
        });
    }
}

In my app that is sending the message I have to configure it to send to the "publish" queue, not "specific".

EndpointConvention.Map<CreateAccessPointsCommand>(new Uri($"queue:specific")); // does not work
EndpointConvention.Map<CreateAccessPointsCommand>(new Uri($"queue:publish")); // this does work
1
  • Ryan, what is 'provider' in this line 'ec.ConfigureConsumers(provider);'? Thanks Commented Oct 28, 2022 at 9:23

1 Answer 1

4

Because you are configuring the receive endpoint yourself, and giving it the name publish, that's the receive endpoint.

To configure the endpoints using the definitions, use:

cfg.ConfigureEndpoints(provider);

This will use the definitions that were registered in the container to configure the receive endpoints, using the consumer endpoint name defined.

This is also explained in the documentation.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Chris! Does this also eliminate the need to call EndpointConvention.Map<T> in the publisher? ... I guess it wouldn't because the publisher has no way to know the consumers. Nevermind.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.