简体   繁体   English

将RFH2标头添加到IBM MQ消息的正确方法是什么

[英]What is the correct way of adding RFH2 header to IBM MQ message

I have recently started working with IBM MQ (v7.5) and currently working on a bridge like service for 2 way data transfer between MQ & another REST service I have. 我最近开始使用IBM MQ(v7.5),目前正在从事类似桥梁的服务,以便在MQ和我拥有的另一种REST服务之间进行2种方式的数据传输。

By using standard APIs I am able to read and write messages without any issue. 通过使用标准API,我可以毫无问题地读取和写入消息。 But the problem I am facing came when I started setting up MQRFH2 header to my messages. 但是,当我开始为消息设置MQRFH2标头时,出现了我面临的问题。 I must be doing some mistake while writing data with header because every time I am getting " End of file exception ('MQMessage.seek()'). " error while reading those messages. 在使用标头写入数据时,我一定会犯一些错误,因为每次读取这些消息时,都会收到“ 文件末尾异常('MQMessage.seek()')。 ”错误。

This is my code snippet while putting the message into MQ: 这是将消息放入MQ时的代码片段:

//Constructing message
MQMessage sendmsg = new MQMessage();
sendmsg.characterSet = 1208;
sendmsg.format = MQC.MQFMT_STRING;
sendmsg.feedback = MQC.MQFB_NONE;
sendmsg.messageType = MQC.MQMT_DATAGRAM;
sendmsg.replyToQueueName = outputBackupQueueName;
sendmsg.replyToQueueManagerName = queueManager;

//Constructing header
MQRFH2 rfh2 = new MQRFH2();
rfh2.setEncoding(MQConstants.MQENC_NATIVE);
rfh2.setCodedCharSetId(MQConstants.MQCCSI_INHERIT);
rfh2.setFormat(MQConstants.MQFMT_STRING);
rfh2.setNameValueCCSID(1208);

//adding message to header
rfh2.write(sendmsg);

//payload is the actual data which we want to send
byte[] messageBytes = payload.getBytes("UTF-8");
sendmsg.write(messageBytes);

//putting message to MQ
MQPutMessageOptions outputMsgOpt = new MQPutMessageOptions();
outputMsgOpt.options = MQConstants.MQPMO_FAIL_IF_QUIESCING |
                MQConstants.MQPMO_DEFAULT_CONTEXT |
                MQConstants.MQPMO_SYNCPOINT;

outputQueue.put(sendmsg, outputMsgOpt);
queueManager.commit();

And this is how I am trying to retrieve it later: 这就是我稍后尝试检索的方式:

MQMessage incomingMessage = new MQMessage();
byte[] incomingMessageId = incomingMessage.messageId;
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.options = MQConstants.MQGMO_FAIL_IF_QUIESCING |
                        MQConstants.MQGMO_CONVERT |
                        MQConstants.MQGMO_SYNCPOINT |
                        MQConstants.MQGMO_LOGICAL_ORDER |
                        MQConstants.MQGMO_ALL_MSGS_AVAILABLE |
                        MQConstants.MQGMO_WAIT;

inputQueue.get(incomingMessage, gmo);
MQRFH2 myRfh2 = new MQRFH2(incomingMessage); //this statement throws error with headers

Complete error message is: 完整的错误消息是:

com.ibm.mq.headers.MQDataException: MQJE001: Completion Code '2', Reason '2195'.
    at com.ibm.mq.headers.MQDataException.getMQDataException(MQDataException.java:317)
    at com.ibm.mq.headers.internal.Header.read(Header.java:620)
    at com.ibm.mq.headers.MQRFH2.<init>(MQRFH2.java:113)
    at com.simility.util.MQRfh2HeaderHelper.getMsgByteArray(MQRfh2HeaderHelper.java:16)
    at com.simility.mq.SimilityMQBridge.main(SimilityMQBridge.java:182)

    Caused by: com.ibm.mq.headers.MQDataException: MQJE001: Completion Code '2', Reason '6114'.
    at com.ibm.mq.headers.MQDataException.getMQDataException(MQDataException.java:314)
    at com.ibm.mq.headers.MQRFH2.read(MQRFH2.java:184)
    at com.ibm.mq.headers.internal.Header.read(Header.java:639)
    at com.ibm.mq.headers.internal.Header.read(Header.java:617)
    ... 3 more

    Caused by: java.io.EOFException: MQJE086: End of file exception ('MQMessage.seek()').
    at com.ibm.mq.MQMessage.seek(MQMessage.java:716)
    at com.ibm.mq.headers.internal.store.MQMessageStore.readFrom(MQMessageStore.java:274)
    at com.ibm.mq.headers.internal.Header.read(Header.java:661)
    at com.ibm.mq.headers.MQRFH2.read(MQRFH2.java:181)

Another thing I verified is message length by "TotalMessageLength", and that matches between reading and writing the messages, but still the failure happens. 我验证的另一件事是“ TotalMessageLength”的消息长度,它在读取和写入消息之间匹配,但是仍然会发生故障。

Can anyone please help me out or point me in right direction related to adding and retrieving messages with RFH2 header ? 任何人都可以帮我一下或为我指出与添加和检索带有RFH2标头的消息有关的正确方向吗?

Another thing I verified is message length by "TotalMessageLength", and that matches between reading and writing the messages, but still the failure happens. 我验证的另一件事是“ TotalMessageLength”的消息长度,它在读取和写入消息之间匹配,但是仍然会发生故障。

Does the method "getMessageLength()" of MQMessage return the data length of the payload? MQMessage的方法“ getMessageLength()”是否返回有效载荷的数据长度?

Why don't you try (in the sender): 您为什么不尝试(在发送者中):

byte[] messageBytes = payload.getBytes();

If your data is not the same codepage or encoding then let MQ do the work rather than you doing getBytes("UTF-8"). 如果您的数据不是相同的代码页或编码,那么请让MQ执行工作,而不要执行getBytes(“ UTF-8”)。

ie Set the Encoding and CCSID to what the data is. 即将Encoding和CCSID设置为数据。

rfh2.setEncoding(???);
rfh2.setCodedCharSetId(???);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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