Broker 10.5 | webMethods Broker Documentation | webMethods Broker Messaging Programmer's Guide | Coding Messaging Client Applications | JMS Request-Reply Application with a Message Selector | Application Code | Using a Message Selector
 
Using a Message Selector
The server application implements a message selector that filters messages based on a customer's geographical region. The message listener receives only messages where the customer region matches that specified by the selector.
Message selector values are specified in property fields in the message header. In this example, a "location" value specified in the requestor application represents such a property field in a customer request message:
msg.setStringProperty(AppConstants.LOCATION_PROPERTY, location);
You enter the message selector value (currentRegion) as a command line argument at server startup. If you enter a value of "All," the server receives a message irrespective of region (that is, message selection is disabled). If you enter the value of a valid region ("East" or "West"), the server enables message selection, allowing the listener to receive only messages from the specified region.
if (currentRegion.equals(AppConstants.ALL_REGIONS)) {
receiver = session.createConsumer(destination);
} else {
receiver = session.createConsumer(destination,
"location = ‘" + currentRegion + "’", false);
}
You specify the valid regions in determineRegion() in the server application.
private static String determineRegion(String regionName)
{
String region;
if (regionName.equalsIgnoreCase("East")) {
region = AppConstants.EAST_REGION;
} else if (regionName.equalsIgnoreCase("West")) {
region = AppConstants.WEST_REGION;
} else if (regionName.equalsIgnoreCase("All")) {
region = AppConstants.ALL_REGIONS;
...
return region;
}