我已经成功设置了 2 个 JBoss AS 7 实例的集群,并部署了以下 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);
}
}
从日志文件我可以看到 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=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
在客户端我做
final InitialContext ctx = new InitialContext();
然后在每个线程中形成:String name = "ejb:/test//TestEJB!" + TestEJBRemote.class.getName();
TestEJBRemote remote = (TestEJBRemote) ctx.lookup(name);
remote.test();
我做错了什么?
更新
如果我只指定连接列表中的第二个节点,我会得到:
java.lang.IllegalStateException: No EJB receiver available for handling [...] combination for invocation context org.jboss.ejb.client.EJBClientInvoc
ationContext
所以可能这个问题需要先解决......
更新 2
我最终通过在从节点中设置应用程序用户解决了这个问题。之前,我试图以管理用户的身份进行连接,但没有成功。
只要我在连接列表中指定一个从节点(在“jboss-ejb-client.properties”中),负载平衡现在也能正常工作。如果我指定主节点,则所有 EJB 将仅在该节点中结束。然而,这个解决方案对我来说已经足够了。
最佳答案
看起来您需要在属性构建中指定两个服务器。看起来 JBoss 7.1 中也有一个但是,所以你应该至少使用 7.2,check this link以下样本取自:
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);
还有 this link可能会有所帮助。
另一个 useful link .
关于jakarta-ee - 集群 EJB 在 JBoss AS 7 中没有得到平衡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15749897/