我有一个Java中的RabbitMQ
客户端,它监听传入的通知消息以对其进行处理(RabbitMQ Java客户端版本5.5.1
)。经过几个月的平稳运行,昨天突然出现了此错误,此后未收到任何消息:
[AMQP Connection 10.233.44.138:5672] WARN com.rabbitmq.client.impl.ForgivingExceptionHandler - An unexpected connection driver error occured (Exception message: Connection reset)
此错误的原因是什么?如何解决它再次发生?
ConnectionFactory factory = new ConnectionFactory();
factory.setHost(rabbitMqHost);
factory.setUsername(rabbitMqUser);
factory.setPassword(rabbitMqPass);
factory.setPort(rabbitMqPort);
factory.setVirtualHost("/");
Connection connection = factory.newConnection();
final Channel channel = connection.createChannel();
channel.exchangeDeclare(EXCHANGE_NAME, "fanout");
String queueName = channel.queueDeclare().getQueue();
channel.queueBind(queueName, EXCHANGE_NAME, "");
logger.info("t3- Listening to RabbitMQ notifications...");
channel.basicConsume(queueName, false, new DefaultConsumer(channel) {
@Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,
byte[] body) throws IOException {
// (process the message components here ...)
final String message = new String(body, "UTF-8");
try {
Thread.sleep(500);
} catch (InterruptedException e) {
}
ParseStatusMessage(message);
}
});
}