title: How to reconnect with Rabbit MQ after server goes down?
body: <p>I have a spring-boot application that uses Rabbit RPC. 
  The problem is that if the app starts, then Rabbit server goes down, the application doesn't reconnect with the server. And if the app starts while the rabbit server is down, it fails and doesn't attempt to reconnect to Rabbit after the Rabbit goes up again.
  Here is code of configuration</p>
  
  <pre><code>@Configuration
  public class RabbitConfiguration {
  
  @Value("${spring.rabbitmq.host}")
  private String rabbitmqHost;
  
  @Value("${spring.rabbitmq.queue}")
  private String rabbitmqQueue;
  
  @Value("${spring.rabbitmq.username}")
  private String rabbitmqUsername;
  
  @Value("${spring.rabbitmq.password}")
  private String rabbitmqPassword;
  
  private final CommentsServiceRpc commentsServiceRpc;
  
  
  public RabbitConfiguration(final CommentsServiceRpc commentsServiceRpc) {
      this.commentsServiceRpc = commentsServiceRpc;
  }
  
  @Bean
  public Connection rabbitmqConnection() throws IOException, TimeoutException {
      ConnectionFactory factory = new ConnectionFactory();
      factory.setHost(rabbitmqHost);
      factory.setUsername(rabbitmqUsername);
      factory.setPassword(rabbitmqPassword);
      return factory.newConnection();
  }
  
  @Bean
  public Channel rpcChanel() throws IOException, TimeoutException {
      Connection connection = rabbitmqConnection();
      Channel channel = connection.createChannel();
      channel.queueDeclare(rabbitmqQueue, false, false, false, null);
      return channel;
  }
  
  @Bean("commentsJsonRpcServer")
  @Lazy(false)
  public JsonRpcServer commentsJsonRpcServer() throws IOException, TimeoutException {
      JsonRpcServer jsonRpcServer = new JsonRpcServer(rpcChanel(), rabbitmqQueue, CommentsServiceRpc.class,
              commentsServiceRpc);
      new Thread(() -&gt; {
          try {
              jsonRpcServer.mainloop();
          } catch (Exception e) {
              System.out.println(e);
          }
      }).start();
      return jsonRpcServer;
  }
  }
  </code></pre>
  
  <p>How can I tell Spring-boot to try to reconnect, if Rabbit server fails and restarts?</p>