如何使用 JMS 发送请求并从 IBM MQ 获取响应?

问题描述 投票:0回答:1

我已使用 JMS 向 MQ 发送请求以及从 MQ 发送请求。我提供了程序名称、逗号、呼叫长度和等待时间作为输入。但是,我遇到了以下异常。

com.ibm.msg.client.jms.DetailedInvalidSelectorException: JMSWMQ2008: Failed to open MQ queue 'SY31.MQ'.
JMS attempted to perform an MQOPEN, but WebSphere MQ reported an error.

WebSphere MQ call failed with compcode '2' ('MQCC_FAILED') reason '2459' ('MQRC_SELECTOR_SYNTAX_ERROR').
    at com.ibm.msg.client.wmq.common.internal.Reason.createException(Reason.java:204)

如何解决此异常?

            producer.send(message);
            
            // Receive a message from reply queue

            MessageConsumer consumer = session.createConsumer(replyQueue,
                    message.getJMSCorrelationID());
            
            Message replyMessage = consumer.receive(replyTimeout * 1000);

            if (replyMessage instanceof TextMessage) {
                
                logger.info(" Reply from CICS server.. TextMessage ");
                String replText = ((TextMessage) replyMessage).getText();
                logger.info(" Reply from CICS server.. " + replText);
                }else if (replyMessage instanceof BytesMessage) {
                BytesMessage bytesMessage = (BytesMessage) replyMessage;
                
int length = (int) bytesMessage.getBodyLength();
                
                
                byte[] messageBytes = new byte[length];
                
                bytesMessage.readBytes(messageBytes);
                
                String textMessage = new String(messageBytes, "UTF-8");
                    
            }

            // Close resources
            session.close();
            connection.close();

        } catch (Exception e) {
            logger.error("Error in JMS Queue reading========" + e);
        }

        return "";
    }
jms ibm-mq mainframe
1个回答
0
投票

JMS Session createConsumer(Destination,String) 的第二个参数应该是 JMS 选择字符串。您的代码使用“消息”中的原始 JMSCorrelationId,它没有消息选择器的正确语法。

此 IBM MQ 文档中描述了正确的语法:https://www.ibm.com/docs/en/ibm-mq/9.3?topic=messages-message-selectors-in-jms

用于匹配 JMS 相关 ID theId 的通用 JMS 语法为“JMSCorrelationId='theId'”。

如果相关 ID 是 MQ CorrelId(一个 24 字节的字节字符串),那么 IBM MQ 还具有通过相关 ID 进行选择的特殊语法,并且选择是为了精确匹配。将消息与 MQ CorrelId CorrelId 匹配的语法为“JMSCorrelationId='ID:CorrelId'。MQ 将优化这种形式的选择器。

链接文档中有相关示例。

© www.soinside.com 2019 - 2024. All rights reserved.