mq
  1. mq
  2. MQ-167

Setting a message selector on a durable subscription to an empty string prevents messages being added to it

    Details

      Description

      This issue relates to following the JMS API method on javax.jms.Session

      createDurableSubscriber(
         Topic topic, java.lang.String name, java.lang.String messageSelector, boolean noLocal throws JMSException
      

      The (javadoc ) documents the messageSelector parameter as follows:

      A value of null or an empty string indicates that there is no message selector for the message consumer.

      A value of null acts as if there is no message selector. However a value of "" prevents messages being added to the subscription.

      Test case here: this fails if messageSelector is set to "". However it passes if it is set to null.

      public class TestJMS {
      
      	private static final String clientID = "myClientID";
      	private static final String topicName = "someTopic";
      	private static final String subscriptionName = "someSubscription";
      
      	@Test
      	public void test1() throws JMSException, InterruptedException {
      
      		{
      			// create a connection, create durable subscription with noLocal=false, messageSelector="", 
      			// then close the connection. 
      			ConnectionFactory connectionFactory = new com.sun.messaging.ConnectionFactory();
      			Connection connection = connectionFactory.createConnection();
      			connection.setClientID(clientID);
      			Session session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
      			boolean noLocal=false;
      			String messageSelector="";
      			session.createDurableSubscriber(session.createTopic(topicName), subscriptionName, messageSelector, noLocal);
      			connection.close();
      		}
      
      		{
      			// create a new connection with clientID unset and use it to send a
      			// message to the topic. 
      			ConnectionFactory connectionFactory2 = new com.sun.messaging.ConnectionFactory();
      			Connection connection2 = connectionFactory2.createConnection();
      			Session session2 = connection2.createSession(false,Session.AUTO_ACKNOWLEDGE);
      			MessageProducer messageProducer2 = session2.createProducer(session2.createTopic(topicName));
      			messageProducer2.send(session2.createTextMessage("Hello"));
      			connection2.close();
      		}
      
      		{
      			// create a third connection, activate the durable subscription, and consume the message
      			ConnectionFactory connectionFactory3 = new com.sun.messaging.ConnectionFactory();
      			Connection connection3 = connectionFactory3.createConnection();
      			connection3.setClientID(clientID);
      			Session session3 = connection3.createSession(false,Session.AUTO_ACKNOWLEDGE);
      			MessageConsumer messageConsumer = session3.createDurableSubscriber(session3.createTopic(topicName),
      					subscriptionName);
      			connection3.start();
      			Message message3 = messageConsumer.receive(1000);
      			// check that message is received
      			Assert.assertNotNull(message3);
      			connection3.close();
      		}
      	}
      
      }
      

        Activity

        Hide
        amyk added a comment -

        This one has been fixed (see MQ-196)

        Show
        amyk added a comment - This one has been fixed (see MQ-196 )
        Hide
        saradak added a comment -


        Verified as part of CTS testing.

        Show
        saradak added a comment - Verified as part of CTS testing.

          People

          • Assignee:
            amyk
            Reporter:
            Nigel Deakin
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: