title: RabbitMQ : Connection recovery mechanism
body: <p>I am using rabbit mq 3.4.1 java client library and not able to get the auto recovery mechanism work.</p>
  
  <p>This is how I am creating the rabbit mq connection factory:</p>
  
  <pre><code>factory = new ConnectionFactory();
  factory.setUsername(userName);
  factory.setPassword(password);
  factory.setVirtualHost(virtualHost);
  factory.setAutomaticRecoveryEnabled(true);
  factory.setNetworkRecoveryInterval(5);
  factory.setRequestedHeartbeat(3);
  </code></pre>
  
  <p>After publishing of a message, if I shutdown the rabbit mq broker and bring it up again, I expect the recovery mechanism to kick in and have the connection restored to a 'sane' state. But I get the below error:</p>
  
  <pre><code>com.rabbitmq.client.AlreadyClosedException: connection is already closed due to connection error; protocol method: #method&lt;connection.close&gt;(reply-code=320, reply-text=CONNECTION_FORCED - broker forced connection closure with reason 'shutdown', class-id=0, method-id=0)
      at com.rabbitmq.client.impl.AMQChannel.ensureIsOpen(AMQChannel.java:190) ~[amqp-client-3.4.1.jar:na]
      at com.rabbitmq.client.impl.AMQChannel.transmit(AMQChannel.java:291) ~[amqp-client-3.4.1.jar:na]
      at com.rabbitmq.client.impl.ChannelN.basicPublish(ChannelN.java:654) ~[amqp-client-3.4.1.jar:na]
      at com.rabbitmq.client.impl.ChannelN.basicPublish(ChannelN.java:631) ~[amqp-client-3.4.1.jar:na]
      at com.rabbitmq.client.impl.ChannelN.basicPublish(ChannelN.java:622) ~[amqp-client-3.4.1.jar:na]
  </code></pre>
  
  <p>Am I missing anything here? The only way to work around this problem is to register a ShutDownListener and re-initialize the rabbit mq connection factory, connection, and the channels.</p>
  
  <p>Also to answer </p>
  
  <blockquote>
    <p>"chrislott"</p>
  </blockquote>
  
  <p>comment, I see the auto recovery kicking in to recover. I create a exchange by using a temporary channel:</p>
  
  <pre><code>Channel channel = connection.createChannel();
  channel.exchangeDeclare(exchangeName, exchangeType, durable);
  channel.close();
  </code></pre>
  
  <p>And I see the below exception when its trying to recover the topology:</p>
  
  <pre><code>Caught an exception when recovering topology Caught an exception while recovering exchange testSuccessfulInitVirtualHost_Exchange: channel is already closed due to clean channel shutdown; protocol method: #method&lt;channel.close&gt;(reply-code=200, reply-text=OK, class-id=0, method-id=0)
  com.rabbitmq.client.TopologyRecoveryException: Caught an exception while recovering exchange testSuccessfulInitVirtualHost_Exchange: channel is already closed due to clean channel shutdown; protocol method: #method&lt;channel.close&gt;(reply-code=200, reply-text=OK, class-id=0, method-id=0)
      at com.rabbitmq.client.impl.recovery.AutorecoveringConnection.recoverExchanges(AutorecoveringConnection.java:482)
      at com.rabbitmq.client.impl.recovery.AutorecoveringConnection.recoverEntities(AutorecoveringConnection.java:467)
      at com.rabbitmq.client.impl.recovery.AutorecoveringConnection.beginAutomaticRecovery(AutorecoveringConnection.java:411)
      at com.rabbitmq.client.impl.recovery.AutorecoveringConnection.access$000(AutorecoveringConnection.java:52)
      at com.rabbitmq.client.impl.recovery.AutorecoveringConnection$1.shutdownCompleted(AutorecoveringConnection.java:351)
      at com.rabbitmq.client.impl.ShutdownNotifierComponent.notifyListeners(ShutdownNotifierComponent.java:75)
      at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:574)
  </code></pre>
  
  <p>The above exception is not seen if I do not close the channel that's used for creating the exchange.</p>