Oracle Coherence & Oracle Service Bus: REST API Integration
Posted
by Nino Guarnacci
on Oracle Blogs
See other posts from Oracle Blogs
or by Nino Guarnacci
Published on Thu, 17 Nov 2011 10:55:39 -0600
Indexed on
2011/11/18
1:56 UTC
Read the original article
Hit count: 690
/Oracle/Integration Solution
This post aims to highlight one of the features found in Oracle Coherence which allows it to be easily added and integrated inside a wider variety of projects. The features in question are the REST API exposed by the Coherence nodes, with which you can interact in the wider mode in memory data grid.
Oracle Coherence and Oracle Service Bus are natively integrated through a feature found in the Oracle Service Bus, which allows you to use the coherence grid cache during the configuration phase of a business service. This feature allows you to use an intermediate layer of cache to retrieve the answers from previous invocations of the same service, without necessarily having to invoke the real business service again. Directly from the web console of Oracle Service Bus, you can decide the policies of eviction of the objects / answers and define the discriminating parameters that identify their uniqueness.
The coherence REST APIs, however, allow you to integrate both products for other necessities enabling realization of new architectures design. Consider coherence’s node as a simple service which interoperates through the stardard services and in particular REST (with JSON and XML). Thinking of coherence as a company’s shared service, able to have an implementation of a centralized “map and reduce” which you can access by a huge variety of protocols (transport and envelopes).
An amazing step forward for those who still imagine connectors and code. This type of integration does not require writing custom code or complex implementation to be self-supported. The added value is made unique by the incredible value of both products independently, and still more out of their simple and robust integration.
As already mentioned this scenario discovers a hidden new door behind the columns of these two products. The door leads to new ideas and perspectives for enterprise architectures that increasingly wink to next-generation applications: simple and dynamic, perhaps towards the mobile and web 2.0.
Below, a small and simple demo useful to demonstrate how easily is to integrate these two products using the Coherence REST API. This demo is also intended to imagine new enterprise architectures using this approach.
The idea is to create a centralized system of alerting, fed easily from any company’s application, regardless of the technology with which they were built . Then use a representation standard protocol: RSS, using a service exposed by the service bus; So you can browse and search only the alerts that you are interested on, by category, author, title, date, etc etc..
The steps needed to implement this system are very simple and very few. Here they are listed below and described to be easily replicated within your environment. I would remind you that the demo is only meant to demonstrate how easily is to integrate Oracle Coherence and the Oracle Service Bus, and stimulate your imagination to new technological approaches.
1) Install the two products: In this demo used (if necessary, consult the installation guides of 2 products)
- Oracle Service Bus ver. 11.1.1.5.0 http://www.oracle.com/technetwork/middleware/service-bus/downloads/index.html
- Oracle Coherence ver. 3.7.1 http://www.oracle.com/technetwork/middleware/coherence/downloads/index.html
2) Because you choose to create a centralized alerting system, we need to define a structure type containing some alerting attributes useful to preserve and organize the information of the various alerts sent by the different applications. Here, then it was built a java class named Alert containing the canonical properties of an alarm information:
- Title
- Description
- System
- Time
- Severity
3) Therefore, we need to create two configuration files for the coherence node, in order to save the Alert objects within the grid, through the rest/http protocol (more than the native API for Java, C + +, C,. Net). Here are the two minimal configuration files for Coherence:
coherence-rest-config.xml
resty-server-config.xml
This minimum configuration allows me to use a distributed cache named "alerts" that can also be accessed via http - rest on the host "localhost" over port "8080", objects are of type “oracle.cohsb.Alert”.
4) Below a simple Java class that represents the type of alert messages:
5) At this point we just need to startup our coherence node, able to listen on http protocol to manage the “alerts” cache, which will receive incoming XML or JSON objects of type Alert. Remember to include in the classpath of the coherence node, the Alert java class and the following coherence libraries and configuration files:
At this point, just run the coherence class node “com.tangosol.net.DefaultCacheServer”
advising you to set the following parameters:
-Dtangosol.coherence.log.level=9
-Dtangosol.coherence.log=stdout
-Dtangosol.coherence.cacheconfig=[PATH_TO_THE_FILE]\resty-server-config.xml
6) Let's create a procedure to test our configuration of Coherence and in order to insert some custom alerts in our cache. The technology with which you want to achieve this functionality is fully not considerable: Javascript, Python, Ruby, Scala, C + +, Java.... Because the protocol to communicate with Coherence is simply HTTP / JSON or XML.
For this little demo i choose Java:
A method to send/put the alert to the cache:
A method to query and view the content of the cache:
Finally the main method that execute our methods:
No special library added in the classpath for our class (json struct static defined), when it will be executed, it asks some information such as title, description,... in order to compose and send an alert to the cache and then it will perform an inquiry, to the same cache. At this point, a good exercise at this point, may be to create the same procedure using other technologies, such as a simple html page containing some JavaScript code, and then using Python, Ruby, and so on.
7) Now we are ready to start configuring the Oracle Service Bus in order to integrate the two products. First integrate the internal alerting system of Oracle Service Bus with our centralized alerting system based on coherence node. This ensures that by monitoring, or directly from within our Proxy Message Flow, we can throw alerts and save them directly into the Coherence node. To do this I choose to use the jms technology, natively present inside the Oracle Weblogic / Service Bus. Access to the Oracle WebLogic Administration console and create and configure a new JMS connection factory and a new jms destination (queue).
Now we should create a new resource of type “alert destination” within our Oracle Service Bus project. The new “alert destination” resource should be configured using the newly created connection factory jms and jms destination.
Finally, in order to withdraw the message alert enqueued in our JMS destination and send it to our coherence node, we just need to create a new business service and proxy service within our Oracle Service Bus project.
Our business service is responsible for sending a message to our REST service Coherence using as a method action: PUT
Finally our proxy service have to collect all messages enqueued on the destination, execute an xquery transformation on those messages in order to translate them into valid XML / alert objects useful to be sent to our coherence service, through the newly created business service.
The message flow pipeline containing the xquery transformation:
Incredibly, we just did a basic first integration between the native alerting system of Oracle Service Bus and our centralized alerting system by simply configuring our coherence node without developing anything.
It's time to test it out. To do this I create a proxy service able to generate an alert using our "alert destination", whenever the proxy is invoked.
After some invocation to our proxy that generates fake alerts, we could open an Internet browser and type the URL http://localhost: 8080/alerts/ so we could see what has been inserted within the coherence node.
8) We are ready for the final step. We would create a new message flow, that can be used to search and display the results in standard mode. To do this I choosen the standard representation of RSS, to display a formatted result on a huge variety of devices such as readers for the iPhone and Android. The inquiry may be defined already at the time of the request able to return only feed / items related to our needs.
To do this we need to create a new business service, a new proxy service, and finally a new XQuery Transformation to take care of translating the collection of alerts that will be return from our coherence node in a nicely formatted RSS standard document.
So we start right from this resource (xquery), which has the task of transforming a collection of alerts / xml returned from the node coherence in a type well-formatted feed RSS 2.0
our new business service that will search the alerts on our coherence node using the Rest API.
And finally, our last resource, the proxy service that will be exposed as an RSS / feeds to various mobile devices and traditional web readers, in which we will intercept any search query, and transform the result returned by the business service in an RSS feed 2.0.
The message flow with the transformation phase (Alert TO Feed Items):
Finally some little tricks to follow during the routing to the business service, - check for any queries present in the url to require a subset of alerts - the http header "Accept" to help get an answer XML instead of JSON:
In our little demo we also static added some coherence parameters to the request:
sort=time:desc;start=0;count=100
I would like to get from Coherence that the results will be sorted by date, and starting from 1 up to a maximum of 100.
Done!!
Just incredible, our centralized alerting system is ready.
Inheriting all the qualities and capabilities of the two products involved Oracle Coherence & Oracle Service Bus:
- RASP (Reliability, Availability, Scalability, Performance)
Now try to use your mobile device, or a normal Internet browser by accessing the RSS just published:
Some urls you may test:
Search for the last 100 alerts :
http://localhost:7001/alarms
Search for alerts that do not have time set to null (time is not null):
http://localhost:7001/alarms?q=time+is+not+null
Search for alerts that the system property is “Web Browser” (system = ‘Web Browser’):
http://localhost:7001/alarms?q=system+%3D+%27Web+Browser%27
Search for alerts that the system property is “Web Browser” and the severity property is “Fatal” and the title property contain the word “Javascript” (system = ‘Web Broser’ and severity = ‘Fatal’ and title like ‘%Javascript%’)
http://localhost:8080/alerts?q=system+%3D+%27Web+Browser%27+AND+severity+%3D+%27Fatal%27+AND+title+LIKE+%27%25Javascript%25%27
To compose more complex queries about your need I would suggest you to read the chapter in the coherence documentation inherent the Cohl language (Coherence Query Language) http://download.oracle.com/docs/cd/E24290_01/coh.371/e22837/api_cq.htm .
Some useful links:
- Oracle Coherence REST API Documentation http://download.oracle.com/docs/cd/E24290_01/coh.371/e22839/rest_intro.htm
- Oracle Service Bus Documentation http://download.oracle.com/docs/cd/E21764_01/soa.htm#osb
- REST explanation from Wikipedia http://en.wikipedia.org/wiki/Representational_state_transfer
At this URL could be downloaded the whole materials of this demo
http://blogs.oracle.com/slc/resource/cosb/coh-sb-demo.zip
Author: Nino Guarnacci.
© Oracle Blogs or respective owner