Sending message to queue in SingleActiveConsumer mode in MassTransit

Viewed 367

I have registered receive endpoint in SingleActiveConsumer mode. However I can't find a way to send a message directly to queue by using sendEndpoint. I receive following error:

The AMQP operation was interrupted: AMQP close-reason, initiated by Peer, code=406, text='PRECONDITION_FAILED - inequivalent arg 'x-single-active-consumer' for queue 'test' in vhost '/': received none but current is the value 'true' of type 'bool'', 

I tried setting header "x-single-active-consumer"=true by using bus configurer:

    var bus = Bus.Factory.CreateUsingRabbitMq(cfg =>
        {
            cfg.Host("localhost", "/", h =>
            {
                h.Username("guest");
                h.Password("guest");
            });
            cfg.ConfigureSend(a => a.UseSendExecute(c => c.Headers.Set("x-single-active-consumer", true)));
        });

and directly on sendEndpoint:

        await sendEndpoint.Send(msg, context => {
                context.Headers.Set("x-single-active-consumer", true);
                });
1 Answers

If you want to send directly to a receive endpoint in MassTransit, you can use the short address exchange:test instead, which will send to the exchange without trying to create/bind the queue to the exchange with the same name. That way, you decouple the queue configuration from the message producer.

Or, you could just use Publish, and let the exchange bindings route the message to the receive endpoint queue.

Related