Uploaded image for project: 'ActiveMQ Classic'
  1. ActiveMQ Classic
  2. AMQ-3245

SELECTORS doesn't work for releases 5.4.0 to current

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 5.4.1, 5.4.2
    • None
    • Selector
    • None

    Description

      Is it possible that selector was broken due to new enhancement regarding REST selectors on 5.4.0? We are using 5.3.0 and selectors are working fine, however since we've upgraded our demo and test environments to 5.4.1 and essentially 5.4.2 it stop working for some reason. I can recreate it 100% of the time and below are the steps.

      1) First create the producer with String property set to 30. i.e. test, 30:

      String username="Me"
      String passwd = "invicible"
      String url ="failover:(tcp://localhost:51515)?maxReconnectDelay=5000&useExponentialBackOff=false";
      ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(username, passwd, url);
      Connection connection = connectionFactory.createConnection();
      // connection.setUseCompression(true); set this on the URL instead
      connection.setExceptionListener(this);
      
      String destinationString = "Test.Dest";
      // create a session, destination, and producer
      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Destination destination = session.createQueue(destinationString);
      
      MessageProducer producer = session.createProducer(destination);
      producer.setDeliveryMode(DeliveryMode.PERSISTENT);
      
      Message message = session.createTextMessage("This is a test message");
      message.setIntProperty("test", 30);
      // insert the message 1000 times.
      for (long l = 0L; l < 1000; l++) {
            producer.send(message);
      }
       producer.close();
       session.close();
       connection.close();
      

      Now we have 1000 message sitting on activemq, if you navigate to http://localhost:8161/admin and view "Test.Dest" queue you should see the 1000 message there.

      2) Create the consumer with test > 50 selector.

      public void setup() {
      String username="Me"
      String passwd = "invicible"
      String url ="failover:(tcp://localhost:51515)?maxReconnectDelay=5000&useExponentialBackOff=false"; //"tcp://localhost:51515";
      ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(username, passwd, url);
      Connection connection = connectionFactory.createConnection();
      // connection.setUseCompression(true); set this on the URL instead
      connection.setExceptionListener(this);
      
      // create a session, destination, and consumer
      Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
      String destinationString = "Test.Dest";
      session.createQueue(destinationString);
      MessageConsumer consumer = session.createConsumer(destination, "test > 50");
      consumer.setMessageListener(this);
      
      connection.start();
      
      }
      
      
      public void onMessage(Message message) {
             try {
                  if (print && text) {
                      TextMessage textMessage = (TextMessage) message;
                      System.out.println(textMessage.getText());
                  }
      
             catch (Exception ex)
             { //swallow } 
      }
      
      

      Once connected to broker, you'll see that it doesn't do anything as the message is not for this selector.

      3) Edit the code to producer.

      message.setIntProperty("test", 60);
      

      And then rerun the producer to insert the 1000 records again.

      Actual: Nothing happens, the consumer just waits for any message that comes in that matches the selector.
      Expected: The message gets consumed, as the latter part of the producer ran matches the selector.

      This behavior works perfectly fine with 5.3.0. As selector is an important functionality of JMS as a whole this being broken is actually bad.

      Attachments

        1. JmsTestProducer1.java
          3 kB
          Melvin Ramos
        2. JmsTestConsumer1.java
          3 kB
          Melvin Ramos
        3. activemq.xml
          3 kB
          Melvin Ramos
        4. ActiveMQ_Test_Case.txt
          2 kB
          Melvin Ramos

        Activity

          People

            Unassigned Unassigned
            jayd.lowrider Melvin Ramos
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: