MQMessage 探索(使用 WebSphere MQ .NET API)
我对 WebSphere MQ 确实很陌生,但我有一个关于 MQMessage API 的问题。 看来 MQMessage 的接收者应该提前知道:
- 写入的消息类型(
if WriteInt then ReadInt
等) - 属性名称和类型(
if SetBooleanProperty(Name) then GetBooleanProperty (名称)
)
这对我来说毫无意义。因为如果我不熟悉消息结构,我是否应该探索所有选项,直到检索其中的数据?
帮助将不胜感激。
I'm really new to WebSphere MQ, but I have one question regarding the MQMessage API.
It seems that a receiver of MQMessage should know in advance:
- The message type that was written (
if WriteInt then ReadInt
etc..) - The properties names and types (
if SetBooleanProperty(Name) then GetBooleanProperty(Name)
)
It make no sense to me. Since if I'm not familiar with the message structure should I explore all options until I retrieve the data in it?
Help will be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,你完全正确,如果消息是结构化数据,例如定长记录格式,则必须提前知道消息的格式才能解析它。另一方面,如果消息有效负载是标记数据结构(例如有效的 XML),那么您将使用正常的解析来访问它。例如,您可以使用 XPath 来访问 XML 有效负载,而无需先了解确切的结构。
您提到的方法(WriteInt、ReadInt 等)通常用于从已知格式中提取数据并将缓冲区指针前进到下一个字段。不过,也有读写 UTF 字符串的方法。如果由于某种原因您的应用程序必须处理多种消息类型,那么您可以通过查询消息描述符来查询消息格式和消息类型。执行此操作的方法记录在 消息描述符字段作为属性。通过这种方式,您可以区分不同类型和格式的消息并适当地解析它们。
请注意,我上面链接的文档是针对 v7 .Net 类的。由于 v6 的生命周期结束日期为 2011 年 9 月,因此希望新的开发全部与 v7 类一起进行,并且最好连接到 v7 QMgr。
编辑 - 回复评论
检查消息格式的示例:
根据上面链接的页面,检查 C 头文件 cmqc.h 中 MQMD 中的字段。这将告诉您字段名称以及字段类型。在默认的 Windows 安装中,该文件位于
C:\Program Files\IBM\WebSphere MQ\tools\c\include\cmqc.h
例如,
message.getStringProperty('Root.MQMD.Format')
返回消息格式。在 cmqc.h 顶部附近,您将找到名为 MQFMT_ 的宏列表,其中包含 MQMD 格式字段的可能值。从 v7.01 开始,它们看起来像这样:实际的 MQMD 结构是在 cmqc.h 底部附近定义的。从 v7.0.1 开始,它看起来像这样:
cmqc.h 文件为显示的每个字段定义宏,这些宏将包含可能的值。这些宏也在 .Net 类中定义为 MQC 对象。 MQC 在此描述< /a> 但由于它没有方法,该页面仅引用它定义的 WMQ 常量列表。该页面在这里< /a>.
Yes, you are absolutely correct that if the message is structured data such as a fixed-length record format, you must know in advance the format of the message in order to parse it. On the other hand, if the message payload is tagged data structure (such as valid XML) then you would use normal parsing to access it. For example, you might use XPath to access an XML payload without first knowing the exact structure.
The methods that you mention (WriteInt, ReadInt, etc.) would ordinarily be used to extract data from a known format and advance the buffer pointer to the next field. However, there are also methods to read and write UTF strings. If for some reason your application must process a variety of message types, then you can inquire on the message format and message type by querying the message descriptor. The method for doing this is documented in Message descriptor fields as properties. In this way you can distinguish between different types and formats of message and parse them appropriately.
Note that the docs I have linked above are to the v7 .Net classes. Since v6 end-of-life is September 2011, it is hoped that new development is all with the v7 classes, and preferably connecting to a v7 QMgr.
Edit - Response to comments
Example of checking the message format:
As per the page linked above, check the C header file cmqc.h for the fields in the MQMD. This will tell you the field name as well as the field type. In a default Windows installation, this file lives at
C:\Program Files\IBM\WebSphere MQ\tools\c\include\cmqc.h
So for example,
message.getStringProperty('Root.MQMD.Format')
returns the message format. Near the top of cmqc.h you will find a list of macros named MQFMT_ with the possible values for the MQMD Format field. As of v7.01 they look like this:The actual MQMD structure is defined near the bottom of cmqc.h. As of v7.0.1 it looks like this:
The cmqc.h file defines macros for each of the fields shown and these will contain the possible values. These macros are also defined in the .Net classes as the MQC object. MQC is described here but since it has no methods, the page just refers you to the list of WMQ constants which it defines. That page is here.