Rather than receiving all messages on a topic to which you have subscribed, your consuming application can use XML Path (XPath) selectors to filter the messages based upon the contents of each message. This content-based subscription gives you greater flexibility in defining the type of information that you want to receive, and your applications do not need to handle their own filtering. Performance is improved because messages that are not relevant are not sent unnecessarily from the server to the application.
The WS-Notification publish and subscribe messaging model is topic-based. Each publication is classified as belonging to one of a fixed set of topics. Publishers label each publication with a topic name and consumers subscribe to all publications on a particular topic. For example a stock trading notification system might define a topic for each issue: Publishers post information labeled with the appropriate issue as the topic name, and subscribers subscribe to information regarding some issue.
(issue="IBM") and (price<120) and (volume>1000)
You code your XPath 1.0 message content filters in the subscribing applications, by using XML Path (XPath) language, Version 1.0..
To filter the message content of publications by using XPath selectors, complete the following steps.
This example XML code illustrates message content filtering by using XPath selectors. In this example a business, represented by a NotificationConsumer application, wants to be notified of bank transfers of over $1,000,000. The monitoring application subscribes on behalf of the NotificationConsumer specifying a valid XPath Version 1.0 message content filter, in the following WS-Notification subscribe message:
<wsnt:Subscribe>
<wsnt:ConsumerReference>
wsa:EndpointReference
</wsnt:ConsumerReference>
<wsnt:Filter>
[ <wsnt:TopicExpression Dialect="xsd:anyURI">
{any} ?
</wsnt:TopicExpression> |
<wsnt:ProducerProperties Dialect="xsd:anyURI">
{any} ?
</wsnt:ProducerProperties> |
<wsnt:MessageContent Dialect="xsd:anyURI">
/bankTransfer[value %gt; 1,000,000]
</wsnt:MessageContent> |
{any} *
] *
</wsnt:Filter> ?
<wsnt:InitialTerminationTime>
[xsd:dateTime | xsd:duration]
</wsnt:InitialTerminationTime> ?
<wsnt:SubscriptionPolicy>
[ <wsnt:UseRaw/> |
{any}
] *
</wsnt:SubscriptionPolicy> ?
{any}*
</wsnt:Subscribe>
The WS-Notification service stores the subscription and its filter.
Another WS-Notification application then publishes a notification in which the message body contains the following information:
<bankTransfer origin="123456 87654321" target="224466 88664422">
<originName>IBM Corporation</originName>
<targetName>Matt Roberts</targetName>
<date>02/02/2006</date>
<value currency="USD">100,000,000</value>
</bankTransfer>
The WS-Notification service in the application server matches this publication to the earlier subscription and delivers the notification to the consumer specified in the subscription.