WAS v8.5 > Develop applications > Develop web services - Notification (WS-Notification) > Develop applications that use WS-Notification

Filtering the message content of publications

Rather than receiving all messages on a topic to which we 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 to receive, and the 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.

We can use XPath selectors to filter messages for a given topic, using a Boolean expression that is evaluated over the XML message content of the message body. For example, a subscriber to a topic-based publish and subscribe system for stock trading might use XPath selectors to specify constraints against three message attributes at the same time:

The resultant Boolean statement might be as follows:

You code your XPath 1.0 message content filters in the subscribing applications, using XML Path (XPath) language, v1.0..

If wer subscriber applications use message content filtering, and are coded to specify the XPath v1.0 SelectorDomain, they can also filter publications from other WS-Notification providers that are of type JMS TextMessage or BytesMessage. For more information about these JMS message types, see Topology for WS-Notification as an entry or exit point to the service integration bus.

To filter the message content of publications using XPath selectors, complete the following steps.

  1. Create a new application that subscribes a WS-Notification consumer.
  2. Code an XPath message content filter in the subscribing application. For example code for doing this, see Example: Subscribing a WS-Notification consumer. For an example of message content filter usage, see the example at the end of this task.
  3. Code error handling for cases where the filter is not valid.
  4. Invoke the application.


Example

This example XML code illustrates message content filtering 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 v1.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:

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.


Related concepts:

WS-Notification
WS-Notification: Overview
WS-Notification: Supported bindings


Related


Writing a WS-Notification application that exposes a web service endpoint
Writing a WS-Notification application that does not expose a web service endpoint
Example: Subscribing a WS-Notification consumer
Example: Pausing a WS-Notification subscription
Example: Publishing a WS-Notification message
Example: Creating a WS-Notification pull point
Example: Getting messages from a WS-Notification pull point
Example: Registering a WS-Notification publisher
Example: Creating a Notification consumer web service skeleton
Use WS-Notification for publish and subscribe messaging for web services
Secure WS-Notification
Develop applications that use WS-Notification


Reference:

WS-Notification troubleshooting tips

WS-BaseNotification v1.3 OASIS Standard

XML Path Language (XPath) v1.0

XQuery 1.0 and XPath 2.0 Formal Semantics


+

Search Tips   |   Advanced Search