Pages

Monday, May 5, 2008

Events in ADF BC and handled by the Soa Suite Mediator

You may already know that events plays an important role in Soa Suite 11g. In this blog entry I will show how you can raise events in your ADF JSF application with ADF BC ( BC4J). These events can be intercepted by a mediator of soa suite 11g and this mediator can start other processes. In my case I publish these events to a file. I hope with this blog you get an inside look how events works.
The first step is to configure the entity in BC4J for events. In this example I use the customer table of the oe schema. On this entity I add a CreditLimit event which fires for every customer insert or update. To this event I add two customers attributes, The customerId and the creditlimit( BC4J adds automatically the old and new value of these attribute ).
BC4J generates a edl and a schema file. Here are an example of the generated files

<?xml version = '1.0' encoding = 'UTF-8'?>
<definitions
targetNamespace="/nl/ordina/events/model/businessobjects/events/edl/Customers"
xmlns:ns0="/nl/ordina/events/model/businessobjects/events/schema/Customers"
xmlns="http://schemas.oracle.com/events/edl">
<schema-import
namespace="/nl/ordina/events/model/businessobjects/events/schema/Customers"
location="Customers.xsd"/>
<event-definition name="CreditLimit">
<content element="ns0:CreditLimitInfo"/>
</event-definition>
</definitions>

The customer schema

<?xml version = '1.0' encoding = 'UTF-8'?>
<xs:schema
targetNamespace="/nl/ordina/events/model/businessobjects/events/schema/Customers"
xmlns="/nl/ordina/events/model/businessobjects/events/schema/Customers"
elementFormDefault="qualified"
attributeFormDefault="unqualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="CreditLimitInfo">
<xs:complexType>
<xs:sequence>
<xs:element name="CustomerId" type="DecimalValuePair" minOccurs="1"/>
<xs:element name="CreditLimit" type="DecimalValuePair" minOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="ValuePair" abstract="true"/>
<xs:complexType name="DecimalValuePair">
<xs:complexContent>
<xs:extension base="ValuePair">
<xs:sequence>
<xs:element name="newValue" minOccurs="0">
<xs:complexType>
<xs:complexContent>
<xs:extension base="xs:anyType">
<xs:attribute name="value" type="xs:decimal"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
<xs:element name="oldValue" minOccurs="0">
<xs:complexType>
<xs:complexContent>
<xs:extension base="xs:anyType">
<xs:attribute name="value" type="xs:decimal"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>

Let's make a JSF page on this entity and publish this application to the Soa suite server. If you don't do this I don't believe the events will be intercepted by the mediator.
Now we have to patch two procedures in the soasuite schema ( JDev TP4). The first procedure is edn_dequeue_bus_event, we have to change the schema name with your own soasuite schema do this before the queue name DBMS_AQ.dequeue(queue_name=>'xxxxx.edn_event_queue'. The same but now for procedure edn_enqueue_business_event DBMS_AQ.enqueue(queue_name=>'xxxxx.edn_event_queue'
The events are enqueued in the following queue edn_event_queue. This queue is located in your own soasuite schema. The published event looks like this.

<business-event
xmlns:ns="/nl/ordina/events/model/businessobjects/events/edl/Customers"
xmlns="http://oracle.com/fabric/businessEvent">
<name>ns:CreditLimit</name>
<id>30b14edf-f366-4091-97e8-3b6a2d514116</id>
<content>
<CreditLimitInfo xmlns="/nl/ordina/events/model/businessobjects/events/schema/Customers">
<CustomerId>
<oldValue value="148"/>
<newValue value="148"/>
</CustomerId>
<CreditLimit>
<oldValue value="1700"/>
<newValue value="1100"/>
</CreditLimit>
</CreditLimitInfo>
</content>
</business-event>

If I manually dequeue this queue the result looks like this.

We are ready with ADF and now we can go to the soa suite part. We create a new soa suite project where we add a mediator. Select now the Subscribe to events template. and browse to the customer.edl which is located in the bc4j model project.

In my case I add a file adapter and connect this file adapter to the mediator.

The last step is to make a stylesheet mapping between the mediator and the file adapter.

The events are now stored in a file. I hope you got a good impression how it works. In the next blogs I will continu this story by adding the CEP soa suite component and BAM j2ee edition to this example

2 comments:

  1. Thanks for the detailed steps. Can you answer a few questions?

    1. My ADF application is deployed on a separate WLS instance and SOA is running on a seperate instance. How will the event triggered on the ADF instance be propagated to SOA instance?

    2"Let's make a JSF page on this entity and publish this application to the Soa suite server. If you don't do this I don't believe the events will be intercepted by the mediator." this point u have mentioned is unclear.

    ReplyDelete
  2. Hi Sandeep,

    you are absolutely right you need to setup an edn network.

    Deliver all messages to soa infra queue or setup jms forwarding to the soa suite server.

    Too bad I don't see so many documentation on this.

    but I will check it out

    thanks

    ReplyDelete