我想从死信队列重新发送消息。为此,我需要将死信转换为BytesMessage(Payload可以是ZIP或字符串)。
到目前为止我尝试了什么:
通过MQRFH2类和seek()获取RFH2:
mqMessage.seek(0); MQRFH2 rfh2 = new MQRFH2(mqMessage); byte[]
data = new byte[mqMessage.getDataLength()];
mqMessage.readFully(data); System.out.println("Message data: "
+new String(data));.
通过MQHeaderlist获取RFH2:
MQHeaderList list = new MQHeaderList (mqMessage, true); // Step 1.
MQDLH dlh = (MQDLH) list.get (0); // Step 2.
int reason = dlh.getReason (); // Step 3.
list.remove (dlh); // Step 4.
mqMessage = new MQMessage ();
list.write (mqMessage, true); // Step 5.
mqMessage.format = list.getFormat (); // Step 6.
MQHeaderIterator it = new MQHeaderIterator(mqMessage);
while (it.hasNext()) {
MQHeader header = it.nextHeader();
System.out.println("Header type " + header.type() + ": " + header);
}
通过MQRFH2类获取RFH2:
MQHeader header = new MQRFH2(mqMessage);
ByteArrayOutputStream out = new ByteArrayOutputStream();
header.write(new DataOutputStream(out), CMQC.MQENC_NATIVE,
CMQC.MQCCSI_DEFAULT); byte[] bytes = out.toByteArray(); String
sout = new String(bytes); System.out.println(sout);
没有什么对我有用:我得到错误,就像这个:
MQJE001: Beendigungscode '2', Ursache '6114'.
MQJE001: Beendigungscode '2', Ursache '2195'.
ch.coop.mid.hecol.DAEQHandler.exception.ZDAEQException: com.ibm.mq.headers.MQDataException: MQJE001: Beendigungscode '2', Ursache '2195'.
at ch.coop.mid.hecol.DAEQHandler.bl.impl.ZMQQueueImpl.resendAllLetters(ZMQQueueImpl.java:52)
at ch.coop.mid.hecol.DAEQHandler.ZStart.main(ZStart.java:20)
Caused by: com.ibm.mq.headers.MQDataException: MQJE001: Beendigungscode '2', Ursache '2195'.
at com.ibm.mq.headers.MQDataException.getMQDataException(MQDataException.java:316)
at com.ibm.mq.headers.internal.Header.read(Header.java:620)
at com.ibm.mq.headers.MQRFH2.<init>(MQRFH2.java:113)
at ch.coop.mid.hecol.DAEQHandler.dto.ZMessageDTO.<init>(ZMessageDTO.java:60)
at ch.coop.mid.hecol.DAEQHandler.bl.impl.ZMQQueueImpl.resendAllLetters(ZMQQueueImpl.java:50)
... 1 more
Caused by: com.ibm.mq.headers.MQDataException: MQJE001: Beendigungscode '2', Ursache '6114'.
at com.ibm.mq.headers.MQDataException.getMQDataException(MQDataException.java:313)
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)
... 4 more
Caused by: java.io.EOFException: MQJE086: Ausnahmebedingung durch Dateiende ('MQMessage.seek()').
at com.ibm.mq.MQMessage.seek(MQMessage.java:715)
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)
是否有另一种方法可以将死信转换为BytesMessage而不将整个消息拆分成小部分并将它们组合在一起?这种方式对我来说不是很美。这很不稳定。
修改 我只能在java中使用7.5.0.0版本的mq库。
答案 0 :(得分:1)
你在世界上做什么?你似乎正在向后攻击这个问题。消息布局是MQDLH + MQRFH2 +消息数据。
我假设您要将“MQRFH2 +消息数据”重新发送到原始目标队列。
以下是您的代码的外观:
mqMsg.seek(0);
MQDLH dlh = new MQDLH(mqMsg);
System.out.println("Reason code= "+dlh.getReason() + " : Dest. Queue Name="+dlh.getDestQName());
byte[] bData = new byte[mqMsg.getDataLength()];
mqMsg.readFully(bData);
// Open the original destination queue
int openOutputOptions = CMQC.MQOO_OUTPUT + CMQC.MQOO_FAIL_IF_QUIESCING;
MQQueue outQ = _qMgr.accessQueue( dlh.getDestQName().trim(),
openOutputOptions,
dlh.getDestQMgrName().trim(),
null,
null );
// Create a new message and set the values from DLH
MQMessage newMsg = new MQMessage();
newMsg.characterSet = dlh.getCharacterSet();
newMsg.encoding = dlh.getEncoding();
newMsg.format = dlh.getFormat();
newMsg.write(bData); // write the data
MQPutMessageOptions pmo = new MQPutMessageOptions();
pmo.options = CMQC.MQPMO_FAIL_IF_QUIESCING;
// Put the message to the destination queue
outQ.put(newMsg, pmo);
outQ.close();