Search code examples
jakarta-eejmswildfly-8message-driven-bean

Getting error while initializing JMS in Wildfly 8.2.0


I am working on MDB in wildfly 8.2.0. Server configuration used is standalone-full-ha.xml. I am getting the below error trace when the line Connection connection = connectionFactory.createConnection() gets executed.

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)

code snippet

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

Getting the below error when calling getObject() on the accessed message as JMS and the required queue is not initialized because of the above error.

Is it problem with the JNDI name java:/ConnectionFactory ?

Code snippet

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

Error

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:]

Is the value of jms-connection-factoryattribute below need to be modified from java:jboss/DefaultJMSConnectionFactory to java:/ConnectionFactory or any other configuration problem ?

<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>

Please help me about why the error occurs and how to resolve the same. Many thanks.


Solution

  • Add this in the standalone.xml

                   <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>
    

    And the Java code

    @Resource(mappedName = "java:/ConnectionFactory")
    private ConnectionFactory connectionFactory;