Advertisements

Posts Tagged 'Coherence'

Coherence in BPEL11g

After trying out with Result Caching feature in OSB, i tried to use the coherence in integration with BPEL to store and retrieve the frequently used data in cache. As OTN puts it, “Coherence provides replicated and distributed (partitioned) data management and caching services on top of a reliable, highly scalable peer-to-peer clustering protocol”. In this post, i want to explain the setup i tried with using SOA Suite 11.1.1.3. The weblogic 10.3.3 installer comes with coherence 3.5

Starting Servers

To use coherence in conjunction with BPEL, the servers have to be started in the following order:

    • Coherence server (cache-server.cmd)
    • Admin and SOA managed server.

Open cache-server.cmd file present in $FMW_HOME\coherence_3.5\bin and set the coherence_home variable as shown below. Replace $FMW_HOME with actual path as per your SOA suite installation.

       set coherence_home = $FMW_HOME\coherence_3.5

Open command window and issue the following commands to start the cache server.

    $<DOMAIN_HOME>\bin\setDomainEnv.cmd or set $JAVA_HOME

    set %PATH% = %JAVA_HOME%\bin;%PATH%

    cache-server.cmd

By default, multicasting is used for communication within coherence cluster. The multicast address and port will be visible in cache server start logs as shown below.

          image

In setDomainEnv.cmd file, modify EXTRA_JAVA_PROPERTIES variable to use above multicast address and port.

       image

In startWeblogic.cmd file, modify CLASSPATH variable to include coherence jar in server classpath.

SOA Composite Creation

We will create a simple BPEL process to demonstrate the use of coherence API to store and retrieve cache entries.

Create a sample SOA project in JDeveloper. Add coherence.jar to project libraries which can be found at location $FMW_HOME\coherence_3.5\lib. Create a BPEL process that accepts a string and returns another string.

        clip_image002

Create a java embedding activity with following code to verify whether the cache contains a value or not.

String cacheToken= ((oracle.xml.parser.v2.XMLElement) getVariableData ("varInput","payload","/client:process/client:input")).getFirstChild().getNodeValue();

//create new cache or to get the existing cache

NamedCache cache = CacheFactory.getCache("myCache");

//verify whether the key exists or not

setVariableData("valExists", cache.containsKey(cacheToken));

setVariableData("var1", cache.get(cacheToken));

Create a switch case in BPEL flow to call the actual service if the cache value does not exist for the token used. The following expression can be used in the switch case.

      bpws:getVariableData(‘valExists’)=string(true())

If the value is retrieved from cache, copy the value stored in ‘var1’ variable to output variable and do reply from BPEL process. Otherwise store the value we have got from the actual service in cache by using another java embedding activity with following code.

String cacheToken= ((oracle.xml.parser.v2.XMLElement) getVariableData("varInput","payload","/client:process/client:input")).getFirstChild().getNodeValue();

String cacheValue= ((oracle.xml.parser.v2.XMLElement) getVariableData("InvokeOutputVariable","parameters","/ns1:getResponse/val")).getFirstChild().getNodeValue();

NamedCache cache = CacheFactory.getCache("myCache");

cache.put(cacheToken,cacheValue);

setVariableData("var1",cache.get(cacheToken));

Execution of BPEL:

When result is not in Cache:

Run the BPEL by giving the value for ‘input’ element that does not exist in the cache currently. Here in this case, we are sending it as ‘NewUser’.

       image

         image

Observe that partner link has been called to get the result.

        image

When result is in Cache:

          image

Observe that partner link is not called and the result is fetched from the cache as expected.

          image

Strategies to Flush/Refresh the Cache:

  • Create a configuration parameter or BPEL property to specify whether cache has to be cleared or not. Modify the above switch condition to include this OR condition so that the existing cache will be reset by fetching the value again by calling the partner link.
  • Restarting the coherence server.
Advertisements

Coherence in OSB

In one of our proxy services, we call one service to get credentials with which we can proceed with next service calls in the message flow. As anybody can guess, the credentials might remain same for a period of time (though based on the reset policy).

So if we can reduce number of service calls by caching the service results will increase the performance of the service. I felt that i have realized this very late Smileonce i started searching for this feature in OSB as i find number of articles on the same.

Using Oracle Coherence is the way to cache service results and ‘Result Caching’ is the feature of business service through which OSB can leverage coherence functionality. Thought of putting all my findings in one post but after seeing this article on OTN, i don’t dare to do that.

I have just taken this simple scenario to make a point on using coherence in OSB. The context explained over here may not be the right candidate if we are not aware of the credential reset policy. Then the credentials stored in cache may not be the right ones always and need to clear the cache. So the context has to be clearly ascertained to use coherence.

Currently in the process of finding the way to use coherence in BPEL.

Java Embedded Activity in BPEL

Today, it’s the first time that i worked with the Java Embedded Activity in BPEL 11g as i had a requirement of using coherence in the context of BPEL.

Came across one of the silly issues during this process so wanted to share the resolution of the same as i feel its the common mistake that can be done.

When i put the code in java embedded activity and rebuild the composite, i was getting the following error.

Error(23,34): Failed to compile bpel generated classes. failure to compile the generated BPEL classes for BPEL process "BPELProcess1" of composite "default/Project1!1.0"
The class path setting is incorrect.
Ensure that the class path is set correctly. If this happens on the server side, verify that the custom classes or jars which this BPEL process is depending on are deployed correctly. Also verify that the run time is using the same release/version.

The issue is coming as the necessary import statements are missing. To resolve this issue, add the import statements in the following way in .bpel file(these are the classes that i used) before the listing of partner links.

<bpelx:exec import="com.tangosol.net.CacheFactory"/>
<bpelx:exec import="com.tangosol.net.NamedCache"/>


Advertisements

Pages

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 372 other followers

Enter your email address to follow this blog and receive notifications of new posts by email.

Advertisements