I've successfully setup a cluster of 2 JBoss AS 7 instances, and deployed the following SLSB:
@Stateless
@Remote(TestEJBRemote.class)
@Clustered
public class TestEJB implements TestEJBRemote {
private static final long serialVersionUID = 1L;
private static final Logger logger = Logger.getLogger(...);
@Override
public void test() {
String nodeName = System.getProperty("jboss.node.name");
logger.info(nodeName);
}
}
From the log files I can see that the bean is correctly deployed on the cluster. On the client side I then create a number of threads that lookup and invoke an instance of TestEJB
. However, it appears that all instances end-up in the same node.
Here's the "jndi.properties" file:
java.naming.factory.url.pkgs=org.jboss.ejb.client.naming
And "jboss-ejb-client.properties":
endpoint.name=client-endpoint
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
remote.connections=default
remote.connection.default.host=192.168.0.1
remote.connection.default.port=4447
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
remote.connection.default.username=user
remote.connection.default.password=pass
remote.clusters=ejb
remote.cluster.ejb.clusternode.selector=org.jboss.ejb.client.RandomClusterNodeSelector
In the client I do final InitialContext ctx = new InitialContext();
and then form within each thread:
String name = "ejb:/test//TestEJB!" + TestEJBRemote.class.getName();
TestEJBRemote remote = (TestEJBRemote) ctx.lookup(name);
remote.test();
What is it that I'm doing wrong?
UPDATE
If I specify only the second node in the connection list, I get:
java.lang.IllegalStateException: No EJB receiver available for handling [...] combination for invocation context org.jboss.ejb.client.EJBClientInvoc
ationContext
So probably this issue needs to be resolved first...
UPDATE 2
I solved the problem eventually, by setting up an application user in the slave node. Before, I was trying to connect as the management user, which didn't work.
The load-balancing now works as well, as long as I specify a slave node in the connection list (in "jboss-ejb-client.properties"). If I specify the master node, all EJBs will end-up in that node only. This solution is sufficient for me, however.