IBM MQ使用Java程序发送消息

IBM MQ使用Java程序发送消息,java,jms,websphere,jndi,mq,Java,Jms,Websphere,Jndi,Mq,我试图从运行在WebSphereApplicationServer上的java程序向MQ队列发送消息。 我在WebSphereApplciaiton服务器中配置了QConnection工厂和QJNDIS。但当运行程序时,我会出错 Details: "com.ibm.ejs.jms.JMSConnectionFactoryHandle incompatible with javax.jms.QueueConnectionFactory". at com.ibm.

我试图从运行在WebSphereApplicationServer上的java程序向MQ队列发送消息。 我在WebSphereApplciaiton服务器中配置了QConnection工厂和QJNDIS。但当运行程序时,我会出错

Details: "com.ibm.ejs.jms.JMSConnectionFactoryHandle incompatible with javax.jms.QueueConnectionFactory".
        at com.ibm.bpm.rest.impl.service.ServiceRunner$TaskRunner.runService(ServiceRunner.java:1385)
        at com.ibm.bpm.rest.impl.service.StartActionHandler.handleActionGetModel(StartActionHandler.java:363)
        at com.ibm.bpm.rest.impl.playback.ServicePlaybackResourceImpl.createServicePlayback(ServicePlaybackResourceImpl.java:141)
        at com.ibm.bpm.rest.impl.playback.ServicePlaybackResource.createServicePlayback(ServicePlaybackResource.java:115)
        at sun.reflect.GeneratedMethodAccessor742.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
这是我正在使用的程序。非常感谢您的帮助

public void putMessageViaCF3(String messageContent, String connectionFactory, String sendQName)
            throws MQException, IOException, NamingException, JMSException {
        Queue myQueue;
        QueueConnectionFactory myQueueFactory;
        QueueConnection connection = null;
        QueueSession session = null;
        try {
            InitialContext jndi = new InitialContext();
            myQueueFactory = (QueueConnectionFactory) jndi.lookup("jms/SORC_QM_CF");
            myQueue = (Queue) jndi.lookup("jms/SORC_SEND_Q");

            connection=myQueueFactory.createQueueConnection();

            session = connection.createQueueSession(true, Session.AUTO_ACKNOWLEDGE);

            QueueSender sender = session.createSender(myQueue);
            connection.start();
            TextMessage textMessage = session.createTextMessage("Test Harish");
            textMessage.setStringProperty("messageType", "file");
            sender.send(textMessage);

            sender.close();
            
        } finally {

            if (session != null) {
                session.close();
            }

            if (connection != null) {
                connection.close();
            }
        }

    }
根据这种
ClassCastException
在以下情况下出现:

…队列连接工厂定义为WebSphere MQ连接工厂,而不是WebSphere MQ队列连接工厂

要解决此问题,您应该:

  • 将连接工厂定义为WebSphere MQ队列连接工厂
  • 在应用程序代码中使用
    javax.jms.ConnectionFactory
    对象,而不是
    javax.jms.QueueConnectionFactory
    对象

这里有什么反馈吗?