Business Process Execution Language for Web Services 2nd Edition
上QQ阅读APP看书,第一时间看更新

WS-Eventing

In a business process, a participating web service may be interested in receiving notifications whenever a certain type of event occurs in relation with other participating web services. A web service that is interested in such a notification should register its interest (subscribe) with other web services (event sources) where such events may be generated. The subscriber is called an event sink. The WS-Eventing specification allows you to create and delete event subscriptions. An expiration time may be set for each subscription. A subscriber may renew or unsubscribe its subscription with the event source.

All these requests are performed by sending an appropriate message to the event source. The WS-Eventing specification defines the message format for achieving this. Like the other specifications we discussed, this specification also relies on other service specifications for secure, reliable, and transacted message delivery.

Event Subscription

An event sink subscribes to an event source by using the following message format:

<s:Envelope ...>
  <s:Header ...>
      <wsa:Action>
        http://schemas.xmlsoap.org/ws/2004/01/eventing/Subscribe
      </wsa:Action>
    <wsa:MessageID>
            xs:anyURI
    </wsa:MessageID>
    <wsa:FaultTo>
           endpoint-reference
    </wsa:FaultTo> ?
    <wsa:ReplyTo>
            endpoint-reference
    </wsa:ReplyTo>
    <wsa:To>
            xs:anyURI
    </wsa:To>
    ...
  </s:Header>
  <s:Body ...>
        <wse:Subscribe ...>
          <wse:NotifyTo>
                          endpoint-reference
          </wse:NotifyTo>
          <wse:EndTo>
                          endpoint-reference
          </wse:EndTo> ?
          <wse:Expires>
            [xs:dateTime | xs:duration]
          </wse:Expires> ?
          <wse:Filter Dialect=”xs:anyURI”? > 
                          xs:string 
          </wse:Filter> ?
          ...
        </wse:Subscribe>
  </s:Body>
</s:Envelope>

In the message header, the Action element indicates an interest in subscribing to an event. The ReplyTo defines the endpoint reference for a reply message and the To element defines the URI for the event source. The <wse:subscribe> element defines the subscription information. The NotifyTo element defines the endpoint reference where the notification messages are to be sent. The EndTo defines a URI where the message is sent whenever the subscription ends. The Expires element defines the requested expiration time for the subscription. The event source may provide the filtering of notification messages. The event source uses the values specified in the Filter element while generating a response or a fault message to the event sink.

Response to Event Subscription

The event source sends a message to the event sink on receipt of a request for subscription using the following format:

<s:Envelope ...>
  <s:Header ...>
    <wsa:Action>
      http://schemas.xmlsoap.org/ws/2004/01/eventing/SubscribeResponse
    </wsa:Action>
    <wsa:RelatesTo>
            xs:anyURI
    </wsa:RelatesTo>
    <wsa:To>
            xs:anyURI
    </wsa:To>
       ...
  </s:Header>
  <s:Body ...>
    <wse:SubscribeResponse ...>
      <wse:Id>
                xs:anyURI
    </wse:Id>
    <wse:Expires>
      [xs:dateTime | xs:duration]
    </wse:Expires>
       ...
    </wse:SubscribeResponse>
  </s:Body>
</s:Envelope>

The RelatesTo element specifies the value of the message ID of the corresponding request. <wse:Id> specifies the unique identifier created by the event source. The Expires element defines the expiry time for the subscription.

Subscription Renewal

An event sink sends a renewal request to the event sink using something like the following message format:

<s:Envelope ...>
  <s:Header ...>
    <wsa:Action>
      http://schemas.xmlsoap.org/ws/2004/01/eventing/Renew
    </wsa:Action>
    ...
  </s:Header>
  <s:Body ...>
    <wse:Renew ...>
      <wse:Id>xs:anyURI</wse:Id>
      <wse:Expires>[xs:dateTime | xs:duration]</wse:Expires> ?
      ...
    </wse:Renew>
  </s:Body>
</s:Envelope>

The Action element specifies that this is a renewal request. The <wse:Renew> element defines the renewal request.

Unsubscribing

An event sink may unsubscribe for an event by sending a message to the event source using the following message format:

<s:Envelope ...>
  <s:Header ...>
    <wsa:Action>
      http://schemas.xmlsoap.org/ws/2004/01/eventing/Unsubscribe
    </wsa:Action>
    ...
  </s:Header>
  <s:Body>
    <wse:Unsubscribe ...>
      <wse:Id>
 xs:anyURI
      </wse:Id>
    ...
      </wse:Unsubscribe>
  </s:Body>
</s:Envelope>

In the Action element, the interest to unsubscribe for an event is specified. The <wse:Unsubscribe> element specifies the subscription ID.

Subscription End Message

Whenever the subscription ends, the source sends a notification to the endpoint reference using following message format:

<s:Envelope ...>
  <s:Header ...>
    <wsa:Action>
      http://schemas.xmlsoap.org/ws/2004/01/eventing/SubscriptionEnd
    </wsa:Action> ?
    <wse:SubscriptionEnd s11:mustUnderstand=”xs:boolean” ?
                         s12:mustUnderstand=”xs:boolean” ?
                         ...>
      <wse:Id>
 xs:anyURI
      </wse:Id>
      <wse:Code>
        [wse:Unsubscribed | wse:Expired | wse:NotifyToFailure |
         wse:SourceCanceling]
      </wse:Code>
      <wse:Reason xml:lang=”language identifier” >
 xs:string
      </wse:Reason> ?
    ...
    </wsa:SubscriptionEnd>
    ...
  </s:Header>
  <s:Body ...>
    ...
  </s:Body>
</s:Envelope>

The Action element indicates that the subscription has ended. The event source specifies the reason for ending the subscription in the Code element. The Unsubscribed value indicates the acceptance of an unsubscribe request from the event sink. The Expired value indicates that the subscription has not been renewed and is now expired. The NotifyToFailure value indicates that the source terminated the subscription because it is not able to deliver the notifications to the URI specified in the NotifyTo element of the request. The SourceCanceling value indicates that the source terminated the subscription before it expired.

With the help of the above message formats, an infrastructure for notifying events between web services is made available to developers.