Put messages on a queue

Use this information to learn how to put messages on a queue.

Use the MQPUT call to put messages on the queue. We can use MQPUT repeatedly to put many messages on the same queue, following the initial MQOPEN call. Call MQCLOSE when you have finished putting all your messages on the queue.

To put a single message on a queue and close the queue immediately afterward, we can use the MQPUT1 call. MQPUT1 performs the same functions as the following sequence of calls:

Generally however, if you have more than one message to put on the queue, it is more efficient to use the MQPUT call. This depends on the size of the message and the platform that we are working on.

Use the following links to find out more about putting messages on a queue:

  • Put messages on a local queue using the MQPUT call
    Use this information to learn about putting messages on a local queue using the MQPUT call.
  • Put messages on a remote queue
    When we want to put a message on a remote queue (that is, a queue owned by a queue manager other than the one to which the application is connected) rather than a local queue, the only extra consideration is how you specify the name of the queue when you open it.
  • Set properties of a message
    Call MQSETMP for each property we want to set. When you put the message set the message handle and action fields of the MQPMO structure.
  • Control message context information
    When we use the MQPUT or MQPUT1 call to put a message on a queue, we can specify that the queue manager is to add some default context information to the message descriptor. Applications that have the appropriate level of authority can add extra context information. We can use the options field in the MQPMO structure to control context information.
  • Put one message on a queue using the MQPUT1 call
    Use the MQPUT1 call when we want to close the queue immediately after you have put a single message on it. For example, a server application is likely to use the MQPUT1 call when it is sending a reply to each of the different queues.
  • Distribution lists
    Not supported on IBM MQ for z/OS. Distribution lists allow you to put a message to multiple destinations in a single MQPUT or MQPUT1 call.
  • Some cases where the put calls fail
    If certain attributes of a queue are changed using the FORCE option on a command during the interval between you issuing an MQOPEN and an MQPUT call, the MQPUT call fails and returns the MQRC_OBJECT_CHANGED reason code.

Parent topic: Writing a procedural application for queuing


Related concepts