MQMessage 探索(使用 WebSphere MQ .NET API)

发布于 2024-10-09 05:55:28 字数 306 浏览 6 评论 0原文

我对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

下壹個目標 2024-10-16 05:55:28

是的,你完全正确,如果消息是结构化数据,例如定长记录格式,则必须提前知道消息的格式才能解析它。另一方面,如果消息有效负载是标记数据结构(例如有效的 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 开始,它们看起来像这样:

 /* Formats */
 #define MQFMT_NONE               "        "
 #define MQFMT_ADMIN              "MQADMIN "
 #define MQFMT_CHANNEL_COMPLETED  "MQCHCOM "
 #define MQFMT_CICS               "MQCICS  "
 #define MQFMT_COMMAND_1          "MQCMD1  "
 #define MQFMT_COMMAND_2          "MQCMD2  "
 #define MQFMT_DEAD_LETTER_HEADER "MQDEAD  "
 #define MQFMT_DIST_HEADER        "MQHDIST "
 #define MQFMT_EMBEDDED_PCF       "MQHEPCF "
 #define MQFMT_EVENT              "MQEVENT "
 #define MQFMT_IMS                "MQIMS   "
 #define MQFMT_IMS_VAR_STRING     "MQIMSVS "
 #define MQFMT_MD_EXTENSION       "MQHMDE  "
 #define MQFMT_PCF                "MQPCF   "
 #define MQFMT_REF_MSG_HEADER     "MQHREF  "
 #define MQFMT_RF_HEADER          "MQHRF   "
 #define MQFMT_RF_HEADER_1        "MQHRF   "
 #define MQFMT_RF_HEADER_2        "MQHRF2  "
 #define MQFMT_STRING             "MQSTR   "
 #define MQFMT_TRIGGER            "MQTRIG  "
 #define MQFMT_WORK_INFO_HEADER   "MQHWIH  "
 #define MQFMT_XMIT_Q_HEADER      "MQXMIT  "

实际的 MQMD 结构是在 cmqc.h 底部附近定义的。从 v7.0.1 开始,它看起来像这样:

 /****************************************************************/
 /*  MQMD2 Structure -- Version-2 Message Descriptor             */
 /****************************************************************/


 typedef struct tagMQMD2 MQMD2;
 typedef MQMD2 MQPOINTER PMQMD2;

 struct tagMQMD2 {
   MQCHAR4   StrucId;           /* Structure identifier */
   MQLONG    Version;           /* Structure version number */
   MQLONG    Report;            /* Report options */
   MQLONG    MsgType;           /* Message type */
   MQLONG    Expiry;            /* Expiry time */
   MQLONG    Feedback;          /* Feedback or reason code */
   MQLONG    Encoding;          /* Numeric encoding of message data */
   MQLONG    CodedCharSetId;    /* Character set identifier of message
                                   data */
   MQCHAR8   Format;            /* Format name of message data */
   MQLONG    Priority;          /* Message priority */
   MQLONG    Persistence;       /* Message persistence */
   MQBYTE24  MsgId;             /* Message identifier */
   MQBYTE24  CorrelId;          /* Correlation identifier */
   MQLONG    BackoutCount;      /* Backout counter */
   MQCHAR48  ReplyToQ;          /* Name of reply-to queue */
   MQCHAR48  ReplyToQMgr;       /* Name of reply queue manager */
   MQCHAR12  UserIdentifier;    /* User identifier */
   MQBYTE32  AccountingToken;   /* Accounting token */
   MQCHAR32  ApplIdentityData;  /* Application data relating to
                                   identity */
   MQLONG    PutApplType;       /* Type of application that put the
                                   message */
   MQCHAR28  PutApplName;       /* Name of application that put the
                                   message */
   MQCHAR8   PutDate;           /* Date when message was put */
   MQCHAR8   PutTime;           /* Time when message was put */
   MQCHAR4   ApplOriginData;    /* Application data relating to
                                   origin */
   MQBYTE24  GroupId;           /* Group identifier */
   MQLONG    MsgSeqNumber;      /* Sequence number of logical message
                                   within group */
   MQLONG    Offset;            /* Offset of data in physical message
                                   from start of logical message */
   MQLONG    MsgFlags;          /* Message flags */
   MQLONG    OriginalLength;    /* Length of original message */
 };

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:

 /* Formats */
 #define MQFMT_NONE               "        "
 #define MQFMT_ADMIN              "MQADMIN "
 #define MQFMT_CHANNEL_COMPLETED  "MQCHCOM "
 #define MQFMT_CICS               "MQCICS  "
 #define MQFMT_COMMAND_1          "MQCMD1  "
 #define MQFMT_COMMAND_2          "MQCMD2  "
 #define MQFMT_DEAD_LETTER_HEADER "MQDEAD  "
 #define MQFMT_DIST_HEADER        "MQHDIST "
 #define MQFMT_EMBEDDED_PCF       "MQHEPCF "
 #define MQFMT_EVENT              "MQEVENT "
 #define MQFMT_IMS                "MQIMS   "
 #define MQFMT_IMS_VAR_STRING     "MQIMSVS "
 #define MQFMT_MD_EXTENSION       "MQHMDE  "
 #define MQFMT_PCF                "MQPCF   "
 #define MQFMT_REF_MSG_HEADER     "MQHREF  "
 #define MQFMT_RF_HEADER          "MQHRF   "
 #define MQFMT_RF_HEADER_1        "MQHRF   "
 #define MQFMT_RF_HEADER_2        "MQHRF2  "
 #define MQFMT_STRING             "MQSTR   "
 #define MQFMT_TRIGGER            "MQTRIG  "
 #define MQFMT_WORK_INFO_HEADER   "MQHWIH  "
 #define MQFMT_XMIT_Q_HEADER      "MQXMIT  "

The actual MQMD structure is defined near the bottom of cmqc.h. As of v7.0.1 it looks like this:

 /****************************************************************/
 /*  MQMD2 Structure -- Version-2 Message Descriptor             */
 /****************************************************************/


 typedef struct tagMQMD2 MQMD2;
 typedef MQMD2 MQPOINTER PMQMD2;

 struct tagMQMD2 {
   MQCHAR4   StrucId;           /* Structure identifier */
   MQLONG    Version;           /* Structure version number */
   MQLONG    Report;            /* Report options */
   MQLONG    MsgType;           /* Message type */
   MQLONG    Expiry;            /* Expiry time */
   MQLONG    Feedback;          /* Feedback or reason code */
   MQLONG    Encoding;          /* Numeric encoding of message data */
   MQLONG    CodedCharSetId;    /* Character set identifier of message
                                   data */
   MQCHAR8   Format;            /* Format name of message data */
   MQLONG    Priority;          /* Message priority */
   MQLONG    Persistence;       /* Message persistence */
   MQBYTE24  MsgId;             /* Message identifier */
   MQBYTE24  CorrelId;          /* Correlation identifier */
   MQLONG    BackoutCount;      /* Backout counter */
   MQCHAR48  ReplyToQ;          /* Name of reply-to queue */
   MQCHAR48  ReplyToQMgr;       /* Name of reply queue manager */
   MQCHAR12  UserIdentifier;    /* User identifier */
   MQBYTE32  AccountingToken;   /* Accounting token */
   MQCHAR32  ApplIdentityData;  /* Application data relating to
                                   identity */
   MQLONG    PutApplType;       /* Type of application that put the
                                   message */
   MQCHAR28  PutApplName;       /* Name of application that put the
                                   message */
   MQCHAR8   PutDate;           /* Date when message was put */
   MQCHAR8   PutTime;           /* Time when message was put */
   MQCHAR4   ApplOriginData;    /* Application data relating to
                                   origin */
   MQBYTE24  GroupId;           /* Group identifier */
   MQLONG    MsgSeqNumber;      /* Sequence number of logical message
                                   within group */
   MQLONG    Offset;            /* Offset of data in physical message
                                   from start of logical message */
   MQLONG    MsgFlags;          /* Message flags */
   MQLONG    OriginalLength;    /* Length of original message */
 };

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文