title: How to use Rabbit Connection Cache Mode and Autodeclare Features Together?
body: <p>The <a href="http://docs.spring.io/spring-amqp/docs/1.7.0.RELEASE/reference/html/_reference.html#connections" rel="nofollow noreferrer">Spring AMQP Reference</a> says:</p>
  
  <blockquote>
    <p>Starting with version 1.3, the <code>CachingConnectionFactory</code> can be configured to cache connections as well as just channels. In this case, each call to <code>createConnection()</code> creates a new connection (or retrieves an idle one from the cache). Closing a connection returns it to the cache (if the cache size has not been reached). Channels created on such connections are cached too. The use of separate connections might be useful in some environments, such as consuming from an HA cluster, in conjunction with a load balancer, to connect to different cluster members. Set the <code>cacheMode</code> to <code>CacheMode.CONNECTION</code>.</p>
  </blockquote>
  
  <p>I have an HA cluster behind a load balancer, and I can clearly see that when I use <code>CacheMode.CHANEL</code> all my channels come from a single connection and they are all located in the same host.</p>
  
  <p>When I change to <code>CacheMode.CONNECTION</code> I do see variance in the channels, i.e. not all are located in the same connection, and therefore I see different hosts from the cluster being used.</p>
  
  <p>So I think this second configuration makes a lot of sense to me in this particular case. However, the documentations also says:</p>
  
  <blockquote>
    <p>When the cache mode is <code>CONNECTION</code>, automatic declaration of queues etc. is NOT supported.</p>
  </blockquote>
  
  <p>And clearly this is also an important feature, because I don't want to have to manually apply any changes from my configuration.</p>
  
  <p>So, my question is, is there a way I can use both things? Would it make sense to have two connection factories, one for the <code>RabbitAdmin</code> and another one for the <code>RabbitTemplate</code>, listeners, etc.?</p>