The Asynchronous Put sample program

Learn about running the amqsapt sample and the design of the Asynchronous Put sample program.

The asynchronous put sample program puts messages on a queue using the asynchronous MQPUT call and then retrieves status information using the MQSTAT call. See Features demonstrated in the sample programs on Multiplatforms for the name of this program on different platforms.


Running the amqsapt sample

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

If a queue manager is not specified, amqsapt connects to the default queue manager.


Design of the Asynchronous Put sample program

The program uses the MQOPEN call with the output options supplied, or with the MQOO_OUTPUT and MQOO_FAIL_IF_QUIESCING options to open the target queue for putting messages.

If it cannot open the queue, the program outputs an error message containing the reason code returned by the MQOPEN call. To keep the program simple, on this and on subsequent MQI calls, the program uses default values for many of the options.

For each line of input, the program reads the text into a buffer and uses the MQPUT call with MQPMO_ASYNC_RESPONSE to create a datagram message containing the text of that line and asynchronously put it to the target queue. The program continues until it reaches the end of the input or the MQPUT call fails. If the program reaches the end of the input, it closes the queue using the MQCLOSE call.

The program then issues the MQSTAT call, returning an MQSTS structure, and displays messages containing the number of messages put successfully, the number of messages put with a warning, and the number of failures.

Parent topic: Use the sample programs on Multiplatforms