menu

Thursday, November 13, 2014

Using Subprocess In SOA

Introduction:

     Today I'll talk about a new feature of SOA Suite 12c environment, subprocesses. We'll see two type of subprocess which are "inline" and "standalone".The main purpose is to create reusable components that include more than one activities.Using subprocess we can develop less code for repeating operations incresing the reusability and maintainability.

Inline Subprocess:

     You can use inline subprocess if you want to reuse a group of activities in a single bpel process rather than using it in more than one process.It will be part of a main bpel process.You have to combine reusable activities in a scope to be able make them as subprocess.There will be only one subprocess in the memory.

Here is an example bpel process for inline subprocess.

The example is just for the explanation of the inline subprocess.We'll create a bpel process which take 2 string input parameters, write the first parameter to a file in a file names as "yyyyMMddHHmmssSSz" and then check if the second parameter's length is greater that 5, if so write that parameter to another file again in a file named as "yyyyMMddHHmmssSSz".Here we need 2 write process and so need 2 invoke for the same file write adapter.At this point inline subprocess comes to rescue and helps us to create a reusable subprocess to be able to call write process many times with only one implementation.

At the end of the example we should get the following composite.


Using Subprocess In SOA
Figure 1

Create a synchron bpel process with an xsd file with 2 string input variables.

Using Subprocess In SOA
Figure 2

Create a file adapter by right clicking in the external references and follow the wizard by entering the File server JNDI name as "eis/FileAdapter" as in Figure 3 and 4.

Using Subprocess In SOA
Figure 3

Using Subprocess In SOA
Figure 4

Then choose the "Write" operation and enter the file directory and the file name convention as in Figure 5 and 6.

Using Subprocess In SOA
Figure 5

Using Subprocess In SOA
Figure 6

Finally we choose the input xsd file as the input of our file write adapter just to be an example.

Using Subprocess In SOA
Figure 7

Now go to the bpel process editor and drag and drop a scope,an assing and an invoke activity after the ReceiveInput component, reference the file adapter from the invoke and place the assign and invoke in the scope activity since the activities should be in a scope activity to create an inline subprocess.See in Figure 8.

Using Subprocess In SOA
Figure 8

Below is the invoke activity edit page.

Using Subprocess In SOA
Figure 9

You can now right click the scope activity and choose "Convert to a Subprocess" as in Figure 9.

Using Subprocess In SOA
Figure 10

Give a name to your subprocess, you can also choose immediately replacing your scope with the call of created subprocess as shown in Figure 10.

Using Subprocess In SOA
Figure 11

You can see your subprocess by choosing the subprocess in the left top corner as shown in the Figure 11 with a red arrow.

Using Subprocess In SOA
Figure 12

You can change your subprocess call name in the edit page.

Using Subprocess In SOA
Figure 13

At this point we define the input of file adapter with the help of the assign activity.We either define a variable in the main process and assign that variable before calling the subprocess and assign that variable to the input of file adapter in the subprocess as shown in Figure 14 and 15 or define a variable in the subprocess and make a relation with the input variable of the main process and the variable created in the subprocess.Since an inline subprocess can see the main process's variables it's no matter here, however when we use the standalone subprocess we have to create a variable in the subprocess and make a relation with the main process variable as we'll see in the standalone subprocess part of this write.

Using Subprocess In SOA
Figure 14


Using Subprocess In SOA
Figure 15

In the bpel process editor place an If activity after the just created subprocess call and check if the second input parameter length is greater than 5.

Using Subprocess In SOA
Figure 16

You can see the inline subprocess in the  Components -> Subprocesses as shown with a red arrow in the Figure 17. Simply drag and drop it in the if activity to call the file process second time after defining an assign activity similar to the previous subprocess call.

Using Subprocess In SOA
Figure 17

The final bpel process should now look like as in Figure 18.

Using Subprocess In SOA
Figure 18

Let's now test our bpel process first with a second input with a length less than 5 and then greater than 5.We should see two files created in the later case.

Using Subprocess In SOA
Figure 19

Since the second input is "test" which has 4 length there will be one file created in the target directory as in Figure 20.

Using Subprocess In SOA
Figure 20

The content of the created file will be like in the following figure

Using Subprocess In SOA
Figure 21

If we run the process with a parameter like "test77" we'll end up with 2 files created as in Figure 22.

