当前位置: 首页 > 知识库问答 >
问题:

远程JMS通信正常,EJB通信失败

江承嗣
2023-03-14

我目前正在介绍Java EE,特别是如何使用EJB和JMS。

我在internet上有一个本地客户端和一个远程服务器。JMS通信工作正常,EJB通信不正常。两种通信都在我的本地网络中成功。

我正在使用Maven构建:

  • 一个包含几个无状态远程EJB和一个MDB的EAR
  • 一个桌面客户端,其中包括Maven生成的用于与服务器通信的EJB客户端JAR。

我正在使用WildFly应用程序服务器来部署EAR。根据服务器日志,EJB已成功导出。所有流量都基于超文本传输协议-Remote ting。Undertow根据需要根据嗅探流量切换协议。

让我们以客户端登录为例。登录API调用基于远程EJB通信,同时发送JMS消息。

如果我从Eclipse在本地机器上同时运行客户端和服务器,登录工作正常,JMS消息处理正确。如果我在同一网络中的另一台计算机上运行客户端,则同样适用。如果在本地网络中运行客户端,但在internet中运行服务器,则EJB通信会失败,JMS消息仍能正确处理。

那是为什么呢?

远程EJB的登录方法没有被调用,没有日志。我添加了log4j。记录器。组织。jboss。ejb。客户端=跟踪到日志4J。属性。这是API调用失败时的客户端日志:

