在Wildfly 8.2.0中初始化JMS时出错

时间:2015-04-02 12:04:01

标签: java-ee jms wildfly-8 message-driven-bean

我正在使用wildfly 8.2.0开发MDB。使用的服务器配置为standalone-full-ha.xml。当行Connection connection = connectionFactory.createConnection()被执行时,我得到以下错误跟踪。

TRACE [org.hornetq.core.client] (pool-14-thread-1) getConnectionWithRetry::1 with retryInterval = 2000 multiplier = 1.0: java.lang.Exception: trace
at org.hornetq.core.client.impl.ClientSessionFactoryImpl.getConnectionWithRetry(ClientSessionFactoryImpl.java:1103)
at org.hornetq.core.client.impl.ClientSessionFactoryImpl.connect(ClientSessionFactoryImpl.java:266)
at org.hornetq.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:881)
at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:669)
at org.hornetq.jms.client.HornetQConnectionFactory.createConnection(HornetQConnectionFactory.java:112)
at org.hornetq.jms.client.HornetQConnectionFactory.createConnection(HornetQConnectionFactory.java:107)

代码段

       try {
                InitialContext initialContext = new InitialContext();
                Object objRef = initialContext.lookup("java:/ConnectionFactory");
                ConnectionFactory connectionFactory = (QueueConnectionFactory) objRef;
                Connection connection = connectionFactory.createConnection();
            } finally {
                initialContext.close();
            }

在访问的消息上调用getObject()作为JMS时出现以下错误,并且由于上述错误而未初始化所需的队列。

JNDI名称java:/ConnectionFactory有问题吗?

代码段

ObjectMessage objMsg = (ObjectMessage) msg;     
Context c = (Context) objMsg.getObject();

错误

ERROR [org.hornetq.ra] (Thread-2 (HornetQ-client-global-threads-23377593)) HQ154004: Failed to deliver message: javax.jms.JMSException: com.test.Context from [Module "org.hornetq:main" from local module loader @13205e1 (finder: local module finder @1201837 (roots: D:\wildfly-8.2.0.Final\modules,D:\wildfly-8.2.0.Final\modules\system\layers\base))]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:213)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:459)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:408)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:389)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:134)
at java.lang.Class.forName0(Native Method) [rt.jar:1.7.0_67]
at java.lang.Class.forName(Class.java:270) [rt.jar:1.7.0_67]
at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:625) [rt.jar:1.7.0_67]
at org.hornetq.utils.ObjectInputStreamWithClassLoader.resolveClass0(ObjectInputStreamWithClassLoader.java:127) [hornetq-core-client-2.4.5.Final.jar:]
at org.hornetq.utils.ObjectInputStreamWithClassLoader.resolveClass(ObjectInputStreamWithClassLoader.java:55) [hornetq-core-client-2.4.5.Final.jar:]
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1612) [rt.jar:1.7.0_67]
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1517) [rt.jar:1.7.0_67]
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771) [rt.jar:1.7.0_67]
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350) [rt.jar:1.7.0_67]
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370) [rt.jar:1.7.0_67]
at org.hornetq.jms.client.HornetQObjectMessage.getObject(HornetQObjectMessage.java:155) [hornetq-jms-client-2.4.5.Final.jar:]

以下jms-connection-factory属性的值是否需要从java:jboss/DefaultJMSConnectionFactory修改为java:/ConnectionFactory或任何其他配置问题?

<subsystem xmlns="urn:jboss:domain:ee:2.0">
...
<default-bindings context-service="java:jboss/ee/concurrency/context/default" datasource="java:/TestDB" jms-connection-factory="java:jboss/DefaultJMSConnectionFactory" managed-executor-service="java:jboss/ee/concurrency/executor/default" managed-scheduled-executor-service="java:jboss/ee/concurrency/scheduler/default" managed-thread-factory="java:jboss/ee/concurrency/factory/default"/>
</subsystem>

请帮我解释错误发生的原因以及如何解决错误。非常感谢。

1 个答案:

答案 0 :(得分:0)

在standalone.xml中添加

print dsk

和Java代码

               <jms-connection-factories>
                    <connection-factory name="InVmConnectionFactory">
                        <connectors>
                            <connector-ref connector-name="in-vm"/>
                        </connectors>
                        <entries>
                            <entry name="java:/ConnectionFactory"/>
                        </entries>
                    </connection-factory>
                    <connection-factory name="RemoteConnectionFactory">
                        <connectors>
                            <connector-ref connector-name="netty"/>
                        </connectors>
                        <entries>
                            <entry name="RemoteConnectionFactory"/>
                            <entry name="java:jboss/exported/jms/RemoteConnectionFactory"/>
                        </entries>
                    </connection-factory>
                    <pooled-connection-factory name="hornetq-ra">
                        <transaction mode="xa"/>
                        <connectors>
                            <connector-ref connector-name="in-vm"/>
                        </connectors>
                        <entries>
                            <entry name="java:/JmsXA"/>
                        </entries>
                    </pooled-connection-factory>
                </jms-connection-factories>