Hussey123 Hussey123 - 30 days ago 10
Java Question

Durable Subscriptions in IBM MQ Java classes

I have used following method to create a durable subscription as mentioned here,

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


The documentation states that
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.


So I created the topic as follows.

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


But this raise the exception 2046(07FE)(RC2046): MQRC_OPTIONS_ERROR.Any idea on how to solve this and initialize the topic for a durable subscription using IBM MQ java classes?

Answer Source

First, a word of warning about IBM MQ documentation:

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

I have been trying to get IBM to update their MQ documentation but they are slow as molasses. The problem is that whoever wrote the Java code for the MQTopic used the wrong field names for the variables. Hence, when they generate the Java Docs from the Java code, the error is peculated.

The CORRECT definition is:

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

The first field is 'topic string' not 'topic name'. See David Ware of IBM blog posting describing 'topic string', 'topic name' and 'topic object'. https://www.ibm.com/developerworks/community/blogs/messaging/entry/mq_topics_but_which_type?lang=en

Next, you should be including the fail if quiescing flag: CMQC.MQSO_FAIL_IF_QUIESCING

I typically open a topic with non-durable:

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);