title: How to search for a particular message in JMS queue
body: <p>I am sending some messages to a JMS queue. What are the possible ways to search for a particular message in a queue to consume?</p>
  
  <p>I tried out in the following way: I am setting the <code>JMSCorrelationID</code> while sending a message to the queue:</p>
  
  <pre><code> public void createDQueue(String queuename, String json, Integer userid) {
            try {
  
                  QueueSession.AUTO_ACKNOWLEDGE );
                  Queue queue = session.createQueue(queuename);
                  ObjectMessage objectMessage = session.createObjectMessage();
                  objectMessage.setJMSCorrelationID(String.valueOf(userid));
                  objectMessage.setObject(json);
                  session.createSender(queue).send(objectMessage);
                  session.close();
                  connection.close();
            }catch(Exception e){
                e.printStackTrace();
            }
        }
  </code></pre>
  
  <p>In the consumer code I want to get that particular message based on the <code>JMSCorrelationID</code>. I am not able to get that particular message. Can you suggest a solution?  </p>
  
  <pre><code>public void getSpecificMessage(String queuename, Integer userid) {
  
           try {
              QueueConnectionFactory connectionFactory = new ActiveMQConnectionFactory( "tcp://localhost:61616");
                  ((ActiveMQConnectionFactory) connectionFactory).setUseAsyncSend(true);
                  QueueConnection connection = connectionFactory.createQueueConnection();
                  connection.start();
                  QueueSession session = connection.createQueueSession( false,
                       QueueSession.AUTO_ACKNOWLEDGE );
                  String id = String.valueOf(userid);
              Queue queue = session.createQueue(queuename);
              QueueReceiver receiver = session.createReceiver(queue, "JMSCorrelationID="+id);
               Message message = receiver.receive();              
          } catch (JMSException e) {              
              e.printStackTrace();
          }
        }
  </code></pre>