Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Problem with jms Message Selector

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all..
Im so desperate..Can anyone of u help me sort this problem..i have a bean that uses the timer service.on the ejbtimeout..i create a topic publisher and send a message to a topic.(topic name and connection factory have been successfully looked up).im using a message selector (userID) on the message im sending. Only users that have that id are supposed to receive the message.

On my client,it implements the messagelistener interface..the users logs with his/her userID.
Even that, a user with a different id receives the message�..

Hope the code will stretch the picture out..


BEAN (omitting exceptions)

Public void ejbtimeout(Timer timer){

String id=�03048660�
outputMessage=getAlertMessage(id);
System.out.println("The message is:"+outputMessage);


//topicConnectionFactory = new com.sun.messaging.TopicConnectionFactory();

Context ctx=new InitialContext();
topic=(Topic) ctx.lookup("java:comp/env/jms/TopicName");


topicConnectionFactory=(TopicConnectionFactory) ctx.lookup("java:comp/env/jms/MyConnectionFactory");

/* Create the connection.../
topicConnection = topicConnectionFactory.createTopicConnection();
/* Not transacted Auto acknowledegement */

topicSession = topicConnection.createTopicSession(false,
Session.AUTO_ACKNOWLEDGE);


topicPublisher = topicSession.createPublisher(topic);
/*
* Non persistent delivery
*/
topicPublisher.setDeliveryMode(DeliveryMode.NON_PERSISTENT);


TextMessage msg=topicSession.createTextMessage();
msg.setText(outputMessage);
msg.setStringProperty("USERID",id);
topicConnection.start();

topicPublisher.publish(msg);

}


CLIENT:


Public class client extends MessageListener{

InitialContext ctx=new InitialContext();
topic=(Topic) ctx.lookup("java:comp/env/jms/TopicName");


TopicConnectionFactory=(TopicConnectionFactory) ctx.lookup("java:comp/env/jms/MyConnectionFactory");

topicConnection = topicConnectionFactory.createTopicConnection();
topicSession = topicConnection.createTopicSession(false,
Session.AUTO_ACKNOWLEDGE);
String filterProperty="USERID like '03048660' ";

topicSubscriber = topicSession.createSubscriber(topic,filterProperty,false);

topicSubscriber.setMessageListener(this);

topicConnection.start();



public void onMessage(Message message){
TextMessage msg=null;

try{
if (message instanceof TextMessage)
{
msg=(TextMessage)message;
System.out.println("Got Message:" + msg.getText());
JOptionPane.showMessageDialog(getContentPane(),msg.getText(),"Alert Service",JOptionPane.INFORMATION_MESSAGE);

}

}

catch(Throwable te){
te.printStackTrace();
}

}


}

When I run the program with ID :03048660, the expected output is obtained. the user receives the message.
But when I run (side by side) another instance of the same program with a different id, that user also receives the message..(although he is not supposed to receive it koz his ID is not 03048660)

Isnt the message filter working???plz help me
reply
    Bookmark Topic Watch Topic
  • New Topic