Selector like operator don work ? It works with Websphere bu
seleuco Nov 12, 2005 2:19 PMWe 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);
}
}