title: Spring AMQP Project with 2 queue's
body: <p>I'm working on a project that involves 2 queue's, and multiples Listeners interacting with them.
  Flow: </p>
  
  <ul>
  <li>New HTTP request comes to the server, then it's converted into a Object that will be the message</li>
  <li>This message has to be published in two queues</li>
  <li>I have two types of Listeners that get messages from each queue and then I do whatever I want</li>
  </ul>
  
  <p>I've been reading and the best way to do is with a fanout-exchange. Here is my code:</p>
  
  <p>listener-configuration.xml</p>
  
  <pre><code>&lt;!-- CREATE CONNECTION FACTORY --&gt;
  &lt;rabbit:connection-factory id="connectionFactory"
      host="localhost" username="guest" password="guest" /&gt;
  
  &lt;rabbit:admin connection-factory="connectionFactory" /&gt;
  
  &lt;!-- &lt;!-- RABBIT QUEUE'S --&gt;
  &lt;rabbit:queue id="trashroute.rabbit.queue" name="trashroute.rabbit.queue" auto-delete="false" auto-startup=false
      durable="true" /&gt;
  &lt;!-- Webapp Queue --&gt;
  &lt;rabbit:queue id="trashroute2.rabbit.queue" name="trashroute2.rabbit.queue" auto-delete="false" auto-startup=false
      durable="true" /&gt; 
  
  &lt;!-- CREATE AN EXCHANGE AND BIND THE QUEUE WITH MY.ROUTINGKEY.* TO THE EXCHANGE --&gt;
  &lt;rabbit:fanout-exchange id="myExchange" name="trashroute-exchange"&gt;
      &lt;rabbit:bindings&gt;
          &lt;rabbit:binding queue="trashroute.rabbit.queue"&gt;&lt;/rabbit:binding&gt;
          &lt;rabbit:binding queue="trashroute2.rabbit.queue"&gt;&lt;/rabbit:binding&gt;
      &lt;/rabbit:bindings&gt;
  &lt;/rabbit:fanout-exchange&gt;
  
  &lt;!-- CREATE THE RABBIT TEMPLATES --&gt;
  &lt;rabbit:template connection-factory="connectionFactory" exchange="myExchange" queue="trashroute.rabbit.queue"/&gt;
  &lt;rabbit:template connection-factory="connectionFactory" exchange="myExchange" queue="trashroute2.rabbit.queue"/&gt;
  
  &lt;!-- INSTANTIATE THE LISTENERS --&gt;
  &lt;bean id="persistenceListener" class="trashroute.rabbitmq.listener.PersistenceListener" /&gt;
  &lt;bean id="webappListener" class="trashroute.rabbitmq.listener.WebappListener" /&gt;
  
  &lt;!-- CREATE THE JsonMessageConverter BEAN --&gt;
  &lt;bean id="jsonMessageConverter" class="org.springframework.amqp.support.converter.JsonMessageConverter" /&gt;
  
  &lt;!-- GLUE THE LISTENER AND QUEUE TO THE LISTENER CONTAINER --&gt;
  &lt;rabbit:listener-container id="listenerContainer"
      connection-factory="connectionFactory" message-converter="jsonMessageConverter"&gt;
      &lt;rabbit:listener ref="persistenceListener" queues="trashroute.rabbit.queue" /&gt;
      &lt;rabbit:listener ref="webappListener" queues="trashroute2.rabbit.queue" /&gt;
  &lt;/rabbit:listener-container&gt;
  </code></pre>
  
  <p>sender-configuration.xml</p>
  
  <pre><code>&lt;!--  First following line creates a rabbit connection factory with specified parameters --&gt;
  &lt;rabbit:connection-factory id="connectionFactory" host="localhost" username="guest" password="guest" /&gt;
  
  &lt;!-- Obtain admin rights to create an exchange --&gt;
  &lt;rabbit:admin connection-factory="connectionFactory" /&gt;
  
  &lt;!-- Create a bean which can send message to trashroute-exchange for the Java program to call --&gt;
  &lt;rabbit:template id="template" connection-factory="connectionFactory"  exchange="myExchange"
  message-converter="jsonMessageConverter" /&gt;
  
  
  &lt;bean id="rabbitTemplate" class="org.springframework.amqp.rabbit.core.RabbitTemplate"&gt;
  &lt;property name="connectionFactory" ref="rabbitConnectionFactory"/&gt;
  &lt;property name="messageConverter"&gt;
      &lt;bean class="org.springframework.amqp.support.converter.JsonMessageConverter"/&gt;
  &lt;/property&gt;
  </code></pre>
  
  <p>Listener MainConfiguration.java</p>
  
  <pre><code>@Configuration
  public class MainConfiguration {
  
  protected final String persistenceQueue = "trashroute.rabbit.queue";
  protected final String webappQueue = "trashroute2.rabbit.queue";
  
  @Bean
  public ConnectionFactory connectionFactory() {
      CachingConnectionFactory connectionFactory = new CachingConnectionFactory("localhost");
      connectionFactory.setUsername("guest");
      connectionFactory.setPassword("guest");
      return connectionFactory;
  }
  
  @Bean
  public AmqpAdmin amqpAdmin() {
      return new RabbitAdmin(connectionFactory());
  }
  
  @Bean
  public DataController DataController(){
      return new DataController();
  }
  
  @Bean
  // Every queue is bound to the default direct exchange
  public Queue persistenceQueue() { 
      //Create a new queue with an specific name and the durability value in true.
      return new Queue(this.persistenceQueue, true);
  }
  
  @Bean
  public Queue webappQueue() {
      //Create a new queue with an specific name and the durability value in true.
      return new Queue(this.webappQueue, true);
  }
  }
  </code></pre>
  
  <p>Sender MainConfiguration.java</p>
  
  <pre><code>@Configuration
  public class SenderConfiguration {
  
  protected final String persistenceQueue = "trashroute.rabbit.queue";
  protected final String webappQueue = "trashroute2.rabbit.queue";
  
  //Create the Template
  @Bean
  public RabbitTemplate rabbitTemplate() {
      RabbitTemplate template = new RabbitTemplate(connectionFactory());
      template.setMessageConverter(new JsonMessageConverter());
      return template;
  }
  
  @Bean
  public ConnectionFactory connectionFactory() {
      CachingConnectionFactory connectionFactory = new CachingConnectionFactory(
              "localhost");
      connectionFactory.setUsername("guest");
      connectionFactory.setPassword("guest");
      return connectionFactory;
  }
  
  @Bean
  public IServiceManager scheduledProducer() {
      return new ServiceManagerImpl();
  }
  
  @Bean
  public BeanPostProcessor postProcessor() {
      return new ScheduledAnnotationBeanPostProcessor();
  }
  
  }
  </code></pre>
  
  <p>Can anyone please tell me what I'm doing wrong? One of the two Listeners, works perfectly, the second never reads a message.</p>