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:
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”.
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:
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:
Last but not least a few notes for you to consider about EDN:
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.
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.
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
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,