Chapter 12: Implementing the PublishSubscribe Pattern


Overview

The observer pattern is pervasive in object-oriented computing and continues to make inroads with Web Services. In some schools of thought, the Publish/ Subscribe pattern is synonymous with the Observer pattern, being essentially different terms for the same pattern. Other schools of thought treat the Publish/ Subscribe pattern as slightly different in nature and more in line with some more robust event patterns, such as the Event Channel pattern that is a part of the Common Object Request Broker Architecture (CORBA). CORBA's Event Channel pattern is a distributed computing pattern using proxies on both sides of a single event service. The service receives events from proxies and delivers events to proxies that register an interest for particular events. In this book, the Publish/ Subscribe pattern is a subtle, but important, extension of the Observer pattern and a subset of the more robust Event Channel pattern. This book does not discuss the Event Channel pattern further. If you would like to learn more about the Event Channel pattern, you can locate the specification at the Object Management Group (OMG) Web site (http://www.omg.org).

The Publish/Subscribe pattern illustrates some interesting aspects of Web Services:

  • The ability to offer generic, utility-based Web Services that any client and service implementation can leverage

  • The ability to use a third-party Web Service to enhance the communication between two other Web Services

  • The ability to facilitate notifications between Web Services without adding a mechanism and interface to the Web Service that is implementing the business behavior

Primarily, using a Publish/Subscribe pattern implies the usage of a dedicated Web Service for receiving and distributing events. One Web Service receives events from an application and distributes those events to interested parties. Web Services, by definition, are small, self-contained application components with low cohesion to other Web Services. By abstracting out the event handling to another Web Service, you start creating a whole network of related Web Services, which is contrary to the direction of Web Services as self- contained applications.

On the other hand, there are distinct possibilities for generalized, stand- alone event services that follow the Publish/Subscribe pattern. For example, a simple, generic, event service can sit on a network and service an arbitrary number of customers. The event service implemented in this chapter does not require any modification to facilitate Web Services using it as an intermediary. The service allows registration and posting of any event topic.

You could use the Publish/Subscribe pattern as an alternative mechanism to the Observer pattern for notifying clients of changes to Web Services throughout the P.T. Monday Coffee Company application. The Publish/Subscribe pattern offers several strengths over the Observer pattern in addition to its ability to simply replace the Observer pattern. One strength of publish/subscribe is its ability to send events that are not related to a particular Web Service. This opens up your event strategy to additional event types, such as the ability to publish an event relating to an internal system state without having it associated with a special System Web Service with which observers would have to register. Consider the differences between the Event Monitor pattern, the Observer pattern, and the Publish/Subscribe pattern implemented in this book. In most cases, one of these will fit any type of event that your Web Services may be interested in or interested in communicating.




Web Service Patterns
Web Services Patterns: Java Edition
ISBN: 1590590848
EAN: 2147483647
Year: 2003
Pages: 190

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net