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 BPEL as well as Mediator 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.
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.
Create one-way BPEL process and name it EventPublisherProcess. Use following screenshot for other parameter values.
Import Order.xsd into the project and select orderDetails as Input element for the BPEL process. Click OK to complete project creation.
Open composite.xml and click on “Event Definition Creation” icon from top left corner of the window as shown below.
Specify “OrderEventDefinition” for EDL File Name.
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.
Click OK from Event Definition dialog.
Open EventPublisherProcess from composite.xml. From Component Palette, drag and drop an Invoke activity on to BPEL process.
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.
Drag and drop an Assign activity. Assign BPEL input variable to event’s input variable.
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.
Now Mediator component has successfully subscribed to OrderPublishingEvent.
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.
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.
In Messages section, click on “Define Schema For Native Format” icon next to URL field. Click Next.
Leave default values in “Choose Type” screen.
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
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.
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.
From Messages section, click Next and Finish.
In composite.xml, wire MediatorSubscriber and OrderWriterService.
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.
Click on orderDetails in <sources> and drop on to OrderCollection element in <target>. Save All.
Finally, Deploy EventDeliveryExample project. Launch the process by specifying values in Test screen.
Order_1.txt should have been created in Outgoing File Directory with the values entered in above screen. This completes the implementation.
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 BPEL as well as Mediator 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.
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.
Create one-way BPEL process and name it EventPublisherProcess. Use following screenshot for other parameter values.
Import Order.xsd into the project and select orderDetails as Input element for the BPEL process. Click OK to complete project creation.
Open composite.xml and click on “Event Definition Creation” icon from top left corner of the window as shown below.
Specify “OrderEventDefinition” for EDL File Name.
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.
Click OK from Event Definition dialog.
Open EventPublisherProcess from composite.xml. From Component Palette, drag and drop an Invoke activity on to BPEL process.
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.
Drag and drop an Assign activity. Assign BPEL input variable to event’s input variable.
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.
Now Mediator component has successfully subscribed to OrderPublishingEvent.
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.
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.
In Messages section, click on “Define Schema For Native Format” icon next to URL field. Click Next.
Leave default values in “Choose Type” screen.
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
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.
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.
From Messages section, click Next and Finish.
In composite.xml, wire MediatorSubscriber and OrderWriterService.
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.
Click on orderDetails in <sources> and drop on to OrderCollection element in <target>. Save All.
Finally, Deploy EventDeliveryExample project. Launch the process by specifying values in Test screen.
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