当代理连接丢失时,RabbitMQ 抛出 AlreadyClosedException 而不是 IOException
我正在使用rabbitmq java客户端2.4.1最新版本。
TCP 连接丢失后,仍然调用通道上的方法 这个连接,将会抛出AlreadyClosedException。
这是一个错误吗?我预计会出现 IOException,但 AlreadyClosedException 我 得到了,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.
}
谢谢。
I'm using rabbitmq java client 2.4.1 the newest version.
After a TCP connection lost, and still call a method on a channel over
this connection, a AlreadyClosedException will be thrown.
Is it a bug? I expected an IOException, but AlreadyClosedException I
got, and AlreadyClosedException is a RuntimeException.
If not, why all other errors cause an 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.
}
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的客户端丢失与代理的 TCP 连接,则该连接被视为“关闭”。因此,客户端库抛出
AlreadyClosedException
是适当的(而不是错误)。换句话说,无论连接如何关闭(通过正常方式或通过意外失败),连接都被视为“关闭”。
If your client loses the TCP connection to your broker, the connection is considered "closed". Therefore it is appropriate (and not a bug) for the client library to throw an
AlreadyClosedException
.In other words, a connection is considered "closed" no matter how it got closed (either through a graceful manner or through an unexpected failure).