title: MQ message selector with JMSTimestamp
body: <p>I have created an MQ receiver with following selector: </p>
  
  <pre><code>String selector = "JMSTimestamp BETWEEN 1446297200000 AND 1552479882777"
  </code></pre>
  
  <p>When I ran the code, the selector is picking up the messages which is out of these bounds and it is not picking up the ones which are actually supposed to be picked up.
  Log snippet is as written below :</p>
  
  <pre><code>**lines****
  --------- Receiving messages from MQ.
  --------- Created consumer with Message selector JMSTimestamp BETWEEN 1446297200000 AND 1552479882777.
  --------- Receiving messages.
  --------- Message type is text.
  --------- JMSTimestamp is 1552480011190.
  --------- JMSTimestamp with format Mar 13,2019 13:26:51 .
  --------- Processing Message.
  ***lines***
  </code></pre>
  
  <p>As we can see in logs the JMSTimeStamp of message is greater than the one mentioned in selector upper bound 1552479882777.</p>
  
  <p>what is wrong in the selector, and how is it supposed to be written? please help to analyse.</p>
  
  <p>Full code is as follows:</p>
  
  <pre><code>      @Cleanup
        QueueConnection connection = null;
        @Cleanup
        QueueSession session = null;
        @Cleanup
        MessageConsumer receiver = null;
        @Cleanup
        InitialContext ctx = null;
        ctx = new InitialContext();
        QueueConnectionFactory cf = (QueueConnectionFactory) ctx.lookup(JMS_FACTORY);
        connection = (QueueConnection) cf.createQueueConnection();
        session = (QueueSession) connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        log.info("Receiving Message from MQ");
        Queue replyQueue = (Queue) session.createQueue(REPLY_QUEUE);
        //getting time till 3 minutes ago
        Long threeMinutesAgo = System.currentTimeMillis() - 180000;
        // below expression is to select messages which are sitting in queue for more than 3 minutes,
        String messageSelector = "JMSTimestamp BETWEEN 1446297200000 AND " + threeMinutesAgo;
        receiver = (MessageConsumer) session.createConsumer(replyQueue, messageSelector);
        log.info("created Consumer with message selector {}", messageSelector);
        connection.start();
        while (true) {
          log.info("------------receiving response--------------");
          Message asyncMessage = receiver.receiveNoWait();
          if (asyncMessage instanceof TextMessage) {
            log.info("Message type is text");
            log.info("JMSTimeStamp is {}", String.valueOf(asyncMessage.getJMSTimestamp()));
            log.info("JMSTimeStamp with format {}", sdf.format(new Date(asyncMessage.getJMSTimestamp())));
            log.info("ThreeMinutesAgo with format {}", sdf.format(new Date(threeMinutesAgo)));
            log.info("Difference is {}", String.valueOf(System.currentTimeMillis() - asyncMessage.getJMSTimestamp()));
            log.info("Difference with format {}",
                sdf.format(new Date(System.currentTimeMillis() - asyncMessage.getJMSTimestamp())));
            String replyString = ((TextMessage) asyncMessage).getText();
            asyncMessage.acknowledge();
            processIntoText(replyString);
          } if (asyncMessage == null) {
            log.error("Queue is now empty for specified messages or null. ");
            break;
          }
        }
      } catch (JMSException | JAXBException | ParserConfigurationException | SAXException | NamingException e) {
        log.error("Error in messaging {}", e);
      }
  </code></pre>