Displaying Message Selectors Indexing Topic Subscriber Message Selectors To Optimize Performance

6-30 Programming JMS for Oracle WebLogic Server The following example shows how to retrieve the name of the second item in the previous example. This method call returns the string, Mitre Saw. String sel = JMS_BEA_SELECTxpath, orderitem[2]nametext = Mitre Saw; Pay careful attention to the use of double and single quotes and spaces. Note the use of single quotes around xpath, the XML tab, and the string value. The following example shows how to retrieve the ID of the third item in the previous example. This method call returns the string, 66. String sel = JMS_BEA_SELECTxpath, orderitem[3]idtext = 66;

6.9.3 Displaying Message Selectors

You can use the following MessageConsumer method to display a message selector: public String getMessageSelector throws JMSException This method returns either the currently defined message selector or null if a message selector is not defined.

6.9.4 Indexing Topic Subscriber Message Selectors To Optimize Performance

For a certain class of applications, WebLogic JMS can significantly optimize topic subscriber message selectors by indexing them. These applications typically have a large number of subscribers, each with a unique identifier like a user name, and they need to be able to quickly send a message to a single subscriber, or to a list of subscribers. A typical example is an instant messaging application where each subscriber corresponds to a different user, and each message contains a list of one or more target users. To activate optimized subscriber message selectors, subscribers must use the following syntax for their selectors: identifier IS NOT NULL where identifier is an arbitrary string that is not a predefined JMS message property e.g., neither JMSCorrelationID nor JMSType. Multiple subscribers can share the same identifier. WebLogic JMS uses this exact message selector syntax as a hint to build internal subscriber indexes. Message selectors that do not follow the syntax, or that include additional OR and AND clauses, are still honored, but do not activate the optimization. Once subscribers have registered using this message selector syntax, a message published to the topic can target specific subscribers by including one or more identifiers in the messages user properties, as illustrated in the following example: Set up a named subscriber, where wilma is the name of the subscriber and subscriberSession is a JMS TopicSession. Note that the selector syntax used activates the optimization. TopicSubscriber topicSubscriber = subscriberSession.createSubscriber Topiccontext.lookupIMTopic, Wilma IS NOT NULL, noLocal= true; Managing Your Applications 6-31 Send a message to subscribers Fred and Wilma, where publisherSession is a JMS TopicSession. Subscribers with message selector expressions Wilma IS NOT NULL or Fred IS NOT NULL will receive this message. TopicPublisher topicPublisher = publisherSession.createPublisher Topiccontext.lookupIMTopic; TextMessage msg = publisherSession.createTextMessageHi there; msg.setBooleanPropertyFred, true; msg.setBooleanPropertyWilma, true; topicPublisher.publishmsg;

6.10 Sending XML Messages