Follow Us on Twitter

Working with Business Events in SOA 11g

by Marcel Maas on November 5, 2009 · 2 comments

A nice new addition to OFM11g is the Event Delivery Network (EDN). This makes it possible to publish and subscibe to business events in a SOA composite application. In this post I will show you how to create a business event. We will use a simple case, the placing of an order and acting on it. Also, I assume you have a basic knowledge on creating SOA composites in JDeveloper 11g.

Firstly, we have to create a new empty SOA project in JDeveloper 11g. Now we create an xsd schema with the purpose of defining the event payload.

<?xml version="1.0" encoding="windows-1252" ?><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns="http://www.whitehorses.nl/schemas/order"
            targetNamespace="http://www.whitehorses.nl/schemas/order"
            elementFormDefault="qualified">
  <xsd:element name="order">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="product" type="xsd:string"/>
        <xsd:element name="cost" type="xsd:string"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

Now that we have created the payload it is necessary to create a new Event Definition. This results in a .edl file which describes all events in the current soa project. We create the definition by clicking the “lightning” icon in the design view of the composite.xml. When the “Event Definition Creation” dialog is displayed we create an event by clicking the “plus” icon. Here we select the “order” element by using the type chooser. For the name we choose “OrderPlacedEvent”. The dialog should now look as follows:

The Event Defintion Creation Dialog showing the single OrderPlacedEvent.

The Event Defintion Creation Dialog showing the single OrderPlacedEvent.

After clicking “Ok” you are taken to the events editor from which you can add / modify or delete events. For now we can close it.

Now we create a “one-way” mediator and expose it as a service. Lets call the mediator “PlaceOrderMediator”. For input we use the “order” element that can be found in order.xsd. After double-clicking the mediator we add a new static routing rule by clicking the “plus” icon in the routing rules section. As target type we choose “event”. The “Event Chooser” dialog appears. As you can see it will load the events from the OrderEvents.edl we have created. Make sure the OrderPlacedEvent is selected and click “Ok”. There will be no need to create a transformation map because the input of the mediator and the event are the same elements, namely “order”.

We now have a mediator which will publish the “OrderPlacedEvent”.

The mediator which publishes the event

The mediator which publishes the event

To subscribe to this event we will create a new mediator which in turn will write the order to a log file using a File adapter. I will only show how to subscribe to the event.

Drag a new mediator onto the composite. In the “Create Mediator” dialog choose “Subscribe to Events” as template. Now add the “OrderPlacedEvent” by clicking the “plus” icon. If you like you can set a filter here too. For example you could only react on the event when the “cost” is over 100. Give the mediator a sensible name and click “Ok”. We can now create a “File Adapter” and write the order to a file.

Your project should now look something like this:

The entire composite with a publishing and subscribing mediator

The entire composite with a publishing and subscribing mediator

Deploy the project to the SOA server and give it a test run. You should see a log file being written to your file system on the specified location. (You could get 2 warnings while compiling. To get rid of these you have explicitly create a transformation map for both the mediators)

The message trace looks like this:

The order trace.

The order trace.

Last but not least a few notes for you to consider about EDN:

1. Scope

When an event is published, it will be published in the entire domain. This means you can publish an event in one composite and subscribe to it in an other composite. You can subscribe to an event from another composite by browsing to its .edl file when adding the event to your mediator.

Browsing for the EDL File

Browsing for the EDL File

This also means it might be hard to find out how many subscribers to an event there are in your domain and in which composite to find them.

2. Consistency

You can play around with the consistency of the event when you subscribe to it. You can choose one of three:

  • One and Only one
  • Guaranteed
  • Immediate

The exact meaning of each of them can be found here. In essence it will controll the way the event is delivered (transaction  and error handling)

So be careful to which use you put your events. It would be a poor job if you have a Business Critical process subscribed to an event which doesn’t get invoked because another subscriber to the same event throws an exeption. (This could happen when you have selected “immediate” consistency)

That’s it for now!

Working with Business Events in SOA 11g, 5.0 out of 5 based on 4 ratings

Ratings:
VN:F [1.9.22_1171]
Rating: 5.0/5 (4 votes cast)

2 comments on “Working with Business Events in SOA 11g

  1. Manitosh on said:

    Hi Marcel,

    Well Explained.

    Thanks !!
    Manitosh

    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  2. Hi Marcel,

    Can you explain me the error handling for this event delivery network??
    Can we publish the event from one server and subscribe it from another???

    Thanks
    Harsh

    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

* Copy This Password *

* Type Or Paste Password Here *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

 

Previous post:

Next post:

About Whitehorses
Company profile
Services
Technology

Whitehorses website

Home page
Whitebooks
Jobs

Follow us
Blog post RSS
Comment RSS
Twitter