Title: Using BPEL with ESB for Loose Coupling of Business Process Version: 1.0, Date: June 26, 2008 Discussion Topics Objective Application Architecture Deployed ESB Architecture Creating Database Tables and Sequence Creating Employee BPEL Process Creating Employee System in ESB (File Adapters) Enhancing ESB to have Database Adapter Register and Test Employee ESB Enhancing Employee BPEL Service to Invoke ESB Test BPEL Process Summary Objective The Objective of this exercise is to Create a Loose Coupled Business Process and an ESB Service, Use Case: The Employee Business Process would receive Employee Name, Employee Type, Basic Salary, HRA from the End User (or any other invoking service), based on this data the process would generate Employee Id, calculate Tax and Net take home Salary The Employee ESB would be responsible for Writing the data to File Using File Adapter if the employee is of type Probation OR Writes the data into Employee and Finance Tables if the employee is of type Permanent The Employee Business Process would invoke Employee ESB to Accomplish the task. Takeaway: The System Answers and shows in Practice Loose Coupling Service Oriented Architecture Concepts How BPEL Processes can be invoked by ESB How ESB can be invoked by a BPEL Process How File and DB Adapters can be used How to set Routing Rules in ESB How to Map incoming and outgoing data through ESB Mappers How Loose Coupling can be established across various Services Respect the Architectural Concepts of Loose Coupling between Business Layer, Service Layer and Data Layer.
Application Architecture The Above Figure shows End User / Any other business Process Invoking an Employee Business Process, The Process would do some Business Logic and in-turn invokes ESB as a Partner Link, In this case ESB acts as a service Provider. ESB is Connected DB and File Adapters. Based on Routing Rules Defined in ESB the XML data received from Employee BPEL Process is sent to DB and File Adapters. The Adapters would write into Appropriate tables or xml file system. Software s: The Entire Architecture uses Oracle 10 g SOA Suite for BPEL and ESB, Oracle XE Database for storing data into tables, JDeveloper 10.1.3.3 release is used as an IDE to Write, Build, Deploy and Test BPEL and ESB Developments. Layering: In Architecture BPEL Process forms to Business Layer (which could also have Oracle Rule Author), The Service Layer is ESB which connects various Adapter Services, Its easier to change routing rules or transformations in this layer based on new rules governing Application Integration, The Last layer which holds data in the form of XML files or in the form of tables is Data Layer.
Deployed ESB Architecture The Above Deployed ESB Diagram shows Employee BPEL Process invoking Employee ESB, This has 3 Adapters connected with routing rules, Employee File Adapter to write into XML File, HR Data Adapter to write into HR table, Finance Data Adapter to write into Finance table, We would also need XSL Mappers to transform data from incoming Employee Process XSD to outgoing HR Data Table XSD; also we need one more Mapper for Finance Adapter as well. Creating Database Tables and Sequence We will install Oracle XE Database, you can use Oracle SQLDeveloper to do SQL Operations on the database or use Oracle XE Database Homepage after installing the software 1. HRData (Table), cols EMPID varchar2(10), EMPNAME varchar2(100), EMPTYPE varchar2(100) for storing HR related data 2. FinanceData (Table), cols EMPID varchar2(10), BASIC number, HRA number, tax number, takehome number for storing Finance related data 3. CREATE SEQUENCE EMPSEQ MINVALUE 1 INCREMENT BY 1 ; Note: In real life production scenarios HR data and Finance data could reside in separate database in multiple tables or even use xml or file formats to hold data Creating Employee BPEL Process We Start of by creating an EmployeeApp having BPEL Process project named EmpProcess using Jdeveloper. We start of by Modifying the Generated
EmpProcess.xsd which would be deciding on input and output variables to the Business Process. I have chosen Employee Name, Employee Type (Probation or Permanent), Basic Salary, HRA Salary as inputs, where as the business process would calculate my Tax Payable, and net take home salary. For us to Generate Employee Id, we would need a sequence number for this we can drag and drop Database Adapter into Service area of BPEL process, give the name as GetSeqNo click next
Its assumed that you have already created a database connection from Jdeveloper into XE Database, I am using the name as soa. If not yet use connection navigator of Jdeveloper to establish the db connection
we would need to execute Custom SQL to get the next sequence number responsible for generating employee id
Give the SQL as select empseq.nextval from dual. Jdeveloper Auto generates the XSD File which can be previewed. Click Finish
The generated Partner Link is shown above.
We would need an invoke activity dragged between receive input and reply output name it as InvokeSeqNo which would be connected to GetSeqNo partner link
Lets save the BPEL Process. And create a New ESB Application. Ignore the above Complete BPEL Process for sometime as we need to create an ESB which can be invoked using BPEL Creating Employee System in ESB Create another new Application named EmployeeESBApp, create a new Project EmpESBProj of type ESB Project. what and why? : We will now create a File Adapter to write the incoming employee data into file, incase the employee type is PROB (Probation). the data would come from Employee BPEL and will be passed into Employee ESB. In the EmpESBProj.esb start with creating a File Adapter as shown below
Give the name as EmpFileAdapter click Next,
Select Write File, Operation Name as Write, Click Next
Select the Output directory as c:\temp and file name as emp_%seq%.xml, for every record a new xml file will be created.
we want the XML File to be of type EmpProcess.xsd which can be Browsed from the file repository from our Employee BPEL Process Project. We will need the Schema Element of type Response because we want to display the output of a BPEL Process rather than request.
Click Finish Button. Enhancing ESB to Add DB Adapter (HR Table) what and why? : Employee data of type PERM (Permanent) would be written to HR table using DB Adapter connected to ESB. The employee type would be passed on from Employee BPEL Process into Employee ESB through a Partner Link. Create a Database Adapter from Create Adapter Service in EmpESBProj.esb
canvas. Give the Name as HRDataAdapter click Next
Select soa connection, click Next
Select Perform an Operation on a Table Radio button and select Insert Only check box, click next button.
Import the HRData Table, click next button.
Click Finish Button. Enhancing ESB to Add DB Adapter (Finance Table)
what and why? : Employee data of type PERM (Permanent) would be written to Finance table using DB Adapter connected to ESB. The employee type would be passed on from Employee BPEL Process into Employee ESB through a Partner Link.
The Wizard is similar to HR Table one except that we need to select FinanceData table from the Import Tables button.
On the ESB canvass we can now see 3 adapters,
Lets create on create system/group icon at extreme top left and create a system EMPLOYEE click OK Lets create a Routing Service to connect these adapters together. what and why? : Routing Service plays very important role in the design of ESB one can say it s the Heart of ESB, its here that we define routing rules to connect to various adapters, map (or Transform) incoming data to out going data through Mappers, In our use case, the employee data of type PROB would be written into xml file, the employee data of type PERM would be written into 2 tables through 2 adapters one for HR and other for Finance.
We create a new Routing Service by name EmpRoutingService in the EMPLOYEE System Routing Rules can be added by clicking on + symbol next to Routing Rules in Routing Service, By clicking on funnel / filter icon routing conditions can be set up.
We will then set up a Routing condition where emptype = PROB the data goes into file adapter is connected to Employee ESB We define one more Routing Rule and set one more Routing condition to send data into HR database Adapter. We would need a New Mapper File to Map data incoming from Employee Business Process into HR File Adapter. So a new xsl transformation file is created.
Connect the 2 wsdl elements as shown in the above figure. Similarly Routing rules are created for emptype = PERM by clicking on the funnel icon.
New Transformation file is created to map incoming Employee BPEL Process schema into outgoing Finance Data table.
The Completed ESB looks as shown in the above figure. Register and Test Employee ESB Once and ESB Project is created and can compile without any errors its time to Register the ESB
Right click on the Employee ESB Project and select Register with ESB and select the SOA Server Connection. If Oracle SOA Suite is installed on port 8888, then ESB console can be opened at the
following URL http://localhost:8888/esb Clicking on Definition Tab will show the links to WSDL URL and SOAP Endpoint URI one can test the ESB at this stage itself. In our case we will test the application end to end after completing our BPEL Process.
Enhancing Employee BPEL Service to Invoke ESB what and why? : From our BPEL Process we will calculate Tax Payable, Net take home salary based on user input, then invoke ESB to write the data into XML File or Database Table, based on business rules Drag and Drop a Partner Link, on to the Employee BPEL Process Project s BPEL Canvas, name it as EmpESBLink, for the wsdl select from Registered ESB Services, select EmpRoutingService under EMPLOYEE
Drag and Drop Invoke Activity above reply output, which invokes this partner link, and name it as InvokeEmpESB. Drag and Drop Assign Activity above InvokeEmpESB to assign variables into the partner link ( Employee ESB ). Name this Assign as AssignEmpData The completed BPEL Process now looks as shown below. Create Copy a Operations in the Assign Activity. 1. Employee Id is Concatination of EmpSeq.next val and employee type, which is assignment of type expression.
2. Employee Name, Employee Type, Basic Salary, HRA are directly mapped from inputvariable payload into InvokeEmpESB input variable.
4. Tax is calculated as 20% the sum of basic + hra using expression type of assignment.
5. Take home salary is calculated as basic sal + hra tax amount once again expression type variable is used to get this done, that s it save the BPEL process.
Deploy and Test BPEL Process Lets build and deploy the BPEL Process into Oracle 10g SOA Suite. Access the BPEL Console at the following URL http://localhost:8888/bpelconsole Invoke the Employee BPEL Process, input data ( Employee Name, Type, Basic, HRA), click on POST XML Message. Since the employee is of type PERM, the employee data is written into database tables HR and Finance
Using SQL Developer one can view the HRData & FinanceData table for the new record entered, you can observe that emp id is auto generated and so is tax and take home salary.
One can view the XML in Flow tab
Also at ESB Console based on the same instance id shared with BPEL console one can also view the ESB diagram how data flow has happened from Employee BPEL Process into HR Data Adapter and Finance Data Adapter marked in green.
Similarly one more test case can be created in BPEL Console where employee is of type PROB this would generate XML File in c:\temp directory
The above fig shows the XML Flow for the BPEL testcase.
Based on instance id one can view the green boxes in the ESB diagram where data has flown from Employee BPEL Process into Employee File Adapter. Summary The above use case and practice session shows how the following can be achieved Loose Coupling Service Oriented Architecture Concepts How BPEL Processes can be invoked by ESB How ESB can be invoked by a BPEL Process How File and DB Adapters can be used How to set Routing Rules in ESB How to Map incoming and outgoing data through ESB Mappers How Loose Coupling can be established across various Services Respect the Architectural Concepts of Loose Coupling between Business Layer, Service Layer and Data Layer Author James Smith Java Oracle Blogs