java – 以字符串格式获取MQ messageId
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java – 以字符串格式获取MQ messageId,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2481字,纯文字阅读大概需要4分钟。
内容图文
![java – 以字符串格式获取MQ messageId](/upload/InfoBanner/zyjiaocheng/707/6c4e0a7ea7e949058694db8858a0230d.jpg)
我正在使用IBM的mq库来读取MQ队列中的消息.现在我需要检索消息的messageid.我现在它在名为messageId的消息头中.但这会返回一个byte [].现在我需要将其更改为可读字符串.
如何将messageId从byte []转换为字符串?
我尝试了几次转换,但不是它们有效:
new String(theMessage.messageId)
new String(theMessage.messageId, "UTF-8")
new String(theMessage.messageId, "UTF-16")
theMessage.messageId.toString()
解决方法:
MQMD中的messageId表示为24个字节.如果您知道这些生成的平台,您可以通过将字节转换为生成它们的队列管理器的字符集中的字符来为它们的某些部分找到一些含义,但不建议依赖于传输的任何数据在messageID中作为字符数据,因为我看到IBM的语句类似于“MsgId is generated by MQ in an IBM proprietary format and it may change at any time.”
如果要将它们表示为字符串,则应将它们表示为表示24个字节的48个字符的HEX字符串.
下面是IBM在Technote中提供的示例函数getHexString,它将为您执行此转换.你会像这样使用它:
getHexString(theMessage.messageId)
以下示例函数来自IBM MQ Technote“How to match correlation id’s when request is made via JMS application and reply generated from base Java API”
public static String getHexString(byte[] b) throws Exception {
String result = "";
for (int i=0; i < b.length; i++) {
result += Integer.toString( ( b[i] & 0xff ) + 0x100, 16).substring( 1 );
}
return result;
}
IBM记录知识中心页面“Reference>Developing applications reference>MQI applications reference>Data types used in the MQI>MQMD – Message descriptor>Fields>MsgId (MQBYTE24)”底部的队列管理器生成的消息ID的格式和唯一性
A MsgId generated by the queue manager consists of a 4-byte product identifier (AMQ¬ or CSQ¬ in either ASCII or EBCDIC, where ¬ represents a blank character), followed by a product-specific implementation of a unique string. In IBM® MQ this contains the first 12 characters of the queue-manager name, and a value derived from the system clock. All queue managers that can intercommunicate must therefore have names that differ in the first 12 characters, in order to ensure that message identifiers are unique. The ability to generate a unique string also depends on the system clock not being changed backward. To eliminate the possibility of a message identifier generated by the queue manager duplicating one generated by the application, the application must avoid generating identifiers with initial characters in the range A through I in ASCII or EBCDIC (X’41’ through X’49’ and X’C1′ through X’C9′). However, the application is not prevented from generating identifiers with initial characters in these ranges.
内容总结
以上是互联网集市为您收集整理的java – 以字符串格式获取MQ messageId全部内容,希望文章能够帮你解决java – 以字符串格式获取MQ messageId所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。