Clustered EJBs not being balanced in JBoss AS 7

2020-06-06 02:46发布

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.

1条回答
地球回转人心会变
2楼-- · 2020-06-06 03:12

It looks like you need to specify both servers in the properties building. Also it looks like there was a but in JBoss 7.1 so you should be using at least 7.2, check this link where the following sample was taken from:

Properties properties = new Properties();
properties.put("endpoint.name", "farecompare-client-endpoint");
properties.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");
properties.put("remote.connections", "cmc5101,cmc5102");
properties.put("remote.connection.cmc5101.host", "cmc5-101");
properties.put("remote.connection.cmc5101.port", "4447");
properties.put("remote.connection.cmc5101.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", "false");
properties.put("remote.connection.cmc5102.host", "cmc5-102");
properties.put("remote.connection.cmc5102.port", "4447");
properties.put("remote.connection.cmc5102.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", "false");
PropertiesBasedEJBClientConfiguration configuration = new PropertiesBasedEJBClientConfiguration(properties);
final ContextSelector ejbClientContextSelector = new ConfigBasedEJBClientContextSelector(configuration);
final ContextSelector previousSelector = EJBClientContext.setSelector(ejbClientContextSelector);
final Hashtable jndiProperties = new Hashtable();
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
final Context context = new InitialContext(jndiProperties);

Also this link might be helpful. Another useful link.

查看更多
登录 后发表回答