title: channel is already closed due to channel error rabbitmq
body: <p>I am triying to develop a publish/subscribe system using RabbitMQ. The RabbitMQ server is in my laptop.
  I have coded the Consumer and Producer Classes. The producer is connected correctly to the broker, but I have a <strong>com.rabbitmq.client.ShutdownSignalException</strong> when I run the consumer class. </p>
  
  <p>My code is as follow. 
  I have a Functions.class :</p>
  
  <pre><code>public class Functions {
  
  
  public static String EXCHANGE_NAME = "exchange";
  
  private static ConnectionFactory factory;
  
  /**
   * Initialization for ConnectionFactory
   */
  static {
      factory = new ConnectionFactory();
      factory.setAutomaticRecoveryEnabled(true);
  
      factory.setHost("localhost");
  
  }
  
  
  public static Connection createConnection() {
      try {
          return factory.newConnection();
      } catch (Exception e) {
          e.printStackTrace();
          return null;
  
      }
  }}
  </code></pre>
  
  <p>Then the MyCosumer.java Class:</p>
  
  <pre><code>public class MyConsumer {
  
  private Connection connection;
  private Channel channel;
  private String queueName = "consumer";
  
  public MyConsumer() {
  
  }
  
  
  public void connect() throws IOException {
      connection = Functions.createConnection();
      channel = connection.createChannel();
      channel.exchangeDeclare(Functions.EXCHANGE_NAME, BuiltinExchangeType.TOPIC);
      channel.queueDeclare(queueName, true, false, false, new HashMap&lt;String, Object&gt;()).getQueue();
  
  }
  
  public void setRoutingKeys(String... keys) throws IOException {
      for (String bindingKey : keys) {
          channel.queueBind(queueName, Functions.EXCHANGE_NAME, bindingKey);
      }
  }
  
  
  public void clearRoutingKeys(String... keys) throws IOException {
      for (String bindingKey : keys) {
          channel.queueUnbind(queueName, Functions.EXCHANGE_NAME, bindingKey);
      }
  }
  
  public void recieveMessages() throws IOException {
      Consumer consumer = new DefaultConsumer(channel) {
          @Override
          public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,
                  byte[] body) throws IOException {
              String message = new String(body, "UTF-8");
              System.out.println(" [x] Received '" + envelope.getRoutingKey() + "':'" + message + "'");
          }
      };
  
      channel.basicConsume(queueName, true, consumer);
  
  }
  public void disconnect() throws IOException, TimeoutException {
      channel.close();
      connection.close();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>And the MyProducer.java Class :</p>
  
  <pre><code>public class MyProducer {
  
  private Connection connection;
  private Channel channel;
  
  public MyProducer() {
  
  }
  
  
  public void connect() throws Exception {
      connection = Functions.createConnection();
      channel = connection.createChannel();
      channel.exchangeDeclare(Functions.EXCHANGE_NAME, "topic");
  }
  
  public void sendMessage(String routingKey, String message) throws IOException {
      channel.basicPublish(Functions.EXCHANGE_NAME, routingKey, null, message.getBytes());
      System.out.println(" [x] Sent '" + routingKey + "':'" + message + "'");
  }
  
  
  public void disconnect() throws IOException, TimeoutException {
      channel.close();
      connection.close();
  }}
  </code></pre>
  
  <p>The main classes are as follow :</p>
  
  <p>the Producer main:</p>
  
  <pre><code>public class MainProducer {
  
  public static String[] categorias = { "Beauty", "Drinks", "Diary", "Vegetable" };
  
  public static void main(String[] args) throws Exception {
  
      MyProducer productor = new MyProducer();
      productor.connect();
      send(productor, categorias[1], "Makeup", "Discount 20% in loreal lipstick");
      send(productor, categorias[0], "Soap", "2x1 in Herbal Essence soap");
      send(productor, categorias[0], "Makeup", "Discount 10% in l'ocitane lipstick");
      send(productor, categorias[0], "Loreal Makeup", "Discount 20% in loreal lipstick");
      productor.disconnect();
  }
  
  private static void send(MyProducer productor, String categoria, String producto, String mensaje) {
      String routingKey = "offers." + categoria + "." + producto;
      try {
          productor.sendMessage(routingKey, mensaje);
      } catch (IOException e) {
          e.printStackTrace();
      }
  }}
  </code></pre>
  
  <p>THe consumer Main:</p>
  
  <pre><code>public class MainConsumer {
  
  public static void main(String[] args) throws Exception {
      MyConsumer consumer = new MyConsumer();
      consumer.connect();
      consumer.setRoutingKeys("kern");
      consumer.recieveMessages();
  }}
  </code></pre>
  
  <p>The obtained exception is : </p>
  
  <pre><code>Exception in thread "main" java.io.IOException
  at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:124)
  at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:120)
  at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:142)
  at com.rabbitmq.client.impl.ChannelN.queueDeclare(ChannelN.java:952)
  at com.rabbitmq.client.impl.recovery.AutorecoveringChannel.queueDeclare(AutorecoveringChannel.java:333)
  at main.MyConsumer.connect(MyConsumer.java:44)
  at main.MainConsumer.main(MainConsumer.java:7)
  
  Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method&lt;channel.close&gt;(reply-code=404, reply-text=NOT_FOUND - home node 'rabbit@souhaila-UX430UAR' of durable queue 'consumer' in vhost '/' is down or inaccessible, class-id=50, method-id=10)
  at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:66)
  at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:36)
  at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:443)
  at com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQChannel.java:263)
  at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:136)
  ... 4 more
  
  Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method&lt;channel.close&gt;(reply-code=404, reply-text=NOT_FOUND - home node 'rabbit@souhaila-UX430UAR' of durable queue 'consumer' in vhost '/' is down or inaccessible, class-id=50, method-id=10)
  at com.rabbitmq.client.impl.ChannelN.asyncShutdown(ChannelN.java:509)
  at com.rabbitmq.client.impl.ChannelN.processAsync(ChannelN.java:340)
  at com.rabbitmq.client.impl.AMQChannel.handleCompleteInboundCommand(AMQChannel.java:162)
  at com.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:109)
  at com.rabbitmq.client.impl.AMQConnection.readFrame(AMQConnection.java:643)
  at com.rabbitmq.client.impl.AMQConnection.access$300(AMQConnection.java:47)
  at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:581)
  at java.lang.Thread.run(Thread.java:748)
  </code></pre>