2015-06-21 16:47:49 [GS Desktop Init Thread] DEBUG PropertiesBasedEJBClientConfiguration:242 - endpoint.create.options. has the following options {}
2015-06-21 16:47:49 [GS Desktop Init Thread] TRACE PropertiesBasedEJBClientConfiguration:272 - Options {} have been merged with defaults {org.xnio.Options.THREAD_DAEMON=>true} to form {org.xnio.Options.THREAD_DAEMON=>true}
2015-06-21 16:47:49 [GS Desktop Init Thread] DEBUG PropertiesBasedEJBClientConfiguration:242 - remote.connectionprovider.create.options. has the following options {org.xnio.Options.SSL_ENABLED=>false}
2015-06-21 16:47:49 [GS Desktop Init Thread] TRACE PropertiesBasedEJBClientConfiguration:272 - Options {org.xnio.Options.SSL_ENABLED=>false} have been merged with defaults {} to form {org.xnio.Options.SSL_ENABLED=>false}
2015-06-21 16:47:49 [GS Desktop Init Thread] DEBUG PropertiesBasedEJBClientConfiguration:242 - remote.connection.default.connect.options. has the following options {org.xnio.Options.SASL_DISALLOWED_MECHANISMS=>[JBOSS-LOCAL-USER],org.xnio.Options.SASL_POLICY_NOANONYMOUS=>false}
2015-06-21 16:47:49 [GS Desktop Init Thread] TRACE PropertiesBasedEJBClientConfiguration:272 - Options {org.xnio.Options.SASL_DISALLOWED_MECHANISMS=>[JBOSS-LOCAL-USER],org.xnio.Options.SASL_POLICY_NOANONYMOUS=>false} have been merged with defaults {} to form {org.xnio.Options.SASL_DISALLOWED_MECHANISMS=>[JBOSS-LOCAL-USER],org.xnio.Options.SASL_POLICY_NOANONYMOUS=>false}
2015-06-21 16:47:49 [GS Desktop Init Thread] DEBUG PropertiesBasedEJBClientConfiguration:242 - remote.connection.default.channel.options. has the following options {}
2015-06-21 16:47:49 [GS Desktop Init Thread] DEBUG PropertiesBasedEJBClientConfiguration:490 - Connection org.jboss.ejb.client.PropertiesBasedEJBClientConfiguration$RemotingConnectionConfigurationImpl@33f49f38 successfully created for connection named default
2015-06-21 16:47:49 [GS Desktop Init Thread] DEBUG PropertiesBasedEJBClientConfiguration:295 - No clusters configured in properties
2015-06-21 16:47:49 [GS Desktop Init Thread] DEBUG EJBClientPropertiesLoader:100 - Looking for jboss-ejb-client.properties using classloader sun.misc.Launcher$AppClassLoader@58644d46
2015-06-21 16:47:49 [GS Desktop Init Thread] INFO  client:45 - JBoss EJB Client version 2.1.1.Final
...
2015-06-21 16:47:51 [Remoting "config-based-ejb-client-endpoint" task-4] DEBUG RemotingConnectionEJBReceiver:191 - Channel Channel ID eb5d763d (outbound) of Remoting connection 25bff644 to euve1234.vserver.de/84.46.96.86:8080 opened for context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@3baeae68, receiver=Remoting connection EJB receiver [connection=org.jboss.ejb.client.remoting.ConnectionPool$PooledConnection@3f310404,channel=jboss.ejb,nodename=euve1234]} Waiting for version handshake message from server
2015-06-21 16:47:51 [Remoting "config-based-ejb-client-endpoint" task-5] INFO  remoting:103 - EJBCLIENT000017: Received server version 2 and marshalling strategies [river]
2015-06-21 16:47:51 [GS Desktop Thread 0] INFO  remoting:218 - EJBCLIENT000013: Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@3baeae68, receiver=Remoting connection EJB receiver [connection=org.jboss.ejb.client.remoting.ConnectionPool$PooledConnection@3f310404,channel=jboss.ejb,nodename=euve1234]} on channel Channel ID eb5d763d (outbound) of Remoting connection 25bff644 to euve1234.vserver.de/84.46.96.86:8080
2015-06-21 16:47:51 [Remoting "config-based-ejb-client-endpoint" task-6] TRACE ChannelAssociation:375 - Received message with header 0x8
2015-06-21 16:47:51 [Remoting "config-based-ejb-client-endpoint" task-6] DEBUG RemotingConnectionEJBReceiver:763 - Received module availability report for 11 modules
2015-06-21 16:47:51 [Remoting "config-based-ejb-client-endpoint" task-6] DEBUG RemotingConnectionEJBReceiver:765 - Registering module EJBModuleIdentifier{appName='GSServerEAR-0.0.1', moduleName='GSAuthManagerEjb-0.0.1', distinctName=''} availability for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@3baeae68, receiver=Remoting connection EJB receiver [connection=org.jboss.ejb.client.remoting.ConnectionPool$PooledConnection@3f310404,channel=jboss.ejb,nodename=euve1234]}
2015-06-21 16:47:51 [Remoting "config-based-ejb-client-endpoint" task-6] DEBUG RemotingConnectionEJBReceiver:765 - Registering module EJBModuleIdentifier{appName='GSServerEAR-0.0.1', moduleName='GSNotificationManagerEjb-0.0.1', distinctName=''} availability for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@3baeae68, receiver=Remoting connection EJB receiver [connection=org.jboss.ejb.client.remoting.ConnectionPool$PooledConnection@3f310404,channel=jboss.ejb,nodename=euve1234]}
...
2015-06-21 16:47:51 [Remoting "config-based-ejb-client-endpoint" task-6] DEBUG RemotingConnectionEJBReceiver:765 - Registering module EJBModuleIdentifier{appName='GSServerEAR-0.0.1', moduleName='GSServerEAR-0.0.1', distinctName=''} availability for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@3baeae68, receiver=Remoting connection EJB receiver [connection=org.jboss.ejb.client.remoting.ConnectionPool$PooledConnection@3f310404,channel=jboss.ejb,nodename=euve1234]}
2015-06-21 16:47:51 [GS Desktop Thread 0] DEBUG ConfigBasedEJBClientContextSelector:174 - Registered 1 remoting EJB receivers for EJB client context org.jboss.ejb.client.EJBClientContext@3baeae68
...
2015-06-21 16:47:51 [JavaFX Application Thread] WARN  GsTask:38 - API call background task failed
java.lang.IllegalStateException: EJBCLIENT000025: No EJB receiver available for handling [appName:GSServerEAR, moduleName:GSAuthManagerEjb-0.0.1, distinctName:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@63dd58c4
    at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:774)
    at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:116)
    at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:186)
    at org.jboss.ejb.client.EJBInvocationHandler.sendRequestWithPossibleRetries(EJBInvocationHandler.java:255)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:200)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:183)
    at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:146)
    at com.sun.proxy.$Proxy7.createSession(Unknown Source)
    ...

