美好的一天,我在理解从独立的远程Java客户端成功调用位于集群中的EJB所需的内容(包括服务器配置)时遇到问题。到目前为止,我已经尝试了jboss的两个官方指南,到目前为止我的解决方案只能部分工作。
https://docs.jboss.org/author/display/WFLY9/WildFly+9+Cluster+Howto https://docs.jboss.org/author/display/WFLY9/EJB+invocations+from+a+remote+client+using+JNDI
目前在客户端,我正在使用“client bom”maven依赖:
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-ejb-client-bom</artifactId>
<version>10.0.0.Final</version>
<type>pom</type>
</dependency>
JNDI查找的初始上下文填充了下一个数据:
Properties env = new Properties();
env.put(Context.PROVIDER_URL, "http-remoting://somehost:8080");
env.put(Context.SECURITY_PRINCIPAL, "client");
env.put(Context.SECURITY_CREDENTIALS, "clientPassword");
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
env.put("jboss.naming.client.ejb.context", true);
所有EJB都标有@ Stateless,@ Cluster和@Remote注释。 如果我使用上面的配置与一个公共部署(不是一个集群),一切正常,并按照预期。但是,如果我尝试连接到我的一个集群实例,我将获得下一个响应(其中“backend2”是集群中的两个实例之一):
[INFO] | 19:26:35.838 | [THREAD: ejb-client-cluster-node-connection-creation-3-thread-1 | CLASS: org.jboss.ejb.client.remoting.RemotingConnectionClusterNodeManager] -> Could not create a connection for cluster node ClusterNode{clusterName='ejb', nodeName='master:backend2', clientMappings=[ClientMapping{sourceNetworkAddress=/0:0:0:0:0:0:0:0, sourceNetworkMaskBits=0, destinationAddress='172.31.28.21', destinationPort=8280}], resolvedDestination=[Destination address=172.31.28.21, destination port=8280]} in cluster ejb
java.lang.RuntimeException: Operation failed with status WAITING
at org.jboss.ejb.client.remoting.IoFutureHelper.get(IoFutureHelper.java:94) ~[jboss-ejb-client-2.1.4.Final.jar:2.1.4.Final]
at org.jboss.ejb.client.remoting.ConnectionPool.getConnection(ConnectionPool.java:80) ~[jboss-ejb-client-2.1.4.Final.jar:2.1.4.Final]
at org.jboss.ejb.client.remoting.RemotingConnectionManager.getConnection(RemotingConnectionManager.java:51) ~[jboss-ejb-client-2.1.4.Final.jar:2.1.4.Final]
at org.jboss.ejb.client.remoting.RemotingConnectionClusterNodeManager.getEJBReceiver(RemotingConnectionClusterNodeManager.java:79) [jboss-ejb-client-2.1.4.Final.jar:2.1.4.Final]
at org.jboss.ejb.client.ClusterContext$EJBReceiverAssociationTask.call(ClusterContext.java:469) [jboss-ejb-client-2.1.4.Final.jar:2.1.4.Final]
at org.jboss.ejb.client.ClusterContext$EJBReceiverAssociationTask.call(ClusterContext.java:443) [jboss-ejb-client-2.1.4.Final.jar:2.1.4.Final]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_92]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_92]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_92]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_92]