Home

 

Publish/Subscribe name/value strings

 

+

Search Tips   |   Advanced Search

 

The MQRFH format is used to encode command messages that are sent to the WebSphere MQ Publish/Subscribe broker. The NameValueString field within the RF header contains name/value pairs that describe the command to be carried out by the broker. If the command being issued is a Publish command, publication data (in a format defined by the publisher) can follow the NameValueString field.

The NameValueString can contain any number of name/value pairs, but only those in which the tag-name begins with the characters 'MQPS' are recognized by the broker. Other name/value pairs (which can be defined by the publisher to encode publication data, for instance) are ignored by the broker.

The first occurrence of an 'MQPS' tag-name must be MQPSCommand, followed by a tag-value that identifies the command to be carried out. Subsequent 'MQPS' tag-names and their values identify any options for that command (if they occur before the MQPSCommand tag-name, the command fails).

Each name or value must be separated from the adjacent name or value by one or more blank characters. The C header file cmqpsc.h defines tag-names and values that can be used by publisher and subscriber applications when building command messages to be sent to the broker. Blank enclosed versions of the constants are provided to simplify construction of a NameValueString. For example, topics are specified using a tag-name of MQPSTopic, and the following three constants are provided in the cmqpsc.h header file:

#define MQPS_TOPIC    "MQPSTopic"
#define MQPS_TOPIC_B  " MQPSTopic "
#define MQPS_TOPIC_A  ' ','M','Q','P','S','T','o','p','i','c',' '

The MQPS_TOPIC constant is not enclosed by blanks. If it is used to build a NameValueString, the application must add blanks between tag-names and values. The version of the constant with the '_B' suffix includes the necessary blanks. The version with the '_A' suffix also includes the blanks, but is in character array form. These constants are most suited for initialization of a C structure that is being used to define a fixed layout of a NameValueString.

For example, the Delete Publication command can be issued to delete retained publications throughout the broker network. A topic of '*' matches all topics within the stream that the command is sent to, so using this deletes all retained publications. A NameValueString to perform such a command can be constructed as follows.

If the constants without blanks are used, the blanks must be inserted, for example:

MQCHAR DeleteCmd[] =
  MQPS_COMMAND " " MQPS_DELETE_PUBLICATION " " MQPS_TOPIC " *";

This can be simplified by using the constants with blanks, for example:

MQCHAR DeleteCmd[] =
  MQPS_COMMAND_B MQPS_DELETE_PUBLICATION_B MQPS_TOPIC_B "*";

A subscribing application might need to analyze a NameValueString, for instance to determine the topic associated with each publication it receives. One approach is to break down the entire NameValueString into its constituent parts. An illustration of this approach is given in the results service sample application (see Sample programs). A simpler approach is to use the sscanf in the C runtime library to determine the position of the MQPSTopic tag-name in the string. Since sscanf automatically strips away white space, the MQPS_TOPIC constant (without the blanks) is needed here.



 

Home