|
|
YOUR FEEDBACK
SOA World Conference
Virtualization Conference $50 Savings Expire June 24, 2008... – Register Today! Did you read today's front page stories & breaking news?
SYS-CON.TV |
TODAY'S TOP SOA & WEBSERVICES LINKS Feature
A Publish/Subscribe Mechanism for Web Services
By: Dmitri Tcherevik
Digg This!
Software platforms traditionally offered a publish/subscribe mechanism as one of the core platform services. With help from this mechanism, an application could raise events or express interest in events produced by other applications. The Internet and Web services are emerging as the next generation platform for distributed applications. While the new platform enables applications to communicate synchronously or asynchronously over standard Internet protocols, it is still lacking a service that would resemble a traditional publish/subscribe mechanism. In this article, I'll show how such a service can be developed by extending the functionality of an existing framework. Background
![]() Let's take a minute to examine the types of communication taking place between the agents and the management applications. First, there is a stream of system status messages flowing from the agents to the management applications. Second, there is a stream of control messages flowing back from the management applications to the agents. The case of control messages is relatively straightforward. A control message has a well-defined source and a well-defined destination. Therefore, it can be delivered easily using a traditional, one-to-one request/reply protocol. All of the available RPC mechanisms, such as IIOP, Java RMI, COM, or SOAP-RPC, satisfy this requirement. The case of status messages is much more interesting. Messages sent by agents are caused by changes in the environment and are therefore asynchronous by nature. In addition, an agent sending a message is decoupled from the management application and rarely knows who will be receiving the message on the other end. Finally, there can be many management applications receiving messages from a single agent. Therefore, what we have here is an asynchronous one-to-many type of messaging that cannot be carried over a traditional RPC link. Instead, a publish/subscribe mechanism is required. This problem has been successfully solved in many products and middleware frameworks. Typically, it is addressed by introducing a stand-alone publish/subscribe service, sometimes called an event broker or an event intermediary. From the point of view of the event broker, the world is divided into two types of entities: event producers and event consumers. Event producers advertise event types and raise events by sending messages to the event broker. Event consumers express interest in events by registering event subscriptions with the event broker. The event broker matches the two parties by forwarding events sent by the producers to endpoints registered by the consumers. In the context of the management application described earlier, this can be seen in Figure 2.
![]() In addition to forwarding events, the event broker can implement a slew of useful functions such as event filtering, event logging, guaranteed event delivery, event correlation, protocol translation, and others. In this article, however, I'll focus not on the functionality of the event broker but on the communication mechanism used by consumers and producers to access its services. In particular, we want to understand what it would take to deploy an existing event broker on the Internet as a Web service that could be easily accessed by other Web services and applications. An Event Broker Overview Advertising Events A fragment of the catalog namespace tree is shown in Figure 3. The catalog namespace that is expanded corresponds to a file system event producer. The schema of this namespace contains three classes, the names of which are self-explanatory. Each class may have several properties describing the corresponding events, e.g. the file system path of the file, its MIME type, and others.
![]() Subscribing for Events The listener object implements the IEventListener interface defined as follows: public interface IEventListener When an event matching the filter is detected by the event broker, the handle Event() method of the listener object is invoked. It receives the event object as an argument. The event object contains properties describing the event. Sending Events I make no assumptions here about the mechanism used by event consumers and event producers to access services of the event broker. In this hypothetical example, they use these services by invoking methods of interfaces that are implemented by local or remote Java objects. In the next section we show how these interfaces can be mapped to a publish/subscribe Web service that can be easily invoked from a program written in essentially any programming language and running on practically any platform. Publish/Subscribe Web Service <soap:operation soapAction="uri" style="rpc"> is encoded as an RPC call while the body of a message sent to an operation declared as <soap:operation soapAction="uri" style="document"> is encoded and interpreted as an XML document. There are strict rules governing how parameters of an RPC request shall be encoded in the body of a SOAP message. Document-style encoding, on the other hand, is very nonrestrictive and allows virtually any type of XML documents. When flexibility or extensibility is desired, document-style encoding is generally preferred. Event broker methods used to manage event subscriptions are static in nature. Therefore, we can safely map them to operations with RPC encoding. The raise() method, on the other hand, is very dynamic. Event objects passed to this method are defined by classes stored in the catalog repository. We cannot afford to recompile an application every time someone adds a new event class to the catalog. Therefore, we choose document-style encoding for the raise() operation. Format of Event Messages The mapping is very simple. If the path of a catalog namespace is "Root/File System," then the URL of the corresponding XML namespace is "http://eventcentral.co m/Root/FileSystem". Properties of event objects are mapped to elements nested in the event element. All property values are encoded as strings. The original type of a property is indicated in the value of the "xsi:type" attribute. Event Processing The SOAPCodec.decodeEventList() method is used here to convert event objects from XML elements to Java objects that can be forwarded to the event broker runtime via a Java interface. Once we implement this portion of the service, we can compose some very interesting scenarios. Consider, for instance, the configuration presented in Figure 4.
![]() With the help of a servlet capable of processing events encoded as SOAP messages, we can build an event gateway that allows applications located outside of a company firewall to send events to subscribers deployed on the internal company network. When an outside application submits a SOAP message to the gateway, these subscribers will receive MQSeries, MSMQ, or JMS messages. Event Forwarding The publish/subscribe service is now virtually complete. Web-based applications can use it to send and receive events. In addition, it can play the role of a gateway translating event messages between SOAP/ HTTP and messaging protocols used on local networks such as MSMQ, MQSeries, or JMS (see Figure 5). Subscription management is the only building block that is still missing.
![]() Subscription Management Writing a WSDL contract by hand is not for the weak of heart, however. A typical WSDL document is written in cryptic XML and consists of many interrelated sections. It's easy to make a mistake while preparing it manually. Fortunately, most Web services development kits are capable of generating a WSDL contract from an interface defined in a conventional programming language such as Java or C#. We will take advantage of this capability and define the subscription management interface in Java as shown in Listing 6. An application can subscribe for events from the publish/subscribe service by submitting a collection of subscription objects. Every subscription object carries a number of properties: Implementation of the subscription management service is very straightforward. Once the communication stubs are generated with a WSDL compiler, the IEventManager interface can be implemented (see Listing 7). When a subscription request arrives from a Web client, we use its endpoint to create a new event listener object. We then register this listener object and the event filter provided as part of the subscription request with the event broker using a method of the broker's API. When an event matching the subscription criteria occurs in the system, the handleEvent() method of the event listener is invoked by the event broker. The method encodes the event in SOAP/XML and posts it to the endpoint provided by the subscriber. Conclusion The publish/subscribe service can be used in a large number of applications that require asynchronous one-to-many messaging: system monitoring and management, information replication, instant messaging, peer-to-peer computing, and others. SOA WORLD LATEST STORIES
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||