Message selector help

Help
2002-12-11
2002-12-13
  • Graeme Boyd

    Graeme Boyd - 2002-12-11

    Hi,

    I'm using Ubermq with JDK1.4.1 on Win2k.  I have no problems receiving messages without a message selector but when I try to use a message selector no messages are delivered.  The messages appear in the viewer application so they are being published.  When the messages selector is replaced with an empty string i.e. "" messages are received.  Ubermq and both publisher and subscriber all run on the same computer.  Changing from a durable to a non durable subscription makes no difference.

    Any help would be greatly appreciated.

    Graeme

    -- imports omitted --

    public class JMSSubTest {
        private static TopicConnectionFactory topicConnectionFactory = null;
        private static Topic myTopic = null;
        protected static TopicConnection topicConnection = null;
        protected static TopicSession topicSession = null;
        protected static TopicSubscriber quoteSubscriber;

        public static void main(String[] args) throws Exception{
            try {
                topicConnectionFactory = new UnicastTopicConnectionFactory("localhost", 3999);
                topicConnection = topicConnectionFactory.createTopicConnection();
                topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
                myTopic = topicSession.createTopic("test");

                String selector = "subject = 'testsubject'";
                quoteSubscriber = topicSession.createDurableSubscriber(myTopic, "sub1", selector, false);
                quoteSubscriber.setMessageListener(new TestListener());
               
                topicConnection.start();
                System.out.println("Waiting...");
            } catch (JMSException e) {
                e.printStackTrace();
            }
        }
    }

    -- imports omitted --

    public class JMSPubTest {
        private static TopicConnectionFactory topicConnectionFactory = null;
        private static Topic myTopic = null;
        protected static TopicConnection topicConnection = null;
        protected static TopicSession topicSession = null;
        protected static TopicPublisher quotePublisher;
       
        public static void main(String[] args) throws Exception {
            try {
                topicConnectionFactory = new UnicastTopicConnectionFactory("localhost", 3999);
                topicConnection = topicConnectionFactory.createTopicConnection();
                topicSession = topicConnection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);

                myTopic = topicSession.createTopic("test");
                quotePublisher = topicSession.createPublisher(myTopic);
               
                TextMessage m = topicSession.createTextMessage("Hello World");
                m.setStringProperty("subject", "testsubject");
                quotePublisher.publish(m);
                System.out.println("Published: " + m);
               
            } catch (JMSException e) {
                e.printStackTrace();
            }
        }
    }

    -- imports omitted --

    public class TestListener implements MessageListener {
        public void onMessage(Message message) {
            System.out.println("Received Message");
            try {
                if (message instanceof TextMessage) {
                    TextMessage m = (TextMessage) message;
                    System.out.println(m.getText());
                }
            } catch (JMSException e) {
                System.out.println("JMSException: " + e);
            }
        }
    }

     
    • Jimmy P

      Jimmy P - 2002-12-11

      Hello,
      This appears to be a bug. The message selector implementation is somewhat quick & dirty...  it only supports clauses that look like:

      WHERE property = scalar

      so a working version of your selector might look like:

      WHERE subject = testsubject

      This has the unfortunate consequence that whitespace in your scalar value is not supported... and the working selector is not SQL-92 compliant.  in my mind there are two options if you need to support this:

      1. go ahead and edit the code. the selector implementation is in com.ubermq.jms.server.routing.impl.SimpleSelector. It is a pretty straightforward object as well, so you shouldn't have trouble with it.

      2. wait till 1.2. i'll add this to the list of bugs for the next release, and it should get fixed by then. I'm guessing 1.2 will be ready sometime early January.

      james

       
    • Graeme Boyd

      Graeme Boyd - 2002-12-11

      Thanks!

      I don't need SQL92 compliance, a simple (and probably much faster) way to discriminate between messages is ideal for me.

      Could I suggest adding to the docs a note that UberMQ doesn't use JNDI to find factory objects and topics.  I had previously been using OpenJMS which uses JNDI to create the factory objects and find topics.  A note in the documentation about this difference would have saved a little head scratching.  Also a simple example application would be useful.  If you like I could package the above code as a simple app.

      Graeme

       
    • Jimmy P

      Jimmy P - 2002-12-12

      OK great! Glad I could help you out.

      It would be tremendously helpful if you packaged up your sample code. I think it would benefit people just starting out, like you mentioned.

      You can email it to me through sourceforge, and I'll get it into the code base.

      Thanks! good luck with UberMQ.

      james

       
    • Sin Le Roop

      Sin Le Roop - 2002-12-13

      Why do you support look the factory objects and find topics?
      I think it wants for us. and UberMQ can portable.

      Roop Sin

       

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks