gpt4 book ai didi

c# - 更改 RabbitMQ 队列中的参数

转载 作者:行者123 更新时间:2023-12-04 12:12:15 25 4
gpt4 key购买 nike

我有一个 RabbitMQ 队列,它最初是这样声明的:

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

我正在尝试添加死信交换,所以我将代码更改为:
_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);

当我运行这个时,我收到错误:

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=



该错误似乎不言自明,如果我删除队列,当我重新创建它时,我不会收到错误消息,但我的问题是:有没有办法在不删除队列的情况下进行此更改?

最佳答案

不,默认情况下您必须删除队列并重新创建它。

但您可以使用该政策:

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

通过这种方式,您可以添加或删除队列 args不删除它。

Read here了解更多详情。

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.

关于c# - 更改 RabbitMQ 队列中的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40146740/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com