Sunday, 25 September 2011

How to publish and subscribe using mediator

This project illustrate the example of publishing and subscribing through mediator. where publish project will invoke the subscribed project and will do the entry in database.
Step1:- Create a new Generic Application with any name
Step 2:- Then create one SOA project with empty Composite for publishing the event.

Step 3:- Drag mediator in component section of composite.xml and select the input customer.xsd
Create one customer.xsd using following entry:-
<schema xmlns="http://www.w3.org/2001/XMLSchema"
        targetNamespace="http://xmlns.oracle.com/ns/Customer"
        xmlns:cust="http://xmlns.oracle.com/ns/Customer"
        attributeFormDefault="qualified" elementFormDefault="qualified">

 <element name="Customer" type="cust:CustomerType"/>
 <complexType name="CustomerType">
    <sequence>
        <element name="customerId" type="string" />
        <element name="Name" type="string" />
        <element name="Age" type="integer" />
<element name="Address" type="string" />
<element name="State" type="string" />
<element name="Country" type="string" />
<element name="City" type="string" />
    </sequence>
</complexType>
</schema>
Step 4:-  Create one event using the same customer.xsd. Click on the create event flash icon

Step 5:- Click on the plus icon to select the customer.xsd


Step 6:- Now right click on the mediator and click the Add Publish Events and then select the .edl file of the created event  in the Event Chooser box.

Step 7:- Open mediator and click on the Transform icon and select the create new mapper radio button. Now  perform one to one mapping as shown below.
Step 8:- Now Create a new SOA project  inside same application with empty composite selected.
Step 9:- Drag n drop the mediator component and select  the subscribed to events template.Then click on the plus icon and select the same .edl  file inside the Event Chooser box.
Here we can notice Run as publisher whether to set it "no" or "yes". If we will set it as yes then all the security policies which are there in the publisher will be applicale to subscriber service as well.

Step 10:- Open mediator and click on the Transform icon and select the create new mapper radio button. Now  perform one to one mapping as shown below.
 
Step 11:- Then drag one BPEL process and choose the template as one way and select the input as customer.xsd.
Step 12:- Then drag one database adapter in Reference section of composite.xml

Step 13:- Enter the JNDI name as same created in my previous blog
Step 14:- select the operation insert as shown below then in next page click on the “Import Table” and then in the Query section dialogue search for the Customer table and Select it.


Step 15:- Then select one primary key as while creating table I didn’t define any primary key so this step will come for the tables where no primary key is defined.
Step 16:- Now drag the wire from mediator to bpel and from BPEL to Database Adapter.
Step 17:- Now open the Mediator Component and drag the transform and then invoke activity.
Step  18:- From invoke activity drag a wire for database adapter to define the partner link. Inside the partner link dialogue Click on the plus icon to create one input variable and select the default value and click ok.

Step 19:- Open the transformation activity and in the source section click the Plus icon and select the input variable and then in the target variable section select the input variable as of invoke activity. Then click on the plus icon in the Mapper File section to create one new xslt file.

Step 20:- Inside xslt file map the sections as below.
Step 21:- After deployment of both the Project. Now select the published one project and click on the test button. Fill all the mandatory field and click on the test web service button below.Now in the response section click on the Launch Flow Trace link and see the flow.
Then After testing the service check whether the data is updated in database table.

1 comment: