Software Engineering

Sample Coherence Cluster in Weblogic 12c

Nicolas Fonnegra
Nicolas Fonnegra

Oracle Coherence plays an essential role inside the Oracle Cloud Application Foundation by providing an in-memory data grid for real-time data and event processing. Coherence delivers a series of features and benefits such as partitioned data caching,  support for Java/C++/.Net/Rest clients, distributed agents for remote data processing, real-time data query, event processing, transaction management and JPA support among others.

This blog will demonstrate how to create a sample Coherence cluster in Weblogic. A sample Java application will also be developed and it will be in charge of storing data into the Coherence cluster and consuming it. This sample cluster will be used as a starting point for future blog entries that will demonstrate other Coherence features.

The whole exercise follows these steps:

  • Configuration of the Coherence Cluster in Weblogic
  • GAR archive definition
  • Java client development
  • Deployment

Coherence Cluster Configuration

We will take a demo Weblogic domain with an admin server and two manage servers as a starting point.


Coherence Cluster

Coherence clusters can be configured between any independent manage server. In this sample, the two managed server happen to be in a Weblogic cluster, but this is not necessary.

The definition of a Coherence cluster follows these steps:

  • In the Weblogic Admin Console, go to Enviroment -> Coherence Cluster and click “New”
  • Enter a name (I will use “CoherenceCluster” in this example) and click “Next”
  • Define 8088 as Unicast Listen Port and click “Next” (In production environments multicast is recommend, if possible)
  • Select the two managed server as the target for the Coherence cluster and click “Finish”.

GAR Archive

The Grid Archive file (GAR file) is a deployable artifact that contains a Coherence cache configuration. Coherence caches can be defined globally in Weblogic but applications can deploy their own cache configuration. A GAR can be viewed as the JAR file for Coherence clusters and it follows this structure:


JDeveloper 12c provides a specific project structure for developing Coherence cluster applications. In the Project Gallery search for “Coherence Project” and then select “Oracle Coherence” in the Project Features screen.

GAR Project Wizard

GAR Project Wizard

The coherence-application.xml file configures the path to the cache configuration file (coherence-cache-config.xml). This file also helps the container to identify this artifact as a GAR. Here is an example of the coherence-application.xml file

In this sample we will be using a basic distributed coherence cluster. This configuration is defined inside the coherence-cache-config.xml file

Java Client Development

The Java client uses the Java API to put information into the cache and also to consume it. In this sample we will fill a simple Map with the names of the British Premier League clubs with a corresponding ID.

Here are is a sample of how to fill the cache

and here is how to read from it

The name of the cache, testCache, is the one that was defined in the coherence-cache-config.xml file.

Two different servlets were developed for this sample. One is intended to print the contents of the cache and the other one for automatically loading the data (in other words, calling the fillCacheWithSampleData() method)


We are going to deploy an EAR file containing the GAR and WAR artifacts. A deployment artifact has to be generated for each one of the artifacts. For the GAR file right click the coherence project -> Project Properties -> Deployment. Create a new profile and select GAR File in the Profile Type select Box.

Deployment descriptor GAR

In the new screen, go to File Groups -> Coherence -> Filters and make sure that the Coherence files and also the application classes, if any, are selected.


There are no special steps for the WAR. Just create a standard WAR deployment.

For the EAR file, the weblogic-application deployment descriptor has to be created in order to define the GAR as a module. Go to File-> New-> From Gallery -> General -> Deployment Descriptors ->Weblogic Deployment Descriptor. In the new screen select weblogic-application.xml, click next, choose the version and the click on Finish.


Here is a sample on how to the declare the GAR module:

The application.xml deployment descriptor has to be generated too in order to define the WAR as a module. The process to generate this file is very similar: Go to File-> New-> From Gallery -> General -> Deployment Descriptors- > Java EE Deployment Descriptor. In the new screen select application.xml, click next, choose the version and the click on Finish. Here is a sample on how to the declare the Web module:

After deploying the EAR, the consuming servlet can be called. It won’t deliver any information, as expected. So the next thing to do is to call the producer to fill the cache, and we will use the port (8001) of the first manage server.



Now we can call the consuming servlet from the other managed server using port 9001.


As we can see, the cluster is working between the two managed servers and the data saved in one manage server can be accessed by the other manage server. There is also one important finding. Coherence cache maps are intended to work like normal Java Maps; the order in which the data is saved is not the same order as the one that is being delivered. In other words, there is no guarantee in which order the data from the cache map can be retrieved.


Coherence Datasheet
Coherence Developers Guide