Oracle SOA suite has introduced a new adapter called as Coherence adapter. This essentially works in the same principal as of Result caching in Oracle service bus.In this exercise we will try to understand more about coherence adapter and will use the same to do an end to end exercise.
Coherence adapter is installed by default in the integrate server however it is not targetted to the server so the very first thing is to target your coherence server to the default server so that it can be used.
Click on the Coherence adapter and then click on the targets tab.
Here Select the default server and save the changes.
After targetting and saving once you will check it again you will find that the Coherence Adapter is up and running
Next is create a JNDI to be used in the design time.
Again click on the COherence Adapter -->Select Configuration
and then select Outbound Connection pools
Create New
Provide a JNDI name and finish the wizard.
save the deployment plan
Now if you will check any of the other predefined jndi for coherence adapter you might find following type of entry
YOU can find that it is pointing to the Cache config location
I actually went back to the file location and check what exactly the file contains
The cache config file allows us to define multiple cache and define what kind of cache can be configured such as SOAAdapterTransactionalCache ,distributionCache. Based on existing schema we can create our own custom config cache and use it for our demo purpose.
We will create our own cache-config file based on the default one.
Here is how my cache-config will look like
Now go to the configuration of your JNDI and provide the details as shown below.
Here location is the path where i have stored my cache-config file locally.
Mode is custom and SErvice name will be the name specified in the config file.
Again WLSExtendProxy is set to false as we are not using any proxy
Once the changes are made, save the changes and update your deployment plan
Now your JNDI is configured and you are now ready to use it for the demo project purpose.We will see in next exercise as to how we can create a sample BPEL process and test the functionality of the coherence in SOA 12c
Testing the Coherence Adapter in SOA 12c
In this exercise we will see how we can create a sample process to test the functionality of coherence adapter.
The functionality we are going to use here is that we will use a DB adapter and based on a unique employeeID we will try to get the employee name from database. The coherence will come into the picture when we will need to retrieve the employee name for employee id which we have already retrieved. Since we are using coherence cache, the second time if we make a call to our web service to retrieve employee name for the same employeeId it should not make a db call instead it should get the result from cache, thus it will save a lot of time for the end user. Again a point to be noted is that coherence is good for those data which are historical and are not supposed to be changed, if the data is supposed to changed frequently then coherence might not provide the best solution as the assumption here is that once we have retrieved a data it will stored in cache that is we are assuming that the data will not further change. So it is important to get the business clarification on the data then only one should go ahead with coherence.
the process we are going to define will look something like this

and the composite will look something like this

Lets start designing this process and test the functionality,
First of all drag and drop a BPEL process in the composite, make it a synchronous process.
give it some logical name and let the other things be default

Next is drag and drop a db adapter and try to pull data from employee table based on the employee id information

I am using the HR Schema and trying to pull data from employees table

Again i am using a parameter so that we can pass the input from web service and retrieve the data based on this parameter from the employees table. Check out the query getting generated

Link your DB Adapter to the BPEL process and then drag and drop a coherence adapter in the External reference pane. We will be using two coherence adapter one to put the data in to the coherence and the other one to retrive it from the Cache.

provide the jndi that you have created in the last exercise(previous post)

select operation as put

in the next step specify the name of the Cache which you have defined in the last exercise(previous post).
Further deselect the option of auto generate key as we are going to pass it on run time as a header variable from soa process

Select the schema of the bpel process and then select the response document as shown below

Similarly put another Coherence adapter for retrieving the data from the cache

use the same jndi however choose get as operation this time

Again use the cache type as XML , provide the cache name and Make key type as string, left the key field blank we will pass it on run time from soa header

Again select the schema of BPEL process and select the response type the same one we have selected in the previous coherence adapter.Link both the adapter to the BPEL process
Now drag and drop an invoke activity and call the GetCacheData.Create an input and output variable for the adapter. This is done immediately after the receive activity as we will have a check on the output result from the cache.If the data is available in cache we will use the same as output otherwise we will call the db adapter and then store the result in the cache

Now go to the properties tab of the adapter and assign the input variable of the BPEL process to the header variable jca.coherence.key as shown below

Now put an assign activity this activity will just assign the input variable of the BPEL to the input of DB adapter. AFter the assign activity put an if condition. This is the place where we will check if there is data in the cache.The If condition will have the following entry. As can be seen it is checking if the output from calling coherence adapter is null or not.If it is null then call the db adapter and store the data in cache.If it is not null then simply pass the same output to the output variable of BPEL

Now we will first configure the else block

