• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

JMS queue problem

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a JMS Queue in My jboss.

Now from my standalone Java class I send message (in the XML format )to the queue.

as queue is used for P2P communication.So there should be a dedicated listener to that queue to get the message.

If I have more than 2 listeners to that Queue, Can It be possible to send the message to a particular Listener Based on the Message Content?
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm promoting this topic to the intermediate forum.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried message selectors?

-Medha
 
shankha bhattacharya
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes I tried it and able to solve it.


Code sample : message to queue.
--------------------------------
try {
Context ctx = new InitialContext(env);

/* ctx = new InitialContext(); */
cf = (QueueConnectionFactory) ctx.lookup("/ConnectionFactory");
destination = (Queue) ctx.lookup("queue/testQueue");
connection = cf.createQueueConnection();
session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
sender = session.createSender(destination);
message = session.createTextMessage();

String name ="shankha1";

message.setText("Hello World --- --- --- "+name);
//message.setJMSType("COMMUNICATOT");

message.setStringProperty("COMMUNICATOR",name);
System.out.println("Sending Message.");
sender.send(message);

connection.close();
System.out.println("Done.");
}
catch (NamingException e) {

e.printStackTrace();
}

catch (JMSException e) {

e.printStackTrace();
}

Code sample : Queue to message
-------------------------------
Context ctx = new InitialContext(env);
cf = (QueueConnectionFactory) ctx.lookup("/ConnectionFactory");
destination = (Queue) ctx.lookup("queue/testQueue");

connection = cf.createQueueConnection();
session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
connection.start();
//String selector = "to = '" + System.getProperty("user.name") + "'";

String selector="COMMUNICATOR='shankha1'";
receiver = session.createReceiver(destination,selector);

System.out.println("Waiting For A Message. QueueToMessage ");
//connection.start();
message = (TextMessage) receiver.receive();
 
You had your fun. Now it's time to go to jail. Thanks for your help tiny ad.
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic