我有一个在独立域上运行的应用程序,但在集群设置中失败。
在我的应用程序中,我有一个 JCA 资源适配器,需要在 EIS 中的特定情况下通过 JMS 消息发送消息,因此在事件发生后的连接实现中,我调用 getJMSConnectionFactory
。
private Object lookup(String what) {
try {
// needs no environment
Context jndiContext = new InitialContext();
return jndiContext.lookup(what);
} catch (NamingException ex) {
throw MyProjectException.getInstance("lookup of " + what + " failed.", ex);
}
}
public ConnectionFactory getJMSConnectionFactory() throws JMSException {
return (ConnectionFactory)lookup("java:comp/DefaultJMSConnectionFactory");
}
我也以这种方式查找目标,然后发送 JMS 消息。现在,当我部署到单个域时,它可以按预期工作,但是当我尝试在集群设置中执行此操作时,我收到此异常(相关详细信息如下):
javax.ejb.EJBException
Caused by: myclasspath.MyProjectException: sayHelloyOverJMS
Caused by: myclasspath.MyProjectException: lookup of java:comp/DefaultJMSConnectionFactory failed.
Caused by: javax.naming.NamingException: Lookup failed for 'java:comp/DefaultJMSConnectionFactory' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NamingException: Lookup failed for 'jms/__defaultConnectionFactory' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NamingException: Unable to lookup resource : jms/__defaultConnectionFactory [Root exception is com.sun.appserv.connectors.internal.api.ConnectorRuntimeException: Lookup failed for '__SYSTEM/pools/jms/__defaultConnectionFactory-Connection-Pool' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming}]]]
Caused by: javax.naming.NamingException: Lookup failed for 'jms/__defaultConnectionFactory' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NamingException: Unable to lookup resource : jms/__defaultConnectionFactory [Root exception is com.sun.appserv.connectors.internal.api.ConnectorRuntimeException: Lookup failed for '__SYSTEM/pools/jms/__defaultConnectionFactory-Connection-Pool' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming}]]
Caused by: javax.naming.NamingException: Unable to lookup resource : jms/__defaultConnectionFactory [Root exception is com.sun.appserv.connectors.internal.api.ConnectorRuntimeException: Lookup failed for '__SYSTEM/pools/jms/__defaultConnectionFactory-Connection-Pool' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming}]
Caused by: com.sun.appserv.connectors.internal.api.ConnectorRuntimeException: Lookup failed for '__SYSTEM/pools/jms/__defaultConnectionFactory-Connection-Pool' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming}
Caused by: javax.naming.NamingException: Lookup failed for '__SYSTEM/pools/jms/__defaultConnectionFactory-Connection-Pool' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: jms]
Caused by: javax.naming.NameNotFoundException: jms
我认为相关细节是:
Lookup failed for '__SYSTEM/pools/jms/__defaultConnectionFactory-Connection-Pool'.
似乎找到了“__SYSTEM/pools”,但没有找到“jms”。我确实研究了 Glassfish 的 GUI 来配置连接池
jms/__defaultConnectionFactory-Connection-Pool
,但我在那里没有找到有关“目标”的任何信息,因此我认为它应该在整个域(包括集群)中可用。集群配置的“资源”选项卡未列出连接池(或与此相关的任何其他“__SYSTEM”条目)。
当我询问 glassfish 有哪些 JNDI 资源可用时:
$ asadmin list-jms-resources cluster_name
jms/DataFlowClusterCommunicationTopic
jms/__defaultConnectionFactory
Command list-jms-resources executed successfully.
$ asadmin list-jms-resources domain-1-instance
remote failure: The list-jms-resources command is not allowed on target domain-1-instance because it is part of cluster cluster_name
Command list-jms-resources failed.
$ asadmin list-jms-resources domain
jms/DataFlowClusterCommunicationTopic
jms/__defaultConnectionFactory
Command list-jms-resources executed successfully.
因此,据我了解,jms/__defaultConnectionFactory
名称存在,并且应该与域设置一样在集群设置中找到。
环境:
- AS:GlassFish Server 开源版 4.1.1(版本 1)
Java:
- openjdk 版本“1.8.0_111”
- OpenJDK 运行时环境(内部版本 1.8.0_111-8u111-b14-2-b14)
- OpenJDK 64 位服务器虚拟机(版本 25.111-b14,混合模式)
操作系统:Linux fuchs-linux-pc 4.7.0-1-amd64 #1 SMP Debian 4.7.8-1 (2016-10-19) x86_64 GNU/Linux
- 使用 Maven 3 构建
最佳答案
我发现这篇文章是因为当我尝试将项目从独立设置移动到集群设置时,我在 glassfish 版本 4.0 和 4.1.1 中遇到了同样的问题。
经过一些测试,我发现 glassfish 团队接受的一些问题仅在集群模式下与 jms 系统相关,就我能够测试的范围而言,从嵌入式 openmq 设置更改为 remote或者本地修复问题,系统在集群中运行良好。
这种行为让我认为问题与带有嵌入式 openMQ 设置的 JNDI 树有关
关于java - 在 Glassfish 集群上查找 JMS 连接工厂池失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40654378/