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

张博强 boqiang.zhang at gmail.com
Thu Apr 28 08:57:57 BST 2011


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.


More information about the rabbitmq-discuss mailing list