Creating truly decoupled composite SOA applications requires a complete separation of the service consumer and the service provider.This is typically achieved through the use of asynchronous messaging.In an asynchronous messaging pattern, applications can perform in a"fire and forget" mode. This removes the need of an application to know details of the application on the other side. Additionally, it also improves resource utilization as applications are not holding onto resources until the interaction is complete. On the other hand, this introduces complexities of creating and managing message queues and topics. It requires that both the publisher of the message and the consumer use the same messaging technology. Each messaging system also has its own constraints on the types of programming languages and environments that can use the service.
In a service-oriented world, this tight coupling to the implementation of the underlying messaging system is at odds with the fundamental requirement of implementation independence. What's needed is a level of abstraction that allows applications to generate an event using business terms and associate a business object in an implementation‑independent form.
Oracle SOA Suite 11g addresses this with the introduction of anew feature in the form of the Event Delivery Network.
The Event Delivery Network (EDN) in Oracle SOA Suite 11g provides a declarative way to use a publish/subscribe model to generate and consume business events without worrying about the underlying message infrastructure.
Developers only need to produce or consume events without having to deal with any particular messaging API like JMS, AQ, and MQ, and so on. Consuming an event means expressing an interest in the occurrence of a specific situation,while producing an event means advertising this occurrence.
Using the same concepts that are used in Web Service Definition Language (WSDL), EDN uses an XML-based Event Definition Language, which allows you to define the event and its associated,strongly typed data. This definition is then registered with the SOA Infrastructure and is available to all composites to publish or subscribe.
WSDL:Standard service interface model
JMS API:Application Programming Interface
EDL:Event Definition Language
Handful of raw types
Wealth of tools
Mostly coding tools
This allows for a fully-declarative, business-oriented, rather than developer-oriented approach for using events in a SOA application.
Another feature of EDN is the ability to publish and subscribe to these events from a variety of programming environments such as Java, PL/SQL, SOA Composites, and ADF-BC applications.
With EDN, Oracle has fostered the concept of events in the context of SCA, and this has given birth to an additional SCA specification:the "Assembly Model Specification Extensions for Event Processing and Pub/Sub". Since EDN in Oracle SOA Suite 11g predates the specification, you will find differences in the details, but the concepts are the same and EDN will eventually be aligned with the standard that emerges from the specification.
Creating and managing event definitions
Events are defined using an Event Definition Language (EDL),an XML schema used to build business event definitions. An EDL consists of the following:
- A global name.
- Custom headers: These can be used for content-based routing without having to parse the XML payload and apply XPath queries to get at the value to be used for the routing decisions. For instance, one can put the purchase order type in the custom header. This easily accessible custom header could then be used to efficiently decide how to process delivered events.
- Payload definition: Typically this is an XML schema for the business data that needs to accompany the event. For example, a "NewPO"event's payload definition will be a schema for a purchase order.
Event definitions can be created declaratively in JDeveloper in a couple of different ways depending on triggering conditions.
To publish events from a SOA composite, one would create new event definitions and register them with the SOA Infrastructure. It is this option that you will be able to try out later in this article during the hands-on exercise.
If you want to raise events on one or more database operations such as insertion of a new row or update of an existing one, you can use ADF-BC to define these events. ApplicationDevelopment Framework(ADF), a model-view-controller pattern based UI development framework for creating Rich Internet Applications (RIAs) and BusinessComponents(BC), an object-relational mapping tool, provide an easy way to define events. ADF-BC has built-in support for associating these events with database actions like insert, delete, and modify. For example, an event called "NewCustomerAdded" could be generated every time a new customer record is inserted into the database.
Registered events, their subscribers, and any faulted deliveries can all be tracked and monitored using the Oracle Enterprise Manager, in the same fashion that you would be managing and monitoring other aspects of your SOA infrastructure.
Consuming events from the Event Delivery Network
The first step to consume an event is to discover its definition. Event definitions can be stored locally in a composite or globally on the server—in either case, they can be discovered through the JDeveloper resource catalogue.
To subscribe to an event within an SOA composite application,you start by defining a Mediator component, selecting the event of interest from a list of registered events in the network.
To further refine a subscription, and narrow down the information you will receive, you can define an XPath-based filter on your subscriptions. For example, for an event named "NewPOCreated", you could either subscribe to all "NewPOCreated" events (default when no filter is defined) or only those where the order amount is more than a million dollars (by defining an XPath-based filter on the order amount field within the payload).
Tutorial: Use of Event Delivery Network (EDN) and POProcessing
Let's try out a simple EDN use case. We will extend a POProcessing example.
In order to follow the tutorial in this article you must have installed the product and learned how to use the WebLogic console to configure the JMS adapter and define queues and connection factories.
To illustrate the usage of events, you modify the existing POProcessing composite to accept new orders from two sources: the Web Service interface, which you have already implemented, and another application that will publish events to indicate new orders.
Modifying the composite to consume events
In this step, you modify the POProcessing composite to use EDN. You add a new mediator component called receivePO, which subscribes to an event called NewPO and sends the received PO to the routePO service.
Defining the event
- Open the POProcessing application in JDeveloper and open composite.xml,and click on the Event Definition Creation icon:
- In the Event Definition Creationwindow, enter POEvents as the name of the event definition. Accept the namespace value generated.
Event names are fully qualified names, which means the combination of a namespace and the event name together identify a unique event. For instance, the event called NewCustomerAdded with name space http://schemas.oracle.com/events/edl/POEvents is different than the event with the same name but under a different namespace, for example, event NewCustomerAdded with namespace http://schemas.oracle.com/event/edl/CRMEvents.
- Add a new event by clicking on the +icon.
- Select the PuchaseOrder element from the po.xsd file using the chooser.
- Enter NewPO as the name of the event and click on OK to close the Add an Eventwindow.
- Click on OK to complete the event definition.
- Close the POEvents.edl panel.
- Save all.
You have just created a new event called POEvent. It is now available to this and other composites to subscribe to or publish. Whenever this event is delivered,it will also carry with it a document for the new purchase order.
Subscribing to the NewPO event
- Drag-and-drop a Mediator component on to the composite.
- Name the mediator receiveNewPO.
- Select Subscribe to Events for the Template.
- Click on the + to add an event. Select the NewPO event from the Event Chooser window.
- Click on OK to accept and create the mediator.
- Save all.
- Connect the receiveNewPO mediator to the routePO mediator:
- Double-click on the receiveNewPO mediator and define a new transformation map. In the transformation-map, map the all the fields from the source to the target.
- Close the mediator and save all.
Deploying and testing
- Deploy the POProcessing composite tothe server.
- Browse to the EM console at http://localhost:7001/em.
- Right-click on folder soa-infra (soa_server1)under folder SOA:
- Click on item Business Events.
- You should see the Business Events management page with the NewPO event listed in the Events
- Select the event and click on the Test…button to publish the event.
- In the pop-up window, enter the following XML and click on Publish:
<productName>Sony Bluray DVD Player</productName>
- You should get a "The Event published successfully" message.
- Click on soa-infra in the navigation panel on the left to get the soa-infra dashboard.
- Click on the POProcessing composite to view new instances. You should see an instance created for processing the event you just published. Click on the instance ID to view the flowtrace.
This was just one way of publishing an event and will typically be used as away to test the composite. In most cases, the events will be published from a number of sources—from a Mediator, from PL/SQL by calling the EDN_PUBLISH_EVENT stored function or from a Java class using the EDNAPI. An ADF-BC application can also publish events based on database insert, update, and delete operations.
You cannot really build comprehensive SOA applications without business events. Traditionally, this requirement has been fulfilled by message-oriented-middleware(MOM). However, MOM-based solutions don't necessarily fit very well within a service-oriented architecture. They are low-level technical solutions that provide no business semantics, whereas one of the main objectives of creating services is to provide business functions using semantics that are better understood by business analysts.
With EDN, Oracle SOA Suite 11g fills this gap by providing an event-handling solution that allows creation and use of events using business semantics, without the publisher or subscriber of the event ever having to worry about the mechanics of messaging.
As you have seen in this short lab, events are created in away that directly maps to actual business events, in this case creation of a new purchase order. The process of subscribing to this event was done declaratively without having to configure any messaging queues or topics.