RabbitMQ - Java Spring - how to init exchange to several queues?
<p>I'm having difficulty finding a Spring way to initial an exchange that's sending the incoming message to more then 1 queue - on my Spring-boot application:</p>
<p>I can't find a good way to define a seconds exchange-queue binding.</p>
<p>I'm using RabbitTemplate as the producer client.</p>
<p>The RabbitMQ 6 page tutorial doesn't really help with that since:</p>
<ol>
<li>the only initial several temporary queues from the Consumer on-demand (while I need to the Producer to do the binding - to persistant queues)</li>
<li>The examples are for basic java usage - not using Spring capabilities.</li>
</ol>
<p>I also failed to find how to implement it via The spring AMQP pages.</p>
<p>what I got so far, is trying to inject the basic java binding to the spring way of doing it - but it's not working....</p>
<pre><code>@Bean
public ConnectionFactory connectionFactory() throws IOException {
    CachingConnectionFactory connectionFactory = new CachingConnectionFactory(&quot;localhost&quot;);
    connectionFactory.setUsername(&quot;guest&quot;);
    connectionFactory.setPassword(&quot;guest&quot;);

    Connection conn = connectionFactory.createConnection();
    Channel channel = conn.createChannel(false);

    channel.exchangeDeclare(SPRING_BOOT_EXCHANGE, &quot;fanout&quot;);
    channel.queueBind(queueName, SPRING_BOOT_EXCHANGE, &quot;&quot;); //first bind
    channel.queueBind(queueName2, SPRING_BOOT_EXCHANGE, &quot;&quot;);// second bind

    return connectionFactory;
}
</code></pre>
<p>Any help would be appreciated</p>
<h2>Edited</h2>
<p>I <em>think</em> the problem arise with the fact that every time I restart my server it tries to redefine the exchange-query-binding - while they persist in the broker...
I managed to define them manually via the brokers UI console - so the Producer only aware of the exchange name, and the Consumer only aware to it's relevant queue.
Is there a way to define those element progrematically - but in such a way so it won't be redefined\overwritten if already exist from previous restarts?</p>