title: How to use Message Selectors to filter messages In JMS
body: <p>I have ejb-jar.xml which contain <code>&lt;message-selector&gt; destinationInstance IN(a', 'b','c')&lt;/message-selector&gt;.</code></p>
  
  <p>How we can implement message selector in standalone java program.</p>
  
  <p><code>JMSMessageListener</code> has been registered on queue and whenever there is message on queue , <code>onMessage</code> method of listener will be called.</p>
  
  <p>I Have Try this.? Does It work...</p>
  
  <p>public void messageSelector() {</p>
  
  <pre><code>List&lt;String&gt; url=StCotants.getUrls();   
  
      for(String obj:url){
  
          ConnectionFactory factory = new ActiveMQConnectionFactory(obj);
  
          System.out.println(factory);
  
          try{
              Connection connection = factory.createConnection();
  
              connection.start();
  
              Session session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE); 
  
               Queue queue = session.createQueue("queue");  
  
               MessageConsumer consumer = session.createConsumer(queue,"destinationInstance IN('a', 'b','c')");
  
               XyzMDBClient xyzClientlistener=new XyzMDBClient();
  
               consumer.setMessageListener(xyzClientlistener);
  
          }
          catch(Exception e){
  
              e.printStackTrace();
  
          }
  
      }
  </code></pre>