Using Subprocess In SOA
Figure 22

Standalone Subprocess:

     The second type of subprocess is standalone which can be reused accross multiple bpel processes.For the first release of Soa Suite 12c its only supported in the same composite.We may use "Create SOA Template" feature to create a template with the standalone subprocess and then reused in different composites. 

Here is an example bpel process for standalone subprocess.

The example is just for the explanation of the standalone subprocess.We'll create a bpel process that takes 1 string input variable and persist it to database using a standalone subprocess which will include a database adapter.We'll create a table named "TEST" that include only one column to hold the string input value.We'll call the subprocess to insert the value and then will check if the count of the "TEST" table is less than 5 using another database adapter with a pure sql to get the count of the rows.If its less than 5 we call the subprocess again to insert the table this time input value concatenated with "-" and the "COUNT" of the table.

At the end of the example we should get the below composite.

Using Subprocess In SOA
Figure 23

First let's create a synchron bpel process with one input variable like in Figure 24.

Using Subprocess In SOA
Figure 24

Then create a standalone  subprocess by right clicking the Components part of the composite page as shown in Figure 25.

Using Subprocess In SOA
Figure 25

Create a connection under Connections -> Database and create a table name "TEST" under SOAINFRA -> Tables as in following figure.

Using Subprocess In SOA
Figure 26

Before editing the standalone subprocess create a database adapter to persist the input to the database.Choose the connection you created and enter the prebuilt JNDI name as eis/DB/SOA.

Using Subprocess In SOA
Figure 27

Choose "Insert Only" option and left the "Attribute Filtering" as it is.See in Figure 28 and 29.

Using Subprocess In SOA
Figure 28

Using Subprocess In SOA
Figure 29

Now double click to the standalone subprocess and go to the bpel editor.Drag and drog an assing and an invoke activity referencing to the database adapter as in the following figure.

Using Subprocess In SOA
Figure 30

To be able to assign the input of database adapter in the subprocess, unlike inline subprocess you must define a variable in the standalone subprocess and link that variable to a variable in the main process.Drag and drop an assign activity after the ReceiveInput of the main process and define a variable named InputValue in the main process and assign it by the input of the schema as in Figure 31.

Using Subprocess In SOA
Figure 31

As you can see in Figure 32, standalone subprocess is now in in the components tab.

Using Subprocess In SOA
Figure 32


Now go to the subprocess create a variable named "InputVar" and then in the main process editor drag and drop the standalone subprocess after the assign activity and link the "InputValue" variable of the main process with the "InputVar" variable of the subprocess in the "Edit Call" page as in Figure 33.

Using Subprocess In SOA
Figure 33

You should then assign the InputVar to the input of database adapter in the subprocess as in the following figure.

Using Subprocess In SOA
Figure 34

Let's now define another database adapter to get the count of the table as in the Figures 35 and 36.We define  a pure sql to get the count.

Using Subprocess In SOA
Figure 35

Using Subprocess In SOA
Figure 36

We now use an If activity after calling the "count" database adapter and if the count is less than 5 we add another call to the standalone subprocess with an input value of the form "input-count".See in Figures 37 and 38.

Using Subprocess In SOA
Figure 37

Using Subprocess In SOA
Figure 38

Finally we should get the following bpel process with 2 subprocess calls.

Using Subprocess In SOA
Figure 39

Let's test the bpel process running it 3 times with the test, test2 and test3 values respectively.In the first two calls we should see two inserts.In the last call since the row count will be 5 the second subprocess call will not be executed.See in Figures 40, 41 and 42 for the results.You can use the Tools -> Database -> SQLWorksheet to see the records in the table.

Using Subprocess In SOA
Figure 40

Using Subprocess In SOA
Figure 41

Using Subprocess In SOA
Figure 42

Conclusion:

      We saw subprocesses which is a new feature of SOA Suite 12c.Subprocesses can be used to develope reusable applications and it can reduce the size of your application.You can either use inline or standalone subprocess according to your need.In the standalone subprocess you can reuse a group of activities across multiple bpel processes while inline can be used only in the same bpel process. In the first release of SOA Suite 12c the standalone subprocess can be used only in the same composite, so you should look for the latest releases.

You can download the source code from here.















No comments:

Post a Comment