title: Routing to virtual destinations inside ActiveMQ broker
body: <p>I have an activemq configuration wherein I have a virtual destination and a normal topic</p>
  
  <p>I want to route all the JMS messages to the destination(VirtualTopic.Notifications) to 2 queues(VirtualTopic.SMS, VirtualTopic.EMAIL) based on their JMSType in the message header.</p>
  
  <p>And I want the normal Topic(VirtualTopic.gps) to work as usual. </p>
  
  <p>This is my configuration of activemq.xml. Here Consumer.SMS.VirtualTopic and Consumer.EMAIL.VirtualTopic is created.</p>
  
  <pre><code>    &lt;destinations&gt;
          &lt;queue physicalName="Consumer.SMS.VirtualTopic" /&gt;
          &lt;queue physicalName="Consumer.EMAIL.VirtualTopic" /&gt;
      &lt;/destinations&gt;
  
      &lt;destinationInterceptors&gt;
        &lt;virtualDestinationInterceptor&gt;
          &lt;virtualDestinations&gt;
            &lt;compositeQueue name="VirtualTopic.Notifications" forwardOnly="false"&gt;
              &lt;forwardTo&gt;
                &lt;filteredDestination selector="JMSType = 'SMS'" queue="Consumer.SMS.VirtualTopic"/&gt;
                &lt;filteredDestination selector="JMSType = 'EMAIL'" queue="Consumer.EMAIL.VirtualTopic"/&gt;
              &lt;/forwardTo&gt;
            &lt;/compositeQueue&gt;
          &lt;/virtualDestinations&gt;
        &lt;/virtualDestinationInterceptor&gt;
      &lt;/destinationInterceptors&gt;
  </code></pre>
  
  <p>While the consumer and topic (VirtualTopic.gps) is created from the server side code.</p>
  
  <pre><code>    private static MessageProducer getTopicProducer(String topicName) throws JMSException {
      MessageProducer producer = topicProducers.get(topicName);
  
      if (producer == null) {
          logger.info("Creating message producer for Topic : {}", topicName);
          Destination destination = session.createTopic(topicName);
  
          List&lt;String&gt; queueNames = PropertyReader
                  .getPropertyStringList("jms.topic.consumer.list", JMSProducer.properties);
          if (queueNames != null) {
              for (String queueName : queueNames) { 
                  Queue virtualQueue = session.createQueue(queueName);
                  MessageConsumer con = session.createConsumer(virtualQueue);
                  con.close();
              }
          }
  
          producer = session.createProducer(destination);
          topicProducers.put(topicName, producer);
      }
  
      return producer;
      }
  </code></pre>
  
  <p>All the messages to the VirtualTopic.Notifications are routed to 2 different queues and consumers can pick up messages from respective queues</p>
  
  <p>But the issue is all the messages which are being sent to the VirtualTopic.gps are filtered and the consumers cant consume the gps messages.</p>