This example shows you how to send a message to an MDB that is configured to use a message selector
The example will send deploy a simple MDB and demonstrate sending a message and the MDB consuming only the message that matches the message selector.
Please refer to HornetQ Quickstart guide to install it in JBoss AS 5
To deploy and start the server, simply type ./build.sh deploy
(or build.bat deploy
on windows) from the example directory
To run the example, simply type ./build.sh
(or build.bat
on windows) from the example directory
To remove the example profile, simply type ./build.sh undeploy
(or build.bat undeploy
on windows) from the example directory
** make sure that JBOSS_HOME is set to the JBoss installation directory
jndi.properties
file in the directory config
initialContext = new InitialContext();
Queue queue = (Queue) initialContext.lookup("/queue/testQueue");
ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");
connection = cf.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer messageProducer = session.createProducer(queue);
TextMessage blueMessage = session.createTextMessage("This is a text message");
blueMessage.setStringProperty("color", "BLUE");
messageProducer.send(blueMessage);
TextMessage redMessage = session.createTextMessage("This is a text message");
redMessage.setStringProperty("color", "RED");
messageProducer.send(redMessage);
TextMessage tm = (TextMessage)message;
String color = textMessage.getStringProperty("color");
String text = tm.getText();
System.out.println("message " + text + " received color=" + color);
finally
block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
finally
{
if (initialContext != null)
{
initialContext.close();
}
if (connection != null)
{
connection.close();
}
}