Friday, 25 January 2013

Event Delivery Network

Event Delivery Network allows publish-subscribe type of loose coupling between SCA components. This is similar to JMS/AQ model except that user is spared from remembering and using low level JMS connectivity details. Instead, SOA framework neatly abstracts these details in the Even Delivery Network so that users can purely focus on publishing and subscribing to events.
This approach is highly useful when an event publisher doesn’t know about the number or type of potential subscribers beforehand. Events can be published/subscribed from both as well as components.
In the present example, we will discuss about an event published from BPEL and subscribed by Mediator component. Mediator component shall write the event information to a File on SOA Server to make sure event subscription has successfully been processed.
image
Steps to implement above example:
Step 1. Publish Event using BPEL
Create an SOA project and name it EventDeliveryExample. Select “Composite with BPEL Process” template.
image
image
Create one-way BPEL process and name it EventPublisherProcess. Use following screenshot for other parameter values.
image
Import Order.xsd into the project and select orderDetails as Input element for the BPEL process. Click OK to complete project creation.
image
image
Open composite.xml and click on “Event Definition Creation” icon from top left corner of the window as shown below.
image
Specify “OrderEventDefinition” for EDL File Name.
image
Click on “+” icon in the Events section to create a new event. Select orderDetails element for Element field. Specify “OrderPublishingEvent” for Name field. Click on OK to add event.
image
Click OK from Event Definition dialog.
image
Open EventPublisherProcess from composite.xml. From Component Palette, drag and drop an Invoke activity on to BPEL process.
image
Open Invoke_1 activity. Specify “Invoke_Event” for Name field. Select “Event” as Interaction Type. For Event, select “OrderPublishingEvent” created in the previous steps. Create a new event input variable. Click OK to close Invoke activity.
image
image
Drag and drop an Assign activity. Assign BPEL input variable to event’s input variable.
image image
This completes Event publishing part using BPEL.
Step 2: Subscribe to Event using Mediator component.
Drag and drop a Mediator component on to Components pane in composite.xml. Specify “MediatorSubscriber” as Name. Select “Subscribe to Events” Template. Select “OrderPublishingEvent” from Event section.
image
Now Mediator component has successfully subscribed to OrderPublishingEvent.
image
Lets create a File Adapter to write file to SOA Server’s File System. Drag and drop a “File Adapter” on to “External References” pane.
From Adapter Configuration Wizard, click Next. Enter “OrderWriterService” for Service Name. Click Next and Next again. From Operation dialog, select “Write File” as Operation Type. Specify “WriteOrder” as Operation Name. Click Next.
image image
Enter appropriate Directory Name for Outgoing Files. Specify File Naming Convention as “Order_%SEQ%.txt”. This ensures Order file get a serial number suffix (Example: Order_1.txt, Order_2.txt). Click Next.
image
In Messages section, click on “Define Schema For Native Format” icon next to URL field. Click Next.
image image
Leave default values in “Choose Type” screen.
image
Save following text to Order.txt file and select this file for “File name” field.
ItemName,OrderType,PurchaseDate,FirstName,LastName,AddressLine1,AddressLine2,City,State,Zip,Country
CT,EXPRESS,2011-02-01,Josh,Roy,Flat 14 Sunrise Heights,12 Martin Road,London,Greater London,EXX 5XX,UK
image
Click Next and Next again. Enter appropriate names for Target Namespace. Specify OrderCollection and Order for multiple collection and single record elements respectively. Click Next and Next.
image
From Field Properties section, select “Use the first record as the field names”. Click Next. In the final step, give an appropriate name for generated schema and Finish.
image
From Messages section, click Next and Finish.
image
In composite.xml, wire MediatorSubscriber and OrderWriterService.
image
Double click on MediatorSubcriber. In Static Routing section, click on Transformation icon next to “Transform Using” field. Select “Create New Mapper File” and leave the default name. Click OK.
image
Click on orderDetails  in <sources> and drop on to OrderCollection element in <target>. Save All.
image
Finally, Deploy EventDeliveryExample project. Launch the process by specifying values in Test screen.
image
Order_1.txt should have been created in Outgoing File Directory with the values entered in above screen. This completes the implementation.
You can download the complete JDeveloper project from here.

No comments:

Post a Comment