The Publish/Subscribe Sample

The Publish/Subscribe sample programs demonstrate the use of the publish and subscribe features in IBM® MQ.

There are four C and two COBOL programming language sample programs demonstrating how to program to the IBM MQ Publish/Subscribe interface. The programs are delivered in the C and COBOL language. The applications run in the batch environment; see Publish/Subscribe samples for the batch applications.

There are also COBOL samples that run in the CICS® environment; see The CICS Asynchronous Consumption and Publish/Subscribe sample.

This topic also provides information about how to run Publish/Subscribe sample programs. These sample programs include:

Running the CSQ4BCP1 sample

This program is written in C, it publishes messages to a topic. Start one of the subscriber samples before running this program.

This program takes up to four parameters:
  1. The name of the target topic (required).
  2. The name of the queue manager (optional).
  3. Open options (optional).
  4. Close options (optional).

If a queue manager is not specified, CSQ4BCP1 connects to the default queue manager. There is a sample JCL to run the program, it resides in CSQ4BCPP.

Message content is provided through standard input ( SYSIN DD ).

Running the CSQ4BCP2 sample

This program is written in C, it subscribes to a topic and prints the messages received.

This program takes up to three parameters:
  1. The name of the target topic (required).
  2. The name of the queue manager (optional).
  3. MQSD subscription options (optional).

If a queue manager is not specified, CSQ4BCP2 connects to the default queue manager. There is a sample JCL to run the program, it resides in CSQ4BCPS.

Running the CSQ4BCP3 sample

This program is written in C, it subscribes to a topic using a user-specified destination queue and prints the messages received.

This program takes up to four parameters:
  1. The name of the target topic (required).
  2. The name of the destination (required).
  3. The name of the queue manager (optional).
  4. MQSD subscription options (optional).

If a queue manager is not specified, CSQ4BCP3 connects to the default queue manager. There is a sample JCL to run the program, it resides in CSQ4BCPD.

Running the CSQ4BCP4 sample

This program is written in C, it subscribes and gets messages from a topic allowing the use of extended options on the MQSUB call, extending those available on the simpler MQSUB sample: CSQ4BCP2. In addition to the message payload, message properties for each message is received and displayed.

This program takes a variable set of parameters:
  1. -t < string >: Topic string (required).
  2. -o < name >: Topic object name (required).
  3. -m < name >: Queue manager name (optional).
  4. -q < name >: Destination queue name (optional).
  5. -w < seconds >: Wait interval on MQGET in seconds (optional).
  6. -d < subname >: Create or resume named durable subscription (optional).
  7. -k: Keep durable subscription on MQCLOSE (optional).

If a queue manager is not specified, CSQ4BCP4 connects to the default queue manager. There is a sample JCL to run the program, it resides in CSQ4BCPE.

Running the CSQ4BVP1 sample

This program is written in COBOL, it publishes messages to a topic. Start one of the subscriber samples before running this program.

This program takes no parameters. SYSIN DD provides the input topic name, queue manager name, and message content.

If a queue manager is not specified, CSQ4BVP1 connects to the default queue manager. There is a sample JCL to run the program, it resides in CSQ4BVPP.

Running the CSQ4BVP2 sample

This program is written in COBOL, it subscribes to a topic and prints the messages received.

This program takes no parameters. SYSIN DD provides the input for topic name and queue manager name.

If a queue manager is not specified, CSQ4BVP1 connects to the default queue manager. There is a sample JCL to run the program, it resides in CSQ4BVPP.