This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JMS queue problem

 
shankha bhattacharya
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?
 
marc weber
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.
 
Medha Jhunjhunwala
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();
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic