title: Configuring ConnectionFactory for RabbitMQ in Spring Boot AMQP
body: <p><strong>TL;DR</strong> How to create Spring Boot AMQP connection factory programatically?</p>
  
  <p>Hey,</p>
  
  <p>In order to connect to my RabbitMQ I added these to my <code>application.properties</code> file of my Spring Boot app:</p>
  
  <pre><code>spring.rabbitmq.host=host
  spring.rabbitmq.port=5672
  spring.rabbitmq.username=myapp
  spring.rabbitmq.password=mypass
  </code></pre>
  
  <p>And according to my understanding, these values are then used to create Spring Boot's auto configured <code>ConnectionFactory</code>, which I then use in:</p>
  
  <pre><code>@Bean
  @Conditional(RabbitCondition.class)
  SimpleMessageListenerContainer container(ConnectionFactory connectionFactory, MessageListenerAdapter completedOrderListenerAdapter) {
      SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
      container.setConnectionFactory(connectionFactory);
      container.setQueueNames(completedOrderQueueName);
      container.setMessageListener(completedOrderListenerAdapter);
      return container;
  }
  </code></pre>
  
  <p>I would like to be able to use rabbitMQ credentials from different environment files which are not <code>application.properties</code>, so I would like to create <code>ConnectionFactory</code> bean programatically.
  How do I achieve this?</p>
  
  <p>Thanks.</p>