title: Handle the exceptions in RabbitMQ Spring Boot Application
body: <p>I am using Spring Boot 1.4.1-RELEASE and RabbitMQ 3.2.3. My Application class looks like this -</p>
  
  <pre><code>@SpringBootApplication
  @EnableAutoConfiguration
  public class EventStoreMessageDeliveryApplication {
  
      public final static String queueName = "customer.default.queue"; // spring-boot
  
      @Bean
      Queue queue() {
          return new Queue(queueName, true);
      }
  
      @Bean
      FanoutExchange exchange() {
  
          return new FanoutExchange("customer.events.fanout.exchange", true, false); // spring-boot-exchange
      }
  
      @Bean
      Binding binding() {
  
          return new Binding(queueName, Binding.DestinationType.QUEUE, "customer.events.fanout.exchange", "*.*", null);
      }
  
      @Bean
      public ConnectionFactory connectionFactory() {
  
          CachingConnectionFactory connectionFactory = new CachingConnectionFactory("localhost");
          connectionFactory.setPublisherConfirms(true);
  
          return connectionFactory;
      }
  
      @Bean
      SimpleMessageListenerContainer container(MessageListenerAdapter listenerAdapter) {
  
          SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
          container.setConnectionFactory(connectionFactory());
          container.setQueueNames(queueName);
          container.setMessageListener(listenerAdapter);
          container.setRecoveryBackOff(new ExponentialBackOff(3000, 2));
          return container;
      }
  
      @Bean
      MessageListenerAdapter listenerAdapter(Receiver receiver) {
  
          return new MessageListenerAdapter(receiver, "receiveMessage");
      }
  
      public static void main(String[] args) throws InterruptedException {
  
          SpringApplication.run(EventStoreMessageDeliveryApplication.class, args);
      }
  }
  </code></pre>
  
  <p>And my listener class looks like -</p>
  
  <pre><code>@Component
  public class Receiver {
  
      private CountDownLatch latch = new CountDownLatch(1);
  
      public void receiveMessage(String message) {
  
          System.out.println("Received &lt;" + message + "&gt;");
  
              // do something
  
          latch.countDown();
      }
  
      public CountDownLatch getLatch() {
  
          return latch;
      }
  
  }
  </code></pre>
  
  <p>I want to handle the exceptions like connection refused which may come when the broker is down. How can I handle such exceptions? I am not sure where I can get the handle for the exceptions.</p>