简体   繁体   English

在2节点Wildfly集群中调用远程ejb

[英]Invoking remote ejb in a 2-node wildfly cluster

I am trying to invoke remote ejb on each node of a cluster with nodes node1 & node2, but i am always getting node1. 我试图在具有节点node1&node2的群集的每个节点上调用远程ejb,但是我一直在获取node1。 Deployed EJB & client code as EAR file in both nodes. 在两个节点中将EJB和客户端代码部署为EAR文件。 Application is running on Wildfly 9 ApplicationServer. 应用程序在Wildfly 9 ApplicationServer上运行。 Invoked client code from node1. 从node1调用了客户端代码。

EJB code : 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);
       }
    }
}

client code: 客户代码:

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);
           }
       }
   }
}

In the logs, 在日志中

node: "node1", binddbejb object: 1276422461
node: "node2", binddbejb object: 1276422461
nodename: "node1_address"
nodename: "node1_address" (instead of node2_address)

Please suggest 请建议

In order to use a clustered EJB wild fly needs to be configured for clustering and as far as I have found: 为了使用集群化的EJB,需要对集群进行配置,而据我所知:

  1. Wildfly provides clustering of stateful EJBs. Wildfly提供有状态EJB的集群。
  2. Wild fly documentation provides an example of a failover scenario for clustering. Wild fly文档提供了群集故障转移方案的示例。 (Client tries to contact ejb on server #1 , if it is unavailable then client contacts the ejb on server #2.) (客户端尝试与服务器#1上的ejb联系,如果不可用,则客户端与服务器#2上的ejb联系。)
  3. Clustered Ejbs need to be configured as needed and annotated properly. 集群Ejb需要根据需要进行配置并正确注释。
 import org.jboss.ejb3.annotation.Clustered; import javax.ejb.Stateful; @Stateful @Clustered public class MyStatefulBean { ... } 

Examples are given from this page of the documentation, which describes what has to be done in detail. 文档的此页面提供了示例,其中详细描述了必须执行的操作。 https://docs.jboss.org/author/display/WFLY8/EJB+Services https://docs.jboss.org/author/display/WFLY8/EJB+Services

If you apply this configuration EJBs from all nodes of the cluster could serve the client. 如果应用此配置,则来自集群所有节点的EJB都可以为客户端提供服务。

However do note that a client should normally be completely unaware of the clustering. 但是请注意,客户端通常通常完全不了解群集。 A clients needs to call the ejb and it should be up to the cluster to decide which instance serves the client. 客户端需要调用ejb,并且应该由集群决定哪个实例为客户端提供服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM