1 Reply Latest reply on Nov 13, 2005 2:46 PM by seleuco

    Selector like operator don work ? It works with Websphere bu

    seleuco

      We are trying to migrate a j2ee solution from websphere to jboss. It is a business layer for a retail company.

      All was OK, but... we cant do a simple LIKE selector. We use the selector to male filters by stores...

      example: in the publisher

      tm.setStringProperty("phone","123");

      in the subcriber

      TopicSubscriber recv = session.createSubscriber(topic, new String("phone like '%123%'"),false);

      This is the example from the JMS expecification.... what are we doing wrong?

      This is the code (a modified version from the basic example from jboss)
      also note we are working in client mode
      :


      package pub;
      import java.util.Hashtable;

      import javax.jms.JMSException;
      import javax.jms.Message;
      import javax.jms.MessageListener;
      import javax.jms.Topic;
      import javax.jms.TopicConnection;
      import javax.jms.TopicConnectionFactory;
      import javax.jms.TopicPublisher;
      //import javax.jms.TopicSlistubscriber;
      import javax.jms.TopicSession;
      import javax.jms.TextMessage;
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;


      public class TopicSendClient
      {
      TopicConnection conn = null;
      TopicSession session = null;
      Topic topic = null;

      public void setupPubSub()
      throws JMSException, NamingException
      {

      Hashtable props = new Hashtable();
      props.put(
      Context.INITIAL_CONTEXT_FACTORY,
      "org.jnp.interfaces.NamingContextFactory");
      props.put(
      Context.URL_PKG_PREFIXES,
      "org.jboss.naming:org.jnp.interfaces");
      props.put(Context.PROVIDER_URL, "jnp://localhost:1099");
      //Context ctx = new InitialContext(props);
      InitialContext iniCtx = new InitialContext(props);
      Object tmp = iniCtx.lookup("ConnectionFactory");
      TopicConnectionFactory tcf = (TopicConnectionFactory) tmp;
      conn = tcf.createTopicConnection();
      topic = (Topic) iniCtx.lookup("topic/testTopic");
      session = conn.createTopicSession(false,
      TopicSession.AUTO_ACKNOWLEDGE);
      conn.start();
      }

      public void sendAsync(String text)
      throws JMSException, NamingException
      {
      System.out.println("Begin sendAsync");
      // Setup the pub/sub connection, session
      setupPubSub();
      // Send a text msg
      TopicPublisher send = session.createPublisher(topic);
      TextMessage tm = session.createTextMessage(text);
      tm.setStringProperty("phone","123");
      send.publish(tm);
      System.out.println("sendAsync, sent text=" + tm.getText());
      send.close();
      System.out.println("End sendAsync");
      }

      public void stop()
      throws JMSException
      {
      conn.stop();
      session.close();
      conn.close();
      }

      public static void main(String args[])
      throws Exception
      {
      System.out.println("Begin TopicSendClient, now=" +
      System.currentTimeMillis());
      TopicSendClient client = new TopicSendClient();
      client.sendAsync("A text msg, now="+System.currentTimeMillis());
      client.stop();
      System.out.println("End TopicSendClient");
      System.exit(0);
      }

      }


      package sub;

      import java.nio.channels.Selector;
      import java.util.Hashtable;

      import javax.jms.JMSException;
      import javax.jms.Message;
      import javax.jms.MessageListener;
      import javax.jms.Topic;
      import javax.jms.TopicConnection;
      import javax.jms.TopicConnectionFactory;
      import javax.jms.TopicPublisher;
      import javax.jms.TopicSubscriber;
      import javax.jms.TopicSession;
      import javax.jms.TextMessage;
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;

      /**
      * A JMS client example program that synchronously receives a message a Topic
      *
      * @author Scott.Stark@jboss.org
      * @version $Revision: 1.9 $
      */
      public class TopicRecvClient
      {
      TopicConnection conn = null;
      TopicSession session = null;
      Topic topic = null;

      public void setupPubSub()
      throws JMSException, NamingException
      {
      Hashtable props = new Hashtable();
      props.put(
      Context.INITIAL_CONTEXT_FACTORY,
      "org.jnp.interfaces.NamingContextFactory");
      props.put(
      Context.URL_PKG_PREFIXES,
      "org.jboss.naming:org.jnp.interfaces");
      props.put(Context.PROVIDER_URL, "jnp://localhost:1099");
      //Context ctx = new InitialContext(props);
      InitialContext iniCtx = new InitialContext(props);
      Object tmp = iniCtx.lookup("ConnectionFactory");
      TopicConnectionFactory tcf = (TopicConnectionFactory) tmp;
      conn = tcf.createTopicConnection();
      topic = (Topic) iniCtx.lookup("topic/testTopic");
      session = conn.createTopicSession(false,
      TopicSession.AUTO_ACKNOWLEDGE);
      conn.start();
      }

      public void recvSync()
      throws JMSException, NamingException
      {
      System.out.println("Begin recvSync");
      // Setup the pub/sub connection, session
      setupPubSub();

      // Wait upto 5 seconds for the message
      //TopicSubscriber recv = session.createSubscriber(topic, new String("phone LIKE '%'"),false);
      TopicSubscriber recv = session.createSubscriber(topic, new String("phone like '%123%'"),false);


      Message msg = recv.receive(10000);
      if (msg == null) {
      System.out.println("Timed out waiting for msg");
      } else {
      System.out.println("TopicSubscriber.recv, msgt="+msg);
      }
      }

      public void stop()
      throws JMSException
      {
      conn.stop();
      session.close();
      conn.close();
      }

      public static void main(String args[])
      throws Exception
      {
      System.out.println("Begin TopicRecvClient, now=" +
      System.currentTimeMillis());
      TopicRecvClient client = new TopicRecvClient();
      client.recvSync();
      client.stop();
      System.out.println("End TopicRecvClient");
      System.exit(0);
      }

      }






        • 1. Re: Selector like operator don work ? It works with Webspher
          seleuco

          I have found the solution. Let me explaning it.

          The client classpath had the most obvious jar. all of them from the jboss client directory, jnp, jbosmq-client, etc ... but it is not obvious to put the regexp jar, which is in the jboss lib jar.

          I had to debug my client code against the jboss mq source to note that the class RegExp uses gnu.regexp.RE. The problem is that the constructor throws a exception (no classdeffound) that is catched by asynchDeliver from the conection class and hidden to me since i have not configured log4j in the client side.

          Thanks for all and i think jboss is the best app server since let me debug it :)