Today we'll talk about caching capability of Oracle SOA Suite environment using Coherence Cache adapter.In general, cache coherence is a way of being sure about the consistency of the cached data in a distributed cache environment especially in multiprocessor systems.Oracle Coherence makes the data available as if it were a single application server in a clustered environment and serves the data from the memory if it is available in the cache, instead of a database call.By this way it reduces load on database and reduces the overall response time.In addition to the read-only data where we can use the query the data from the coherence cache, it can also be used for the insert, update and delete operations lefting the database operation at a later time where the system is not heavy loaded.By this way, even it can be used as a failover scenario if there is a problem with the database.
Configure Coherence Adapter In the Application Console:
First of all, we have to target Coherence Adapter to our server which is the DefaultServer in our case.To do that, go to the http://localhost:7101/console and choose CoherenceAdapter in the Deployments menu.See in Figure 1.
Figure 1
Then, go to the Targets tab and check the DefaultServer as in Figure 2.
Figure 2
Go to Window -> Database -> Databases and create a new Database Connection like in Figure 3.
Figure 3
Then, create a new table named PERSON with the columns as shown in Figure 4.
Figure 4
Run the following insert queries in the Tools -> Database -> SQL Worksheet screen.
Figure 5
Create the Bpel Process:
Create a synchron Bpel process in the composite page and change the xsd file as in the Figure 6.
Figure 6
Then, drag and drop a Coherence Adapter to be used with Get operation from the Components -> Technology to the composite editor and rename it like in the following figure.
Figure 7
Choose eis/Coherence/Local as the JNDI Name.
Figure 8
Choose the Get operation.See in Figure 9.
Figure 9
On the next screen of the wizard, enter the cache name as "adapter-local" which is a prebuilt internal coherence cache.
Figure 10
Leave the Key field as empty and ignore the following message, we'll enter the Key value later on.
Figure 11
On the next screen, choose the processResponse schema element of the xsd we have defined earlier as in Figure 12.
Figure 12
The composite now should look like the following figure.
Figure 13
Next, drag and drop another Coherence Adapter to be used with Put operation and rename it.
Figure 14
Choose the Put operation.
Figure 15
Enter again the builtin coherence cache named "adapter-local", uncheck the Auto-generate key, and enter a temporary random key definition which will be overrided soon.See in Figure 16.
Figure 16
Similar to the previous Coherence adapter, choose the processResponse Schema element of the previously defined xsd file.
Figure 17
Before go in to the detail of the Bpel process, the final step is to define the database adapter, so drag and drop a database adapter to the composite editor.
Figure 18
Choose the connection we've just created and enter the builtin JNDI eis/DB/SOA like in Figure 19.
Figure 19
Choose only the Select operation on the following screen.
Figure 20
Import the table PERSON we've created previously.
Figure 21
Check all the columns of the table PERSON like in Figure 22.
Figure 22
Now, define the parameters and the SQL.We want to select a person with a id.See in Figure 23.
Figure 23
At the end we should get the following diagram in the composite page.
Figure 24
Build the Detail of Bpel Process in the Bpel Editor:
Go into the bpel editor and drag and drop an invoke activity after the receiveInput component.Reference the Coherence Adapter with Get operation from the invoke activity.Then define the input and output variables by just clicking the green plus sign like in Figure 25.
Figure 25
The bpel process should look like the following now.
Figure 26
Go to properties page of the invoke activity and click to the green plus sing to add a new property.
Figure 27
In the opened "To Propery" page choose the jca.coherence.Key property and give its value as the id of the input variable as in Figure 28.
Figure 28
Then, drag and drop an If activity just after the Coherence Adapter with the Get operation and define the following condition to understand whether the data is in the cache.If the name property of the output of the Coherence adapter will not be null that means the data is in cache.
Figure 29
If its returned true from the If activity just assing the output of the Coherence Get Adapter to the output variables by dragging and dropping an assing activity.See in Figure 30.
Figure 30
If its returned false from the If activity, in the else part drag and drop an invoke activity and reference it to the Database Adapter we've defined choosing the input and output variables by just clicking the green plus sign as we did previously, and assing the input id to the input variable of the database adapter with the help of an assign activity. See in Figure 31 and 32.
Figure 31
Figure 32
Next, drag and drop an invoke activity referencing to the Coherence Adapter with the Put operation.See in Figure 33.
Go to properties page of the invoke activity and click to the green plus sing to add a new property and define the jca.coherence.Key property as the input id as in Figure 34.
Then, drag and drop another assing activity and assign the output of the database adapter that just select the person information to the input of the Coherence Adapter with the Put operation and at the same time to the output variable of the bpel process to reply to the caller.See in Figure 35.
Figure 33
Figure 34
Figure 35
The final bpel process should now look the following figure.
Figure 36
Test the Bpel Process In the Enterprice Manager:
Go to the http://localhost:7101/em, open your project, click on Test and call the service using the same values that exists in the database for example with the id 1.
Figure 37
You'll see in the first execution there will be database call, while the later calls will get the data from the cache coherence.You can see this execution paths in the "Flow Instances" page of the enterprice manager as in the Figure 38 and 39.
Figure 38
Figure 39
Conclusion;
We saw how to use a coherence cache in Oracle SOA Suite environment.The coherence cache can greatly improve performance of an application by serving the data from the memory rather than requesting the database all the time and by reducing the load on database.
You can download the source code from here.
No comments:
Post a Comment