com.rabbitmq.client.AlreadyClosedException:由于连接错误,连接已经关闭

时间:2019-11-20 05:55:41

标签: rabbitmq

rabbitMQ:3.7.18

Erlang:22.1

错误消息:

ERROR com.rabbitmq.client.impl.ForgivingExceptionHandler:119 - Consumer com.snsprj.sbsm.mq.rabbitmq.MyConsumer@77fba29d (amq.ctag-Z9h3gT_bM7HibebpYsw6Hg) method handleDelivery for channel AMQChannel(amqp://guest@192.168.1.189:5672/,1) threw an exception for channel AMQChannel(amqp://guest@192.168.1.189:5672/,1)
com.rabbitmq.client.AlreadyClosedException: connection is already closed due to connection error; cause: java.net.SocketException: Connection reset by peer: socket write error
    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:93)
    at com.rabbitmq.client.impl.recovery.AutorecoveringChannel.basicAck(AutorecoveringChannel.java:436)
    at com.snsprj.sbsm.mq.rabbitmq.MyConsumer.handleDelivery(MyConsumer.java:46)
    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)

我的消费者代码:

public class MqConsumer {

        ...

        channel.queueDeclare(QUEUE_NAME_TEST, MqConstant.DURABLE_FALSE, false, MqConstant.AUTO_DELETE_FALSE,null);

        channel.basicConsume(QUEUE_NAME_TEST, false, new MyConsumer(channel));
}

public class MyConsumer extends DefaultConsumer {

    ...

    @Override
    public void handleDelivery(String consumerTag, Envelope envelope, BasicProperties properties, byte[] body)throws IOException {

        String msg = new String(body, StandardCharsets.UTF_8);

        ...
        Thread.sleep(10000L);

        channel.basicAck(envelope.getDeliveryTag(), false);
    }
}

消费者线程.sleep(10000),然后发生错误。仅发出32条消息。 有什么问题吗?

0 个答案:

没有答案