我正在尝试在具有节点 node1 和 node2 的集群的每个节点上调用远程 ejb,但我总是得到 node1。将 EJB 和客户端代码部署为两个节点中的 EAR 文件。应用程序在 Wildfly 9 ApplicationServer 上运行。从 node1 调用客户端代码。
EJB 代码:
@Remote
public interface SLSBRemote {
public void test();
}
@Stateless(mappedName="SLSBEJB")
public class SLSBEJB implements SLSBRemote {
@Override
public void test()
{
try {
String nodeName = System.getProperty("jboss.node.name");
if(nodeName == null) {
nodeName = InetAddress.getLocalHost().getHostName();
}
log.debug("nodename: "+nodeName);
} catch (Exception e) {
log.error("Error",e);
}
}
}
客户端代码:
public class testEjb
{
//invoking this method from other class. Able to pass node address
public void testBean(List<String> nodes)
{
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
Context context;
for (String node : nodes) {
properties.put(Context.PROVIDER_URL,"http-remoting://" + node);
try {
context = new InitialContext(properties);
SLSBRemote slsbRemote=(SLSBRemote)context.lookup(getLookupName());
log.debug("node:"+node+"slsbejbobject:"+slsbRemote.hashCode());
slsbRemote.test();
} catch (NamingException e) {
log.error("Error ", e);
}
}
}
}
在日志中,
node: "node1", binddbejb object: 1276422461
node: "node2", binddbejb object: 1276422461
nodename: "node1_address"
nodename: "node1_address" (instead of node2_address)
请建议