今天部署环境RabbitMQ报了这么一个错误:
com.rabbitmq.client.AlreadyClosedException: channel is already closed due to clean channel shutdown; protocol method: #method<channel.close>(reply-code=200, reply-text=Closed due to exception from Consumer (amq.ctag-WI4aPw6N3v3BoIKrEXKmDg) method handleDelivery for channel AMQChannel(amqp://[email protected]:5999/v3,1), class-id=0, method-id=0)
at com.rabbitmq.client.impl.AMQChannel.ensureIsOpen(AMQChannel.java:253)
at com.rabbitmq.client.impl.AMQChannel.transmit(AMQChannel.java:422)
at com.rabbitmq.client.impl.AMQChannel.transmit(AMQChannel.java:416)
at com.rabbitmq.client.impl.recovery.RecoveryAwareChannelN.basicAck(RecoveryAwareChannelN.java:89)
at com.rabbitmq.client.impl.recovery.AutorecoveringChannel.basicAck(AutorecoveringChannel.java:436)
at cn.sh.ideal.utils.UsersUtils$1.handleDelivery(UsersUtils.java:126)
at com.rabbitmq.client.impl.ConsumerDispatcher$5.run(ConsumerDispatcher.java:149)
at com.rabbitmq.client.impl.ConsumerWorkService$WorkPoolRunnable.run(ConsumerWorkService.java:104)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
在网上搜了搜方法,有的说是把当使用channel的basicAck方法时,定义了channel的basicConsume方法的第二个参数,autoAck为true。将true改成false,但是试了不能解决我的问题。
然后网上也没有什么办法了,我就翻译了报错信息:
通道已经关闭;协议方法:#Method<Channel.Close>(回-代码=200,答复-text=由于来自消费者的异常而关闭(amq.ctag-WI4aPw6N3v3BoIKrEXKmDg)方法为通道AMQChannel(amqp://[email protected]:5999/v3,1),类-id=0,方法-id=0)
关键:代码由于来自消费者的异常而关闭
我恍然大悟,收到的状态是200,说明接受到消息,但是处理消息时,出现异常,于是连接通道断开了。
于是我就对代码进行了加强,问题解决。