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

Ann Witbrock awitbrock at vmware.com
Thu Apr 28 13:11:32 BST 2011


Having looked at the API docs, you might also expect to find a ShutdownSignalException.

Ann Witbrock
awitbrock at vmware.com
________________________________________
From: rabbitmq-discuss-bounces at lists.rabbitmq.com [rabbitmq-discuss-bounces at lists.rabbitmq.com] On Behalf Of Ann Witbrock [awitbrock at vmware.com]
Sent: 28 April 2011 11:52
To: rabbitmq-discuss at lists.rabbitmq.com
Subject: [rabbitmq-discuss]  it throws AlreadyClosedException, not IOException.

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.

      @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.
_______________________________________________
rabbitmq-discuss mailing list
rabbitmq-discuss at lists.rabbitmq.com
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
_______________________________________________
rabbitmq-discuss mailing list
rabbitmq-discuss at lists.rabbitmq.com
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss


More information about the rabbitmq-discuss mailing list