• Solution for unable to create "dead-letter-exchange" in RabbitMQ


    在参考 Dead-Letter-Exchange 进行Dead-letter-exchange的理解,

    在本地时,想要创建 Dead-letter-exchange 时,一直报错,错误如下:

    Unhandled Exception: RabbitMQ.Client.Exceptions.OperationInterruptedException: The AMQP operation was interrupted: AMQP close-reason, initiated by Peer, code=406, text="PRECONDITION_FAILED - inequivalent arg 'x-dead-letter-exchange' for queue 'q_test' in vhost '/': received the value 'q-dead-letter-exchange' of type 'longstr' but current is none", classId=50, methodId=10, cause=
       at RabbitMQ.Client.Impl.SimpleBlockingRpcContinuation.GetReply(TimeSpan timeout)
       at RabbitMQ.Client.Impl.ModelBase.QueueDeclare(String queue, Boolean passive, Boolean durable, Boolean exclusive, Boolean autoDelete, IDictionary`2 arguments)
       at RabbitMQ.Client.Impl.AutorecoveringModel.QueueDeclare(String queue, Boolean durable, Boolean exclusive, Boolean autoDelete, IDictionary`2 arguments)
       at CNBlogs.Question.EventBusRabbitMQ.EventBusRabbitMQ.CreateConsumerChannel()
    

    去官网查了查,姿势也正确,先声明一个Exchange

    channel.ExchangeDeclare("q-dead-letter-exchange", type: "direct");
    

    然后再指定 x-dead-letter-exchange 参数

    var args = new Dictionary<string, object>()
                {
                    {"x-dead-letter-exchange", "q-dead-letter-exchange"}
                };
    

    最后放到队列声明里面:

     channel.QueueDeclare(queue: _queueName,
                                     durable: true,
                                     exclusive: false,
                                     autoDelete: false,
                                     arguments: args);
    
    

    然而,每次一运行就报上面那个错误,最后子啊Github上找到了答案

    原因可能是我原来的队列中,因为有尚未确认的消息在。然后,把RabbitMQ 中的Queue 和Exchange 删除,重新运行程序就成功了。下面是Queue和Exchange 的截图

  • 相关阅读:
    C#中怎么设置comboBox1为只读,即不可在里面进行编辑?
    笔记
    Head First ObjectOriented Analysis & Design 读书 概记
    看到这篇东西 ,要收藏 呵呵
    HELLO OPENGL
    调试opengl程序出错
    HeadFirst C# 读书笔记 0426
    css布局容易范的一些错误
    百度新年贪吃蛇效果
    css3教程:boxsizing属性说明
  • 原文地址:https://www.cnblogs.com/xiyin/p/8946268.html
Copyright © 2020-2023  润新知