zoukankan      html  css  js  c++  java
  • 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 的截图

  • 相关阅读:
    servlet容器与web容器的概念
    apache点NET环境
    JAVA web选型
    Web服务器排行:Nginx超越Apache 成为全球
    软件介绍(apache lighttpd nginx)
    C++性能榨汁机之虚函数的开销
    C++性能榨汁机之伪共享
    《四重缘起深般若》 和 《心经修正圆通法门》
    冥想方法
    中医方子
  • 原文地址:https://www.cnblogs.com/xiyin/p/8946268.html
Copyright © 2011-2022 走看看