Monday, July 21, 2014

Testing the Coherence Adapter in SOA 12c

In the previous exercise we saw how we can create jndi connection for coherence adapter. 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

2 comments:

Kumar Gaurav said...

How do I synchronize the database changes to be available in cache. I believe I need to perform some checks to identify the changes and then to put in cache. I am not sure How to achieve the same in SOA 12c. Any help please.

Unknown said...

Thanks for your post!

Could you please also share how to PUT POJO into Coherence cache.

Thanks in advance.