问题是否由以下原因引起

  • IP无效?
    • 否。移动服务器后,我已更新了单机版。xml配置,我通过观察所有机器上的网络流量来确保接收到所有呼叫。JMS工作正常
    • 不。登录在本地工作。这些设置在移动服务器后应该有效。JMS和EJB都使用同一个WildFly应用程序用户。JMS工作。
    • 可能吧,但JMS可以工作。我还不太习惯JMS,但它不是基于RMI吗?我发送javax。jms。ObjectMessage会话。createObjectMessage(可序列化对象)采用可序列化对象,这就是为什么我建议这里也使用RMI
    • 关于Java和WildFly:它们独立于平台。编写一次,到处运行。我建议问题不太可能是由底层操作系统引起的。我已经验证了流量和JMS的工作原理。

    如果我错了,请纠正我。

    • 我知道这么久以来我提供的信息很少,因为我不想夸大我的问题。如果您需要更多信息,请随时询问。这也适用于代码
    • 我正在使用JavaSE 8/JavaEE 7。关于WildFly:我已经测试了8.1.0。最终,8.2.0。最终和9.0.0。Beta2。
    • 请不要简单地参考在线示例。我已经为此工作了好几天,请记住本地通信已经正常工作。

    我非常感谢大家对这件事的想法和评论,因为我真的被卡住了。非常感谢。

    服务器:

    @Remote
    public interface GsAuthManager {
    
        GsClientSession createSession(String username, String password);
    
    }
    
    @Stateless
    public class GsAuthManagerBean implements GsAuthManager {
    
        @Override
        public GsClientSession createSession(String username, String password) {
            // ...
        }
    
    }
    

    WildFly日志:

    java:jboss/exported/GSServerEAR/GSAuthManagerEjb-0.0.1/GsAuthManagerBean!de.genesys.server.ejb.auth.GsAuthManager
    

    客户:

    static void initEjbClient(String serverHostname, String username, String password) {
        final Properties ejbClientProps = new Properties();
        ejbClientProps.put("remote.connections", "default");
        ejbClientProps.put("remote.connection.default.port", "8080");
        ejbClientProps.put("remote.connection.default.host", serverHostname);
        ejbClientProps.put("remote.connection.default.username", username);
        ejbClientProps.put("remote.connection.default.password", password);
        ejbClientProps.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", "false");
        ejbClientProps.put("remote.connection.default.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS", "JBOSS-LOCAL-USER");
        ejbClientProps.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");
    
        EJBClientConfiguration clientConfig = new PropertiesBasedEJBClientConfiguration(ejbClientProps);
        ContextSelector<EJBClientContext> selector = new ConfigBasedEJBClientContextSelector(clientConfig);
        EJBClientContext.setSelector(selector);
    }
    
    static GsAuthManager initEjbProxy(String serverHostname, String username, String password) throws NamingException{
        Properties props = new Properties();
        props.put("jboss.naming.client.ejb.context", true);
        props.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false");
        props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
        props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
        props.put(Context.PROVIDER_URL, "http-remoting://" + serverHostname + ":8080");
        props.put(Context.SECURITY_PRINCIPAL, username);
        props.put(Context.SECURITY_CREDENTIALS, password);
        InitialContext context = new InitialContext(props); // Stripped down, original code keeps a strong reference and closes context on program termination 
        return (GsAuthManager) context.lookup("ejb:GSServerEAR/GSAuthManagerEjb-0.0.1/GsAuthManagerBean!de.genesys.server.ejb.auth.GsAuthManager");
    }
    

共有1个答案

西门智
2023-03-14

在deploy上获得的日志中,但出现异常时:appName:GSServerEAR。所以我认为,EAR文件的运行时(部署时)包含该版本,而它不应该包含该版本。

 类似资料:
  • 进程的管理主要是指进程的关闭与重启。我们一般关闭或重启软件,都是关闭或重启它的程序,而不是直接操作进程的。比如,要重启 apache 服务,一般使用命令"service httpd restart"重启 apache的程序。 那么,可以通过直接管理进程来关闭或重启 apache 吗?答案是肯定的,这时就要依赖进程的 信号(Signal)了。我们需要给予该进程号,告诉进程我们想要让它做什么。 系统中

  • 我试图连接我的java应用程序与SQL数据库和当我点击保存按钮它给我以下错误 这是我的密码

  • 进程间通信(Inter-Process Communication),简称IPC。 分类 管道通信 信号通信 共享内存通信* 信号量通信* 消息队列通信* 套接口(Socket)通信 全双工管道通信(部分Unix系统支持,Linux只支持半双工管道) 加星号*的三种通信方式,是源自于AT&T发行的System V(SYSV)版本的新IPC机制。 管道 管道pipe 命名管道FIFO FIFO 命名

  • 问题内容: Java上下文中的线程和进程之间有什么区别?用Java如何实现进程间通信和线程间通信?请给我指出一些现实生活中的例子。 问题答案: 根本的区别是线程位于相同的地址空间中,而进程位于不同的地址空间中。这意味着线程间通信是关于传递对对象的引用以及更改共享对象,而进程是关于传递对象的序列化副本。 在实践中,Java线程间通信可以实现为对共享对象进行简单的Java方法调用,并引入适当的同步。或

  • 问题内容: 我使用Java从Mysql查询一些记录。但是在某些持续时间的查询中,我遇到了使查询失败的问题,而在其他查询中,它查询成功了。错误消息是下一个: 我尝试了一些方法,例如: 设置 在 添加 到我的连接网址 但什么也没发生。 我的环境是: Mysql:5.5.3-m3-log源代码分发 的Java:1.6.0_16 JDK:HotSpot(TM)64位服务器VM(内部版本14.2-b01,混

  • 一、简介 查看和管理系统用户通信信息。 二、功能演示 1.查看和管理通信信息 查看通信信息,选择不需要的通信信息进行删除。如下图: