Pages - Menu

Weblogic Server - Coherence Configuration Example

Friday, July 26, 2013

Weblogic Server - Coherence Configuration

For theoretical knowledge on coherence read my this post - http://weblogicserveradministration.blogspot.com/2011/05/oracle-coherence-37-coherenceweb.html

In this post I am going to cover practical example on Coherence


I have used Weblogic Server 10.3.5 + Coherence 3.6

High Level Steps


1.  Install weblogic server 10.3.5 with coherence 3.6 or 3.7

2.  Create a domain
3.  Create a machine, start node manager and check status from console if it's accessible
4.  Create a a simple cluster with two managed servers, and assign both managed servers to 
      machine
5.  Create a Coherence cluster and assign your above defined cluster to coherence cluster
      [ OR instead of above step2 and step3, you can just create two managed servers, then  
         create a coherence cluster and assign both managed servers to this coherence cluster ]
6.  Start a cache server
7.  Start both managed servers
8.  Deploy shared library files
9.  Create a testing application and deploy on cluster
10.Test 

Steps


1. For installation see my other post 
http://learn-weblogic.blogspot.in/2013/07/weblogic-server-installation-console.html

2. For domain creation see my other post

http://learn-weblogic.blogspot.in/2013/07/create-domain-in-gui-mode.html
http://learn-weblogic.blogspot.in/2013/07/weblogic-domain-creation-in-console.html
http://learn-weblogic.blogspot.in/2013/07/domain-creation-in-console-mode-on.html

3. For machine,node manager configuration see my other post
http://learn-weblogic.blogspot.in/2013/07/configure-start-stop-node-manager-step.html


4. To create a simple cluster and assign servers to cluster see my other post
http://learn-weblogic.blogspot.in/2013/07/vertical-clustering-step-by-step.html

5. Create a coherence cluster and assign your above created cluster to this coherence cluster

a. Login to admin console
b. Click on Coherence Clusters option on left hand side panel
c. Do the configuration like below and save

Unicast Listen Address - your machine hostname or i.p
Unicast Listen Post - 8085 ( or any other available port of your machine )
Multicat Listen Address - 231.1.1.1 ( or any multicast range available i.p but make sure this need to update in coherence server startup script which i will explain later )
Multicast Listen Port - 7777 ( or you can use any other available port of your machine but make sure this need to update in coherence server startup script which i will explain later )




After creating coherence cluster, click on Target tab and assign your previously create simple cluster to this coherence cluster

Now you can see like below under coherence cluster option



6. Start Cohrence Server

Copy the below contents, paste in a text file and rename it as .bat ( on windows )
( if you are on unix based systems then change scripts variable settings, path etc accordingly )

Start-Coherence.bat

setlocal

set COHERENCE_HOME=C:\Oracle\Middleware2\coherence_3.6
set COH_OPTS=%COH_OPTS% -server -cp %COHERENCE_HOME%\lib\coherence.jar;%COHERENCE_HOME%\lib\coherence-web-spi.war;
set COH_OPTS=%COH_OPTS% -Dtangosol.coherence.management.remote=true -Dtangosol.coherence.cacheconfig=/WEB-INF/classes/session-cache-config.xml -Dtangosol.coherence.distributed.localstorage=true -Dtangosol.coherence.clusterport=7777 -Dtangosol.coherence.clusteraddress=231.1.1.1 -Dtangosol.coherence.session.localstorage=true
java %COH_OPTS% -Xms256m -Xmx256m -XX:MaxPermSize=256m com.tangosol.net.DefaultCacheServer
:exit

Now start above create script

Output should be like below



7. Start both managed servers from console


8.  Deploy below shared libraries on your cluster ( During deployment make sure to choose 
     option deploy this file as library not application for both files )
coherence-web-spi.war from  ORACLE_HOME\coherence_3.6\lib and  active-cache-1.0.jar  
  from  ORACLE_HOME\wlserver_10.3\common\deployable-libraries

9.  Create a testing application like below

[1] Create a folder CoherenceTest
[2] Inside CoherenceTest folder create 
      a. META-INF folder, Inside it a file with name manifest.mf with below contents


Extension-List: active-cache
active-cache-Extension-Name: active-cache
active-cache-Specification-Version: 1.0
active-cache-Implementation-Version: 1.0


 [3] WEB-INF folder
        
        3.1 inside it, create a file web.xml with below contents

               <?xml version = '1.0' encoding = 'windows-1252'?>
               <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web- 
               app_2_4.xsd" 
               xmlns="http://java.sun.com/xml/ns/j2ee" version="2.5">
              <description>Empty web.xml file for Web Application</description>       
             </web-app>
        
         3.2 inside it, create a file weblogic.xml with below contents

         <weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app"  
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
         xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-web-app 
         http://www.oracle.com/technology/weblogic/weblogic-web-app/1.1/weblogic-web-app.xsd">
         <library-ref>
           <library-name>coherence-web-spi</library-name>
         </library-ref>
         <coherence-cluster-ref>
            <coherence-cluster-name>CoherenceCluster</coherence-cluster-name>
         </coherence-cluster-ref> 
           </weblogic-web-app>

( Make sure here cluster name exactly the same you have given to your coherence cluster )

        3.3 inside it, create a folder with name lib and copy coherence.jar file from 
               COHERENCE_HOME\lib to here ( ORACLE_HOME\coherence_3.6\lib in my case )
        
 [4]. A jsp file with name counter.jsp ( copy and paste below code inside it )


<html>
    <body>
<h3>
      Counter :
      <%
         Integer counter = new Integer(1);
         HttpSession httpsession = request.getSession(true);
         if (httpsession.isNew()) {
                httpsession.setAttribute("count", counter);
                out.println(counter);
         } else {
                int count = ((Integer) httpsession.getAttribute("count")).intValue();
                httpsession.setAttribute("count", new Integer(++count));
                out.println(count);
         }
      %>
      </h3>

    </body>
</html>


Below is the structure


10. Deploy this CoherenceTest application as in exploded form on your cluster

11. Test

Now, first access you application using first managed server URL

http://host:first_managed_server_port/CoherenceTest/counter.jsp

it will show you as counter : 1


After that access your application using second managed server URL

http://host:second_managed_server_port/CoherenceTest/counter.jsp

it will show you counter : 2



So, here session shared on your external coherence server and shared across servers on your cluster..

you are done...cheers!!!!!!!

No comments:

Post a Comment

 

Archives

Blogger news

Blogroll

Most Reading