Oracle 11g SOA Suite – The Event Delivery Network – part 2- Subscribing to and Consuming Business Events

Events are an important element of SOA infrastructures. Events carry information between SCA Components – without direct dependencies or interaction between these components. Events are published by components in a fire-and-forget style into the Event Delivery Network. This EDN will make the events available to any subscribers to the event. These subscribers for now are all Mediator components. If no subscribers are found, the event goes nowhere from the EDN. That’s life in an Event Driven Architecture.

The Event Type NewEmployee was introduced in the article Oracle 11g SOA Suite – The Event Delivery Network – Publishing Business Events. This event is published by the ReadNewEmployees Mediator Component:

Oracle 11g SOA Suite - The Event Delivery Network - part 2- Subscribing to and Consuming Business Events edaevents047

....
 

The payload of the event is defined by the NewEmployee element:

Oracle 11g SOA Suite - The Event Delivery Network - part 2- Subscribing to and Consuming Business Events edaevents044

When a new employee document arrives, it is read and processed leading to a database record – as described in the article Oracle 11g SOA Suite – Straightforward Mediator example (employees from file to database) – and it is also turned into a Business Event, as is demonstrated by this audit trail:

Oracle 11g SOA Suite - The Event Delivery Network - part 2- Subscribing to and Consuming Business Events edaevents087

We will now create a Mediator Component that will subscribe to this Business Event. Instances of the Mediator Component are created upon consumption of the event.

In the Composite Editor, drag the Mediator Component to the central swimlane. In the Create Mediator dialog, specify the name for the Mediator, choose the Subscribe to Events template and select the NewEmployee event:

Oracle 11g SOA Suite - The Event Delivery Network - part 2- Subscribing to and Consuming Business Events edaevents092 

Press OK. The Composite editor is displayed:

Oracle 11g SOA Suite - The Event Delivery Network - part 2- Subscribing to and Consuming Business Events edaevents093

We will now create a new File Adapter Service that will write a new personnel file for the new employee from the NewEmployee event to the c:\temp\personnelfiles directory.

Oracle 11g SOA Suite - The Event Delivery Network - part 2- Subscribing to and Consuming Business Events edaevents060

Let’s quickly walk through the File Adapter Service wizard:

Oracle 11g SOA Suite - The Event Delivery Network - part 2- Subscribing to and Consuming Business Events edaevents061

Oracle 11g SOA Suite - The Event Delivery Network - part 2- Subscribing to and Consuming Business Events edaevents062

 

 Oracle 11g SOA Suite - The Event Delivery Network - part 2- Subscribing to and Consuming Business Events edaevents064

 

Oracle 11g SOA Suite - The Event Delivery Network - part 2- Subscribing to and Consuming Business Events edaevents065

Oracle 11g SOA Suite - The Event Delivery Network - part 2- Subscribing to and Consuming Business Events edaevents069

 Oracle 11g SOA Suite - The Event Delivery Network - part 2- Subscribing to and Consuming Business Events edaevents070

 

Oracle 11g SOA Suite - The Event Delivery Network - part 2- Subscribing to and Consuming Business Events edaevents071

Press Next, Press Finish, Accept  further defaults and press Next and Finish where available.

Wire this File Adapter Service to the ConsumeNewEmployeeEvent Mediator Component. Then double click the Mediator Component, expand the Routing Rule and click on the Mapping icon.

Oracle 11g SOA Suite - The Event Delivery Network - part 2- Subscribing to and Consuming Business Events edaevents077

The mapping file needs to be created ‘manually’ in the source view: the NewEmployee Event is known as an AnyType – therefore the visual mapper does not  do it for us.

The XSLT we need to create the XML document required by the File Adapter Service to write the New Personnel file looks like this, retrieving the required values from the NewEmployee event payload:

Oracle 11g SOA Suite - The Event Delivery Network - part 2- Subscribing to and Consuming Business Events edaevents080

With the Mapping done, we can deploy the Composite to the SOA runtime.

 

 

Copying a new employee file to the c:\temp\hr directory, we start off a new instance of the ReadNewEmployee Composite. That instance publishes a NewEmployee event that the EDN will hand over to the ConsumeNewEmployeeEvent Mediator Component. 

This Instances overview for the ConsumeNewEmpEvent component shows the consumption of the event:

Oracle 11g SOA Suite - The Event Delivery Network - part 2- Subscribing to and Consuming Business Events edaevents089 

The Audit Trail for the instance :

Oracle 11g SOA Suite - The Event Delivery Network - part 2- Subscribing to and Consuming Business Events edaevents090

It is clear that the instance was instantiated because of the Business Event. It then delivered the Event payload into the File Adapter Service that will write out the personnel file.

We can see the result of this instance on the file system, as the ConsumeNewEmpEvent Mediator Component has created a new personnel file in the personnel directory:

Oracle 11g SOA Suite - The Event Delivery Network - part 2- Subscribing to and Consuming Business Events edaevents083

The contents of this file:

Oracle 11g SOA Suite - The Event Delivery Network - part 2- Subscribing to and Consuming Business Events edaevents084

Summary

In two prequels to this article we have seen how we can define a Business Event Type in the context of the Oracle 11g SOA Suite and how we can publish events of that type in Mediator Components. In this article, we see how a Mediator Component can register itself as subscriber to a Business Event type. Such Component are then instantiated by the Event Delivery Network when the events for which they registered occur.

In this way, an event in one Component indirectly instantiates a completely different Component. That is loosely coupling for you – without even knowing about each other and only a dependency on the Event (type), these two Components seem to collaborate.

4 Comments

  1. Oracletube.com March 11, 2010
  2. dominique debailleux March 27, 2008
  3. Andre Broers March 26, 2008
  4. Harald Reinmueller March 26, 2008