简体   繁体   中英

Different JMS providers in Websphere and JMS

Way 1 : Third-party messaging provider

I use Websphere application Server 8.5.5 and I configured the queue by creating
my JMS provider as mentioned in the link1 and link2

(In classpath :where I used fscontext jar and required required ibm jms jars and ). QueueConnectionFactory with my jms provider.

In application I use jms to put meesages to the queue.

  @Resource(lookup = "jms/ConnectionFactory")
  private static QueueConnectionFactory connectionFactory;

  @Resource(lookup = "jms/Queue")
  private static Queue queue;

  public void putMessagesToQueue() {                                                                   
  try {
     // create a queue connection
     QueueConnection queueConn = connFactory.createQueueConnection();
     ......... 
  } catch(JMSException exp) {
       // Handle this exception
   } finally {      
        if(queueConn != null) {                                                     
             // close the queue connection
            queueConn.close();
        } else {
          System.out.println("Queue connection is null");
        }
   }

I get the below exception at line connFactory.createQueueConnection(). I see the sysout in final block is getting printed as "Queue connection is null".

Exception :

javax.jms.JMSException: Failed to create queue connection
    at com.ibm.ejs.jms.JMSCMUtils.mapToJMSException(JMSCMUtils.java:140) ~[com.ibm.ws.runtime.jar:na]
    at com.ibm.ejs.jms.JMSQueueConnectionFactoryHandle.createQueueConnection(JMSQueueConnectionFactoryHandle.java:91) ~[com.ibm.ws.runtime.jar:na]

getLinkedException()=javax.resource.spi.ResourceAllocationException: Expected QueueConnectionFactory

Caused by: java.lang.ClassCastException: com.ibm.mq.jms.MQConnectionFactory incompatible with javax.jms.QueueConnectionFactory
    at com.ibm.ejs.jms.JMSManagedQueueConnection.createConnection(JMSManagedQueueConnection.java:157) ~[com.ibm.ws.runtime.jar:na]
    at com.ibm.ejs.jms.JMSManagedConnection.<init>(JMSManagedConnection.java:352) ~[com.ibm.ws.runtime.jar:na]
    at com.ibm.ejs.jms.JMSManagedQueueConnection.<init>(JMSManagedQueueConnection.java:72) ~[com.ibm.ws.runtime.jar:na]
    at com.ibm.ejs.jms.GenericJMSManagedQueueConnectionFactory.createManagedConnection(GenericJMSManagedQueueConnectionFactory.java:92) ~[com.ibm.ws.runtime.jar:na]
    at com.ibm.ejs.jms.JMSManagedConnectionFactory.createManagedConnection(JMSManagedConnectionFactory.java:687) ~[com.ibm.ws.runtime.jar:na]
    at com.ibm.ejs.j2c.FreePool.createManagedConnectionWithMCWrapper(FreePool.java:2160) ~[com.ibm.ws.runtime.jar:na]
    at com.ibm.ejs.j2c.FreePool.createOrWaitForConnection(FreePool.java:1838) ~[com.ibm.ws.runtime.jar:na]
    at com.ibm.ejs.j2c.PoolManager.reserve(PoolManager.java:3816) ~[com.ibm.ws.runtime.jar:na]
    at com.ibm.ejs.j2c.PoolManager.reserve(PoolManager.java:3092) ~[com.ibm.ws.runtime.jar:na]
    at com.ibm.ejs.j2c.ConnectionManager.allocateMCWrapper(ConnectionManager.java:1548) ~[com.ibm.ws.runtime.jar:na]
    at com.ibm.ejs.j2c.ConnectionManager.allocateConnection(ConnectionManager.java:1031) ~[com.ibm.ws.runtime.jar:na]
    at com.ibm.ejs.jms.JMSQueueConnectionFactoryHandle.createQueueConnection(JMSQueueConnectionFactoryHandle.java:85) ~[com.ibm.ws.runtime.jar:na]

Way 2 : WebSphere MQ messaging provider

I used the same code in application to put messages to queue but with different provider which is ( WebSphere MQ messaging provider ) and created queue Connection factory with that provider and Queue manager, hostname, port and all details I have added in QueueConnectionFactory .

In this case I see I don't see any error and I'm successfully able to write in to the queue.

Question :

Why is it not working in way 1? I need to work in way 1 not in way 2.

Based on comments from OP @AlagammalP, non-IBM MQ supplied providerutil.jar and fscontext.jar were added to the class path.

WAS (Websphere Application Server) comes with the IBM MQ resource adapter included which includes these.

Remove the non-IBM MQ supplied providerutil.jar and fscontext.jar that were added to the class path as they are causing your issue:

Caused by: java.lang.ClassCastException: com.ibm.mq.jms.MQConnectionFactory incompatible with javax.jms.QueueConnectionFactory

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM