4
votes

I have a RabbitMQ queue that was originally declared like this:

var result = _channel.QueueDeclare("NewQueue", true, false, false, null);

And I'm trying to add a dead letter exchange, so I've changed the code to this:

_channel.ExchangeDeclare("dl.exchange", "direct");
Dictionary<string, object> args = new Dictionary<string, object>()
{
    { "x-dead-letter-exchange", "dl.exchange" }
};            

var result = _channel.QueueDeclare("NewQueue", true, false, false, args);

When I run this, I get the error:

Exception thrown: 'RabbitMQ.Client.Exceptions.OperationInterruptedException' in RabbitMQ.Client.dll

Additional information: The AMQP operation was interrupted: AMQP close-reason, initiated by Peer, code=406, text="PRECONDITION_FAILED - inequivalent arg 'x-dead-letter-exchange' for queue 'NewQueue' in vhost '/': received the value 'dl.exchange' of type 'longstr' but current is none", classId=50, methodId=10, cause=

The error seems pretty self explanatory, and if I delete the queue, when I re-create it, I don't get the error, but my question is: is there a way to make this change without deleting the queue?

1

1 Answers

6
votes

No, by default you have to delete the queue and recreate it.

but you can use the policy:

rabbitmqctl set_policy DLX "NewQueue" '{"dead-letter-exchange":"my-dlx"}' --apply-to queues

In this way you can add or remove queue args without delete it.

Read here for more detail.

Configuration using policy

To specify a DLX using policy, add the key "dead-letter-exchange" to a policy definition. Similarly, an explicit routing key can be specified by adding the key "dead-letter-routing-key" to the policy.

Policies can also be defined using the management plugin, see the policy documentation for more details.