Get MQ messageId in string format

后端 未结 3 545
春和景丽
春和景丽 2020-12-10 20:05

I\'m using the mq library of IBM to read messages from MQ queues. Now I need to retrieve the messageid of the message. I now it is in the message header under the name messa

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-10 20:16

    I have successfully implemented the cycle of getting the MQ MessageId and converting it to a hexadecimal string for local storage and then converting it back to a byte[] when using it to query MQ again later, using the Apache Commons Codec thus:

    import org.apache.commons.codec.binary.Hex;
    
    String mqMessageId = Hex.encodeHexString(message.messageId);
    message.messageId = Hex.decodeHex(mqMessageId.toCharArray());
    

    I like this approach because it depends on a well maintained library from a well known and respected organization, and I do not have to maintain any additional methods.

    None the less I would like to acknowledge Roger's comments above because they put me on the trail that lead to Apache Commons Codec.

提交回复
热议问题