title: ShutdownSignalException while using Spring Cloud + Spring ampq + Spring Boot + RabbitMQ
body: <p>I am working on a spring cloud based application using Spring Boot and RabbitMQ. I am trying to use <code>FanoutExchange</code> to create an exchange in RabbitMQ. <strong>My requirement is to send same message to multiple queues, so i am using <code>FanoutExchange</code></strong> But getting the exception as :</p>
  
  <pre><code>Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; 
  protocol method: #method&lt;channel.close&gt;(reply-code=406, reply-text=PRECONDITION_FAILED
   - inequivalent arg 'type' for exchange 'rkk_exchange1' in vhost  
  '': received 'fanout' but current is 'topic', 
  class-id=40, method-id=10)
  </code></pre>
  
  <p>Below is the code (configuration file):</p>
  
  <pre><code>@Configuration
  @Profile("cloud")
  public class MultiListenerRabbitConfig extends AbstractCloudConfig{
  
  private static final String QUEUE_NAME1="rk.rkk_queue1";
  private static final String QUEUE_NAME2="rk.rkk_queue2";
  private static final String EXCHANGE_NAME="rkk_exchange1";
  private static final int PORT = 1;
  
  
  @Bean
  public CachingConnectionFactory cachingConnectionFactory(){
  
      CloudFactory cloudFactory = new CloudFactory();
      Cloud cloud = cloudFactory.getCloud();
      List&lt;ServiceInfo&gt; listServices = cloud.getServiceInfos();
      AmqpServiceInfo serviceInfo = (AmqpServiceInfo) cloud.getServiceInfo(cloud.getServiceInfos().get(0).getId());
  
  
      CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory();
      cachingConnectionFactory.setUsername(serviceInfo.getUserName());
      cachingConnectionFactory.setPassword(serviceInfo.getPassword());
      cachingConnectionFactory.setVirtualHost(serviceInfo.getVirtualHost());
      cachingConnectionFactory.setHost(serviceInfo.getHost());
      cachingConnectionFactory.setPort(PORT);
      cachingConnectionFactory.setRequestedHeartBeat(30);
      cachingConnectionFactory.setConnectionTimeout(30000);
      return cachingConnectionFactory;
  }
  
  @Bean
  public RabbitTemplate rabbitTemplate(){
      System.out.println("-----------------**************------------------ Create Rabbit Template");
      RabbitTemplate template = new RabbitTemplate(cachingConnectionFactory());
  
      return template;
  }
  
  
  @Bean
  public RabbitAdmin rabbitAdmin(){
      //Set up queue, exchanges and bindings
      RabbitAdmin admin = new RabbitAdmin(cachingConnectionFactory());
      Queue queue1 = new Queue(QUEUE_NAME1);
      admin.declareQueue(queue1);
      //For a Fanout Exchange, any Queue bound to that Exchange will receive any message sent to that Exchange
      FanoutExchange exchange = new FanoutExchange(EXCHANGE_NAME);
      admin.declareExchange(exchange);
      Binding binding = BindingBuilder.bind(queue1).to(exchange);
      admin.declareBinding(binding);
  
  
      return admin;
  }
  }
  </code></pre>
  
  <p>Putting the stack trace:</p>
  
  <blockquote>
    <p>ERR Caused by: java.io.IOException
    2016-09-14T19:42:02.68+0530 [App/0]      ERR    at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:106)
    2016-09-14T19:42:02.68+0530 [App/0]      ERR    at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:102)
    2016-09-14T19:42:02.68+0530 [App/0]      ERR    at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:124)
    2016-09-14T19:42:02.68+0530 [App/0]      ERR    at com.rabbitmq.client.impl.ChannelN.exchangeDeclare(ChannelN.java:693)
    2016-09-14T19:42:02.68+0530 [App/0]      ERR    at com.rabbitmq.client.impl.ChannelN.exchangeDeclare(ChannelN.java:662)
    2016-09-14T19:42:02.68+0530 [App/0]      ERR    at com.rabbitmq.client.impl.ChannelN.exchangeDeclare(ChannelN.java:61)
    2016-09-14T19:42:02.68+0530 [App/0]      ERR    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    2016-09-14T19:42:02.68+0530 [App/0]      ERR    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    2016-09-14T19:42:02.68+0530 [App/0]      ERR    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    2016-09-14T19:42:02.68+0530 [App/0]      ERR    at java.lang.reflect.Method.invoke(Method.java:498)
    2016-09-14T19:42:02.68+0530 [App/0]      ERR    at org.springframework.amqp.rabbit.connection.CachingConnectionFactory$CachedChannelInvocationHandler.invoke(CachingConnectionFactory.java:625)
    2016-09-14T19:42:02.68+0530 [App/0]      ERR    at com.sun.proxy.$Proxy50.exchangeDeclare(Unknown Source)
    2016-09-14T19:42:02.68+0530 [App/0]      ERR    at org.springframework.amqp.rabbit.core.RabbitAdmin.declareExchanges(RabbitAdmin.java:422)
    2016-09-14T19:42:02.68+0530 [App/0]      ERR    at org.springframework.amqp.rabbit.core.RabbitAdmin.access$000(RabbitAdmin.java:54)
    2016-09-14T19:42:02.68+0530 [App/0]      ERR    at org.springframework.amqp.rabbit.core.RabbitAdmin$1.doInRabbit(RabbitAdmin.java:111)
    2016-09-14T19:42:02.68+0530 [App/0]      ERR    at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:1045)
    2016-09-14T19:42:02.68+0530 [App/0]      ERR    ... 38 more
    2016-09-14T19:42:02.68+0530 [App/0]      ERR Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method(reply-code=406, reply-text=PRECONDITION_FAILED - inequivalent arg 'type' for exchange 'rkk_exchange1' in vhost '': received 'fanout' but current is 'topic', class-id=40, method-id=10)
    2016-09-14T19:42:02.68+0530 [App/0]      ERR    at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:67)
    2016-09-14T19:42:02.68+0530 [App/0]      ERR    at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:33)
    2016-09-14T19:42:02.68+0530 [App/0]      ERR    at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:343)
    2016-09-14T19:42:02.68+0530 [App/0]      ERR    at com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQChannel.java:216)
    2016-09-14T19:42:02.68+0530 [App/0]      ERR    at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:118)
    2016-09-14T19:42:02.68+0530 [App/0]      ERR    ... 51 more
    2016-09-14T19:42:02.68+0530 [App/0]      <strong>ERR Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method(reply-code=406, reply-text=PRECONDITION_FAILED - inequivalent arg 'type' for exchange 'rkk_exchange1' in vhost '': received 'fanout' but current is 'topic', class-id=40, method-id=10)</strong>
    2016-09-14T19:42:02.68+0530 [App/0]      ERR    at com.rabbitmq.client.impl.ChannelN.asyncShutdown(ChannelN.java:478)
    2016-09-14T19:42:02.68+0530 [App/0]      ERR    at com.rabbitmq.client.impl.ChannelN.processAsync(ChannelN.java:315)
    2016-09-14T19:42:02.68+0530 [App/0]      ERR    at com.rabbitmq.client.impl.AMQChannel.handleCompleteInboundCommand(AMQChannel.java:144)
    2016-09-14T19:42:02.68+0530 [App/0]      ERR    at com.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:91)
    2016-09-14T19:42:02.68+0530 [App/0]      ERR    at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:552)
    2016-09-14T19:42:02.68+0530 [App/0]      ERR    ... 1 more
    2016-09-14T19:42:02.73+0530 [DEA/19]     ERR Instance (index 0) failed to start accepting connections</p>
  </blockquote>
  
  <p>Note: This app is working with <code>TopicExchange</code> , but my requirement is to use <code>FanoutExchange</code></p>