Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: ......

在启动RabbitMQ消费端的时候报错:Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=406, reply-text=PRECONDITION_FAILED - inequivalent arg 'type' for exchange 'messageChange' in vhost '/': received 'fanout' but current is 'direct', class-id=40, method-id=10)

F:jdk1.8.0_151injava.exe "-javaagent:E:IntelliJ IDEA 2019.2.1libidea_rt.jar=58077:E:IntelliJ IDEA 2019.2.1in" -Dfile.encoding=UTF-8 -classpath F:jdk1.8.0_151jrelibcharsets.jar;F:jdk1.8.0_151jrelibdeploy.jar;F:jdk1.8.0_151jrelibextaccess-bridge-64.jar;F:jdk1.8.0_151jrelibextcldrdata.jar;F:jdk1.8.0_151jrelibextdnsns.jar;F:jdk1.8.0_151jrelibextjaccess.jar;F:jdk1.8.0_151jrelibextjfxrt.jar;F:jdk1.8.0_151jrelibextlocaledata.jar;F:jdk1.8.0_151jrelibext
ashorn.jar;F:jdk1.8.0_151jrelibextsunec.jar;F:jdk1.8.0_151jrelibextsunjce_provider.jar;F:jdk1.8.0_151jrelibextsunmscapi.jar;F:jdk1.8.0_151jrelibextsunpkcs11.jar;F:jdk1.8.0_151jrelibextzipfs.jar;F:jdk1.8.0_151jrelibjavaws.jar;F:jdk1.8.0_151jrelibjce.jar;F:jdk1.8.0_151jrelibjfr.jar;F:jdk1.8.0_151jrelibjfxswt.jar;F:jdk1.8.0_151jrelibjsse.jar;F:jdk1.8.0_151jrelibmanagement-agent.jar;F:jdk1.8.0_151jrelibplugin.jar;F:jdk1.8.0_151jrelib
esources.jar;F:jdk1.8.0_151jrelib
t.jar;F:workspace
abbitmqDemo
abbitmqConsumer02	arget	est-classes;F:
epository_sshorgspringframeworkootspring-boot-starter-logging2.1.0.RELEASEspring-boot-starter-logging-2.1.0.RELEASE.jar;F:
epository_sshchqoslogbacklogback-classic1.2.3logback-classic-1.2.3.jar;F:
epository_sshchqoslogbacklogback-core1.2.3logback-core-1.2.3.jar;F:
epository_sshorgapachelogginglog4jlog4j-to-slf4j2.11.1log4j-to-slf4j-2.11.1.jar;F:
epository_sshorgapachelogginglog4jlog4j-api2.11.1log4j-api-2.11.1.jar;F:
epository_sshorgslf4jjul-to-slf4j1.7.25jul-to-slf4j-1.7.25.jar;F:
epository_sshcom
abbitmqamqp-client5.7.0amqp-client-5.7.0.jar;F:
epository_sshorgslf4jslf4j-api1.7.26slf4j-api-1.7.26.jar xyfer.Consumer02
java.io.IOException
    at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:129)
    at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:125)
    at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:147)
    at com.rabbitmq.client.impl.ChannelN.exchangeDeclare(ChannelN.java:783)
    at com.rabbitmq.client.impl.recovery.AutorecoveringChannel.exchangeDeclare(AutorecoveringChannel.java:242)
    at com.rabbitmq.client.impl.recovery.AutorecoveringChannel.exchangeDeclare(AutorecoveringChannel.java:232)
    at com.rabbitmq.client.impl.recovery.AutorecoveringChannel.exchangeDeclare(AutorecoveringChannel.java:212)
    at com.rabbitmq.client.impl.recovery.AutorecoveringChannel.exchangeDeclare(AutorecoveringChannel.java:217)
    at xyfer.Consumer02.main(Consumer02.java:28)
Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=406, reply-text=PRECONDITION_FAILED - inequivalent arg 'type' for exchange 'messageChange' in vhost '/': received 'fanout' but current is 'direct', 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:502)
    at com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQChannel.java:293)
    at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:141)
    ... 6 more
Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=406, reply-text=PRECONDITION_FAILED - inequivalent arg 'type' for exchange 'messageChange' in vhost '/': received 'fanout' but current is 'direct', class-id=40, method-id=10)
    at com.rabbitmq.client.impl.ChannelN.asyncShutdown(ChannelN.java:522)
    at com.rabbitmq.client.impl.ChannelN.processAsync(ChannelN.java:346)
    at com.rabbitmq.client.impl.AMQChannel.handleCompleteInboundCommand(AMQChannel.java:182)
    at com.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:114)
    at com.rabbitmq.client.impl.AMQConnection.readFrame(AMQConnection.java:672)
    at com.rabbitmq.client.impl.AMQConnection.access$300(AMQConnection.java:48)
    at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:599)
    at java.lang.Thread.run(Thread.java:748)

仔细看一下报错信息:Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=406, reply-text=PRECONDITION_FAILED - inequivalent arg 'type' for exchange 'messageChange' in vhost '/': received 'fanout' but current is 'direct', class-id=40, method-id=10)

大概意思是交换机的类型不匹配,消费端应该收到名称为“messageChange”,类型为“fanout”的交换机发送的消息,但是当前RabbitMQ中存在的名称为“messageChange”的交换机的类型却是“direct”,所以交换机的类型不匹配。

打开RabbitMQ可以看到确实是这样:

目前有两种解决方式:

一、更改消费端代码中声明的交换机名称即可;

二,把RabbitMQ中的同名却不同类型的交换机删除即可;(测试环境下)

原文地址:https://www.cnblogs.com/qingmuchuanqi48/p/14159452.html