JBoss AS 7中的集群EJB不兼容 [英] Clustered EJBs not being balanced in JBoss AS 7
问题描述
我已经成功建立了2个JBoss AS 7实例集群,并部署了以下SLSB:
@Stateless
@Remote(TestEJBRemote.class)
@Clustered
public class TestEJB实现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);
}
}
从日志文件中我可以看到,bean正确部署在簇。在客户端,我然后创建一些查询并调用 TestEJB
的实例的线程。但是,似乎所有实例都在同一个节点中。
这是jndi.properties文件:
java.naming.factory.url.pkgs = org.jboss.ejb.client.naming
和jboss-ejb-client.properties:
endpoint.name = client-endpoint
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED = false
remote.connections =默认
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
在客户端我做 final InitialContext ctx = new InitialContext();
然后每个线程内的表单:
String name =ejb:/ test // TestEJB! + TestEJBRemote.class.getName();
TestEJBRemote remote =(TestEJBRemote)ctx.lookup(name);
remote.test();
我做错了什么?
更新
如果我只指定连接列表中的第二个节点,我得到: p>
java.lang.IllegalStateException:没有EJB接收器可用于处理[...]组合用于调用上下文org.jboss.ejb.client.EJBClientInvoc
ationContext
所以可能这个问题需要先解决...
更新2
最终通过在从属节点中设置应用程序用户来解决问题。之前,我试图连接作为管理用户,这是不起作用的。
负载平衡现在也可以,只要我指定一个从节点在连接列表中(在jboss-ejb-client.properties中)。如果我指定了主节点,则所有EJB将仅在该节点中结束。这个解决方案对我来说足够了。
看起来你需要在属性构建中指定两个服务器。此外,它似乎有一个但是在JBoss 7.1中,所以你应该使用至少7.2,检查此链接,其中以下示例来自:
属性属性= 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);
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.
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.
这篇关于JBoss AS 7中的集群EJB不兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!