[rabbitmq-discuss] it throws AlreadyClosedException, not IOException.

Ann Witbrock awitbrock at vmware.com
Thu Apr 28 11:52:53 BST 2011

Closing the connection will also close the channel it created using connection.createChannel().
Therefore, calling a channel method after the connection is closed, should also find the channel closed, or closing. 
This should raise an AlreadyClosedException, as you discovered, allowing you to know the connection and channel are absent, rather than performing unexpectedly.

Ann Witbrock
awitbrock at vmware.com
From: rabbitmq-discuss-bounces at lists.rabbitmq.com [rabbitmq-discuss-bounces at lists.rabbitmq.com] On Behalf Of 张博强 [boqiang.zhang at gmail.com]
Sent: 28 April 2011 08:57
To: rabbitmq-discuss at lists.rabbitmq.com
Subject: [rabbitmq-discuss] it throws AlreadyClosedException,   not IOException.

I'm using rabbitmq java client 2.4.1

After a TCP connection lost, and still call a method on a channel over
this connection, a AlreadyClosedException will be thrown.

it is a bug? I expected an IOException,  but AlreadyClosedException I
got, and AlreadyClosedException is a RuntimeException.

if not, why all other errors cause an IOException.

      public void testConnectionLost() throws IOException{
                ConnectionFactory factory = new ConnectionFactory();
                factory.setHost("<your rabbitmq host>");

                Connection connection = factory.newConnection();
                Channel channel = connection.createChannel();

                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
                }catch (AlreadyClosedException e) {
                        // it will reach here.

                        //this is strange!
                        //I expected IOException , but AlreadyClosedException I got.
                        //And AlreadyClosedException is a RuntimeException.

Thank you.
rabbitmq-discuss mailing list
rabbitmq-discuss at lists.rabbitmq.com

More information about the rabbitmq-discuss mailing list