title: Rabbitmq camel spring boot auto config
body: <p>I have camel and rabbitmq configured like the following and it is working.  I am looking to improve the config setup.  </p>
  
  <p><strong>pom.xml</strong></p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;dependency&gt;
      &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
      &lt;artifactId&gt;camel-rabbitmq-starter&lt;/artifactId&gt;
      &lt;version&gt;2.19.1&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p><strong>application.yml</strong></p>
  
  <pre class="lang-yaml prettyprint-override"><code>spring: 
    rabbitmq:
      host: rabbithost-url
      port: 5672
      username: my-user
      password: my-password
  </code></pre>
  
  <p><strong>config bean</strong></p>
  
  <pre class="lang-java prettyprint-override"><code>@Configuration
  public class CamelConfig {
  
      @Resource private Environment env;
  
      @Bean
      public ConnectionFactory rabbitConnectionFactory(){
          ConnectionFactory connectionFactory = new ConnectionFactory();
          connectionFactory.setHost(env.getProperty("spring.rabbitmq.host"));
          connectionFactory.setPort(Integer.valueOf(env.getProperty("spring.rabbitmq.port")));
          connectionFactory.setAutomaticRecoveryEnabled(true);
          // more config options here etc
          return connectionFactory;
      }
  }
  </code></pre>
  
  <p><strong>Route Example</strong></p>
  
  <pre class="lang-java prettyprint-override"><code>@Component
  public class MyRoute extends RouteBuilder {
  
      @Override
      public void configure() throws Exception {
  
       from("direct:startQueuePoint")
            .id("idOfQueueHere")
            .to("rabbitmq://rabbithost-url:5672/TEST-QUEUE.exchange?queue=TEST-QUEUE.queue&amp;autoDelete=false&amp;connectionFactory=#rabbitConnectionFactory")
            .end();
      }
  }
  </code></pre>
  
  <p>Would like to improve the following?  Or at least see if its possible?</p>
  
  <p><strong>1)</strong>  How do I leverage spring boot autowiring.  I feel like im duplicating beans by added the custom CamelConfig > rabbitConnectionFactory?  Its not using the RabbitAutoconfiguration?</p>
  
  <p><strong>2)</strong>  When I am using the connection factory I am referencing the rabbitmq-url and port twice?  I am adding it in the rabbitConnectionFactory bean object and in the camel url?  e.g. </p>
  
  <pre class="lang-java prettyprint-override"><code>.to("rabbitmq://rabbithost-url:5672/ ..etc.. &amp;connectionFactory=#rabbitConnectionFactory")
  </code></pre>
  
  <p>can I not just reference it once in the connection factory?  tried the following without the host as its included in connectionFactory but it did not work.</p>
  
  <pre class="lang-java prettyprint-override"><code>.to("rabbitmq://TEST-QUEUE.exchange?queue=TEST-QUEUE.queue&amp;autoDelete=false&amp;connectionFactory=#rabbitConnectionFactory")
  </code></pre>
  
  <p>The 1st working example I am using is based off this.
   <a href="http://camel.apache.org/rabbitmq.html" rel="noreferrer">camel.apache.org/rabbitmq example (see Custom connection factory )</a></p>