2
我正在使用rabbitmq java客戶端2.4.1最新版本。當代理連接丟失時,RabbitMQ拋出AlreadyClosedException而非IOException
TCP連接丟失後,仍然通過 此連接調用通道上的方法時,將拋出AlreadyClosedException。
這是一個錯誤?我期待一個IOException,但AlreadyClosedException得到了I ,並且AlreadyClosedException是一個RuntimeException。
如果不是,爲什麼所有其他錯誤都會導致IOException。
@Test
public void testConnectionLost() throws IOException{
ConnectionFactory factory = new ConnectionFactory();
factory.setRequestedHeartbeat(60);
factory.setHost("<your rabbitmq host>");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
connection.close();
try {
channel.queueDeclare("queueName", false, false, false, null);
Assert.fail("Exception expected.");
}catch (IOException e) {
//it will NOT reach here.
//Inner exception should be AlreadyClosedException
System.out.println(e);
}catch (AlreadyClosedException e) {
// it will reach here.
System.out.println(e);
//this is strange!
//I expected IOException , but AlreadyClosedException I got.
//And AlreadyClosedException is a RuntimeException.
}
謝謝。