title: How to publish messages on RabbitMQ with fanout exchange using Spring Boot
body: <p>I have the following piece of code that publishes messages onto <code>RabbitMQ</code> queues using <code>fanout exchange</code>. The <code>exchange</code> is getting created but the message cannot be see in <code>RabbitMQ</code> queues. I am not seeing any error either.</p>
  
  <p><strong>BasicApplication.java</strong></p>
  
  <pre><code>@SpringBootApplication
  public class BasicApplication {
  
      public static final String QUEUE_NAME_1 = "helloworld.fanout.q1";
      public static final String QUEUE_NAME_2 = "helloworld.fanout.q2";
      public static final String EXCHANGE_NAME = "helloworld.fanout.x";
  
      //here the message ==&gt; xchange ==&gt; queue1, queue2
      @Bean
      public List&lt;Declarable&gt; fanoutBindings() {
          Queue fanoutQueue1 = new Queue(QUEUE_NAME_1, false);
          Queue fanoutQueue2 = new Queue(QUEUE_NAME_2, false);
          FanoutExchange fanoutExchange = new FanoutExchange(EXCHANGE_NAME);
          return Arrays.asList(
                  fanoutQueue1,
                  fanoutQueue2,
                  fanoutExchange,
                  bind(fanoutQueue1).to(fanoutExchange),
                  BindingBuilder.bind(fanoutQueue2).to(fanoutExchange));
      }
  
      public static void main(String[] args) {
          SpringApplication.run(BasicApplication.class, args).close();
      }
  
  }
  </code></pre>
  
  <p><strong>Producer.java</strong></p>
  
  <pre><code>@Component
  public class Producer implements CommandLineRunner {
  
      @Autowired
      private RabbitTemplate rabbitTemplate;
  
      @Override
      public void run(String... args) throws Exception {
          this.rabbitTemplate.convertAndSend(EXCHANGE_NAME, "Hello World !");
      }
  
  }
  </code></pre>