First of all we will call the db adapter to get the response from the database based on the employeeID.
Next is we will use an assign activity.
In this assign activity we will first assing the output from Database to the output variable and then we will assign this output variable to the input variable of CahceStore adapter.

Immediately we will use a cache adapater to insert the result that we have received in the previous step to be stored in cache.
We will again pass the key as a header variable as we have passed earlier
Now in the if block we will assing the output data from the GetCacheData to the output of the BPEL

NOw the process is complete,Deploy the process to the integrated server and test it.

The flow will take the else block since this is a first time invocation. It will call the db and get the result and at the same time it will store the result in cache.
The flow in this case will be as shown

Expanding the process you will find that the data is getting stored in the cache with a unique key value

Now once the process is invoked lets again call the same process with same input and you will find that the response is same however the flow is now different

Now if you will go to the flow of the second process you will find that it is actually retrieving the data from the cache

The functionality we are going to use here is that we will use a DB adapter and based on a unique employeeID we will try to get the employee name from database. The coherence will come into the picture when we will need to retrieve the employee name for employee id which we have already retrieved. Since we are using coherence cache, the second time if we make a call to our web service to retrieve employee name for the same employeeId it should not make a db call instead it should get the result from cache, thus it will save a lot of time for the end user. Again a point to be noted is that coherence is good for those data which are historical and are not supposed to be changed, if the data is supposed to changed frequently then coherence might not provide the best solution as the assumption here is that once we have retrieved a data it will stored in cache that is we are assuming that the data will not further change. So it is important to get the business clarification on the data then only one should go ahead with coherence.
the process we are going to define will look something like this
and the composite will look something like this
Lets start designing this process and test the functionality,
First of all drag and drop a BPEL process in the composite, make it a synchronous process.
give it some logical name and let the other things be default
Next is drag and drop a db adapter and try to pull data from employee table based on the employee id information
I am using the HR Schema and trying to pull data from employees table
Again i am using a parameter so that we can pass the input from web service and retrieve the data based on this parameter from the employees table. Check out the query getting generated
Link your DB Adapter to the BPEL process and then drag and drop a coherence adapter in the External reference pane. We will be using two coherence adapter one to put the data in to the coherence and the other one to retrive it from the Cache.
provide the jndi that you have created in the last exercise(previous post)
select operation as put
in the next step specify the name of the Cache which you have defined in the last exercise(previous post).
Further deselect the option of auto generate key as we are going to pass it on run time as a header variable from soa process
Select the schema of the bpel process and then select the response document as shown below
Similarly put another Coherence adapter for retrieving the data from the cache
use the same jndi however choose get as operation this time
Again use the cache type as XML , provide the cache name and Make key type as string, left the key field blank we will pass it on run time from soa header
Again select the schema of BPEL process and select the response type the same one we have selected in the previous coherence adapter.Link both the adapter to the BPEL process
Now drag and drop an invoke activity and call the GetCacheData.Create an input and output variable for the adapter. This is done immediately after the receive activity as we will have a check on the output result from the cache.If the data is available in cache we will use the same as output otherwise we will call the db adapter and then store the result in the cache
Now go to the properties tab of the adapter and assign the input variable of the BPEL process to the header variable jca.coherence.key as shown below
Now put an assign activity this activity will just assign the input variable of the BPEL to the input of DB adapter. AFter the assign activity put an if condition. This is the place where we will check if there is data in the cache.The If condition will have the following entry. As can be seen it is checking if the output from calling coherence adapter is null or not.If it is null then call the db adapter and store the data in cache.If it is not null then simply pass the same output to the output variable of BPEL
Now we will first configure the else block
First of all we will call the db adapter to get the response from the database based on the employeeID.
Next is we will use an assign activity.
In this assign activity we will first assing the output from Database to the output variable and then we will assign this output variable to the input variable of CahceStore adapter.
Immediately we will use a cache adapater to insert the result that we have received in the previous step to be stored in cache.
We will again pass the key as a header variable as we have passed earlier
Now in the if block we will assing the output data from the GetCacheData to the output of the BPEL
NOw the process is complete,Deploy the process to the integrated server and test it.
The flow will take the else block since this is a first time invocation. It will call the db and get the result and at the same time it will store the result in cache.
The flow in this case will be as shown
Expanding the process you will find that the data is getting stored in the cache with a unique key value
Now once the process is invoked lets again call the same process with same input and you will find that the response is same however the flow is now different
Now if you will go to the flow of the second process you will find that it is actually retrieving the data from the cache
No comments:
Post a Comment