Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

JMS queue problem  RSS feed

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • 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
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm promoting this topic to the intermediate forum.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried message selectors?

-Medha
 
shankha bhattacharya
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • 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();
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!