每一秒钟的时间都值得铭记

0%

RabbitMQ爆出com.rabbitmq.client.ShutdownSignalException异常及解决办法

RabbitMQ爆出com.rabbitmq.client.ShutdownSignalException异常。

异常具体信息如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Exception in thread "main" java.io.IOException
at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:126)
at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:122)
at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:144)
at com.rabbitmq.client.impl.ChannelN.exchangeDeclare(ChannelN.java:762)
at com.rabbitmq.client.impl.recovery.AutorecoveringChannel.exchangeDeclare(AutorecoveringChannel.java:237)
at com.rabbitmq.client.impl.recovery.AutorecoveringChannel.exchangeDeclare(AutorecoveringChannel.java:227)
at com.rabbitmq.client.impl.recovery.AutorecoveringChannel.exchangeDeclare(AutorecoveringChannel.java:207)
at com.rabbitmq.client.impl.recovery.AutorecoveringChannel.exchangeDeclare(AutorecoveringChannel.java:212)
at com.amqp.fanout.Send.main(Send.java:22)
Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=406, reply-text=PRECONDITION_FAILED - inequivalent arg 'durable' for exchange 'amq.fanout' in vhost '/mymq': received 'false' but current is 'true', class-id=40, method-id=10)
at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:66)
at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:36)
at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:494)
at com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQChannel.java:288)
at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:138)
... 6 more

通过异常我们可以发现以下几点:

  • 异常出现在代码的第22行。
  • 异常原因是因为在/mymq虚拟主机下的amq.fanout交换机是持久化的,但是代码在声明交换机的时候,并没有声明该交换机的持久化属性。
    在这里插入图片描述
    在这里插入图片描述

通过源码我们可以发现,通过声明交换机有重载方法:

1
Exchange.DeclareOk exchangeDeclare(String exchange, BuiltinExchangeType type) throws IOException;
1
Exchange.DeclareOk exchangeDeclare(String exchange, BuiltinExchangeType type, boolean durable) throws IOException;

其中第二个重载方法比第一个重载方法多出了一个持久化的boolean属性,所以该异常的解决方法就是增加该参数,并且参数属性为true
在这里插入图片描述

坚持原创技术分享,您的支持将鼓励我继续创作!
-------------这是我的底线^_^-------------