连接到 IBM MQ 时更改 "app name"?

Change "app name" when connecting to IBM MQ?

我正在开发一个使用 C API 连接到 IBM MQ 8.0 的应用程序,调用 MQCONNX 函数。我同时 运行 此应用程序的多个实例,当我打开 MQ Explorer 列出队列管理器的应用程序连接时,我看到每个连接都有一个条目。但是,所有条目都具有相同的 "app name"(可执行文件的名称),因此很难区分哪些实例已连接或未连接。

是否可以更改最终在 MQ Explorer 中显示为 "app name" 的值?我想从我的应用程序传递一个实例标识符,但查看 MQCONNX none 选项的文档似乎适用。

您可以使用 MQOO_SET_ALL_CONTEXT 和 MQPMO_SET_ALL_CONTEXT 选项更改您发送的消息的应用程序名称。

但我认为您不能更改频道状态上显示的应用程序名称。

但是您可以 运行 不同 OS 用户下的应用程序的不同实例。用户名也显示在状态信息中,如果您不覆盖 MCA 用户 ID,它可以用于您的目的。 (或者您可以通过使用 SSL 连接并使用显示的 SSL 证书信息来区分您的应用程序实例来执行类似的操作。)

虽然我同意 Attila 的观点,您 "could" 使用 MQOO_SET_ALL_CONTEXT 和 MQPMO_SET_ALL_CONTEXT 选项,但我强烈建议您不要这样做。

如果您确实使用了这些选项,那么您需要了解后果。每条消息的以下 MQMD 字段将留空 and/or null 并由应用程序填充它们:

  • AccountingToken
  • ApplIdentityData
  • ApplOriginData
  • PutApplType
  • PutApplName
  • PutDate
  • PutTime
  • 用户标识符

那么,您要付出多少努力才能在 MQ Explorer 中看到一些毫无意义的东西?

此外,要使用这些选项,UserId(或组)需要为其打开的队列“+设置”MQ OAM 权限。

在 APPLTAG 下的 IBM MQ v8.0 知识中心页面“DISPLAY CONN”中,它显示了 MQ 如何确定该值。您没有说明 OS 您的客户端应用 运行 正在运行什么,Unix 和 Windows 的信息是:

  • UNIX process
    Note

  • On HP-UX if the process name exceeds 14 characters, only the first 14 characters are shown.

  • On Linux and Solaris, if the process name exceeds 15 characters, only the first 15 characters are shown.

  • On AIX®, if the process name exceeds 28 characters, only the first 28 characters are shown.

  • Windows process
    Note
    This consists of the full program path and executable file name. If it is more than 28 characters long, only the last 28 characters are shown.


如@Attila Repasi 所述,您可以使用“设置所有上下文”更改每条消息的 MQMD 中的 ApplName,这不会影响 MQ Explorer 中显示的“应用程序名称”。


如果您 运行 在 Unix 上使用,我想到的一个解决方法是为您的程序创建单独的符号链接,每个符号链接具有不同的名称。如果您随后 运行 每个副本都使用不同的符号链接名称,那么这应该反映为 MQ Explorer 显示的“应用程序名称”。


我在 Linux 上测试的第二个解决方法无需符号链接即可在您的程序中设置进程名称。我首先尝试覆盖 argv[0],但我发现虽然这会更改 ps 输出中的进程名称,但它不会更改 MQ 显示的 APPLTAG 值。我在Linux中找到的工作方式如下,这必须在MQCONN之前调用。

char *process_name = "samplename[=10=]";
prctl(PR_SET_NAME,process_name,NULL,NULL,NULL);

@Fusspawn 对“How to name a thread in Linux? [duplicate]”的回答有助于上述语法。


请注意,在 Unix 操作系统 MQI 客户端上进行测试时,我发现在 Linux 和 Solaris 上,进程名称被 OS 限制为 15 个字符。只有在 AIX 上,RAPPLTAG 才能够显示完整的 28 个字符。 Windows MQI 客户端也能够显示完整的 28 个字符。 IBM 知识中心只说​​ HP-UX 限制为 14 个字符,但指出在其他 Unix 平台上它限制为 28 个字符,这似乎与 Linux 和 Solaris 有 15 个字符限制的不正确。

有用的答案:

  • Linux 进程名称大小限制:Thread name longer than 15 chars?
  • Solaris 进程名称大小限制:psinfo_t solaris does not contain full process name in its field

更新: IBM KC 页面已根据我提供的反馈进行了更新,它现在说明了 Linux 和 Solaris 的正确进程名称限制。


为了向可能使用 IBM MQ 类 Java API 的人提供信息,知识中心的“DISPLAY CONN”页面并未指出IBM MQ 类 for Java API 客户端可以设置这个值。这在 IBM MQ 知识中心页面“Setting up the IBM MQ environment for IBM MQ classes for Java”下的Identifying a connection to the queue manager by setting an application name 下有所说明。这仅在 v7.5 之后可用。

Application names are limited to 28 characters and longer names are truncated to fit. If an application name is not specified, a default is provided. The default name is based on the invoking (main) class, but if this information is not available, the text WebSphere MQ Client for Java is used.

...

To set an application name in the properties hash table that is passed to the MQQueueManager constructor, add the name to the properties hash table with a key of MQConstants.APPNAME_PROPERTY.


IBM MQ 类 for JMS API 客户端也可以设置这个值。 IBM MQ 知识中心页面“Properties of IBM MQ classes for JMS objects > APPLICATIONNAME”对此进行了说明。这仅在 v7.5 之后可用。

Applicable Objects

ConnectionFactory, QueueConnectionFactory, TopicConnectionFactory, XAConnectionFactory, XAQueueConnectionFactory, XATopicConnectionFactory

JMS administration tool long name: APPLICATIONNAME

JMS administration tool short name: APPNAME

Programmatic access

Setters/getters

  • MQConnectionFactory.setAppName()
  • MQConnectionFactory.getAppName()

Values

Any valid string that is no longer than 28 characters. Longer names are adjusted to fit by removing leading package names, if necessary. For example, if the invoking class is com.example.MainApp, the full name is used, but if the invoking class is com.example.dictionaryAndThesaurus.multilingual.mainApp, the name multilingual.mainApp is used, because it is the longest combination of class name and rightmost package name that fits into the available length.

If the class name itself is more than 28 characters long, it is truncated to fit. For example, com.example.mainApplicationForSecondTestCase becomes mainApplicationForSecondTest.