google Analytics

Monday, September 20, 2010

Jboss Cluster Configuration


Jboss Cluster Configuration



=============================================================
 

Starting with a newly unzipped copy of JBoss, navigate into the server
directory and copy the
 all directory twice: once to a directory called
node1 and once to a directory called node2. The contents of your server
directory should now look like that




Issue the following command

run -c node1 -g  cluster1 -u 239.255.100.100 -b localhost -Djboss.messaging.ServerPeerID=1 -Djboss.service.binding.set=ports-01
run  -c node2 -g cluster2 -u 239.255.100.100 -b localhost -Djboss.messaging.ServerPeerID=1 -Djboss.service.binding.set=ports-02





=============================================================

Creating a clustered EJB

The remote interface for a clustered SLSB
import javax.ejb.Remote;
@Remote
public interface TestRemote {
  public void sayHello(String msg);
}

The bean code for a clustered SLSB
import javax.ejb.Stateless;
import org.jboss.ejb3.annotation.Clustered;
@Stateless
@Clustered
public class TestBean implements Counter {
  public void sayHello(String msg) {
    System.out.println(countNumber);
  }
}
 
@org.jboss.ejb3.annotation.Clustered annotation defined.
This annotation tells the server that this bean is clustered and should be load balanced.



Calling the clustered EJB
The client code that calls the clustered SFSB

import javax.naming.Context;
import javax.naming.InitialContext;
public class Client {
  public static void main(String[] args) throws Exception {
    InitialContext ctx = new InitialContext();
    TestRemote s = (TestRemote) ctx.lookup("TestBean/remote");
    for (int i = 0; i < 100; i++) {
      s.sayHello("Anish")
      Thread.sleep(1000);
    }
  }
}


includes the client/jbossallclient.jar in your classpath
The Jndi.properties file
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming

=========================================
jboss clustering example/clustering with JBOSS 5.0/ejb
jboss clustering step by step
jboss clustering step by step
@clustered annotation
EJB Clustering Example
===============================================

ANish

No comments:

Post a Comment