IBM MQ 中的持久订阅 Java 类

Durable Subscriptions in IBM MQ Java classes

我已经使用以下方法创建持久订阅,如前所述here

public MQTopic accessTopic(java.lang.String topicName,
                  java.lang.String topicObject,
                  int options,
                  java.lang.String altUserId,
                  java.lang.String subscriptionName)
                    throws MQException

文档指出 subscriptionName - This field is only required if the options parameter specified CMQC.MQSO_DURABLE, but if provided will be used by the queue manager for CMQC.MQSO_NON_DURABLE as well.

所以我创建的话题如下

qmanager.accessTopic("TOPICSTR",
                      "TOPICNAME",
                      CMQC.MQSO_DURABLE,
                      null,
                      "subscription")

但这会引发异常 2046(07FE)(RC2046):MQRC_OPTIONS_ERROR.Any 关于如何解决此问题并使用 IBM MQ 为持久订阅初始化主题的想法 java 类 ?

我想你需要使用更多选项:

CMQC.MQSO_CREATE | CMQC.MQSO_ALTER | CMQC.MQSO_DURABLE

来自 IBM 文档:

options - Upon opening the topic for subscription the following valid options are shown below. If more than one option is required, the values can be added together or combined using the bitwise OR operator.

CMQC.MQSO_CREATE
CMQC.MQSO_RESUME
CMQC.MQSO_ALTER 

If none of these options are specified, then CMQC.MQSO_CREATE + CMQC.MQSO_ALTER is assumed. Other valid options are also available.

首先,关于 IBM MQ 文档的警告:

public MQTopic accessTopic(java.lang.String topicName,
                           java.lang.String topicObject,
                           int options,
                           java.lang.String altUserId,
                           java.lang.String subscriptionName)
                    throws MQException

我一直在尝试让 IBM 更新他们的 MQ 文档,但他们像糖蜜一样慢。问题在于为 MQTopic 编写 Java 代码的人使用了错误的变量字段名称。因此,当他们从 Java 代码生成 Java 文档时,就会推测错误。

正确的定义是:

public MQTopic accessTopic(java.lang.String topicString,
                           java.lang.String topicObject,  /* aka topic name */
                           int options,
                           java.lang.String altUserId,
                           java.lang.String subscriptionName)
                    throws MQException

第一个字段是 'topic string' 而不是 'topic name'。请参阅描述 'topic string'、'topic name' 和 'topic object' 的 IBM 博客文章的 David Ware。 https://www.ibm.com/developerworks/community/blogs/messaging/entry/mq_topics_but_which_type?lang=en

接下来,您应该包括 fail if quiescing 标志:CMQC.MQSO_FAIL_IF_QUIESCING

我通常打开一个非持久性主题:

int openOptions = CMQC.MQSO_CREATE | CMQC.MQSO_FAIL_IF_QUIESCING | CMQC.MQSO_MANAGED | CMQC.MQSO_NON_DURABLE;

MQTopic subscriber = qMgr.accessTopic( topicString,
                                       null,
                                       CMQC.MQTOPIC_OPEN_AS_SUBSCRIPTION,
                                       openOptions);