Putting a message using MQPUT

This example demonstrates how to use the MQPUT call to put a message on a queue. This extract is not taken from the sample applications supplied with WebSphere(R) MQ. For the names and locations of the sample applications, see Sample programs (all platforms except z/OS) and Sample programs for WebSphere MQ for z/OS.



  ·
  ·
  ·
qput() { MQMD MsgDesc; MQPMO PutMsgOpts; MQLONG CompCode; MQLONG Reason; MQHCONN Hconn; MQHOBJ Hobj; char message_buffer[] = "MY MESSAGE"; /*-------------------------------*/ /* Set up PMO structure. */ /*-------------------------------*/ memset(&PutMsgOpts, '\0', sizeof(PutMsgOpts)); memcpy(PutMsgOpts.StrucId, MQPMO_STRUC_ID, sizeof(PutMsgOpts.StrucId)); PutMsgOpts.Version = MQPMO_VERSION_1; PutMsgOpts.Options = MQPMO_SYNCPOINT; /*-------------------------------*/ /* Set up MD structure. */ /*-------------------------------*/ memset(&MsgDesc, '\0', sizeof(MsgDesc)); memcpy(MsgDesc.StrucId, MQMD_STRUC_ID, sizeof(MsgDesc.StrucId)); MsgDesc.Version = MQMD_VERSION_1; MsgDesc.Expiry = MQEI_UNLIMITED; MsgDesc.Report = MQRO_NONE; MsgDesc.MsgType = MQMT_DATAGRAM; MsgDesc.Priority = 1; MsgDesc.Persistence = MQPER_PERSISTENT; memset(MsgDesc.ReplyToQ, '\0', sizeof(MsgDesc.ReplyToQ)); /*---------------------------------------------------*/ /* Put the message. */ /*---------------------------------------------------*/ MQPUT(Hconn, Hobj, &MsgDesc, &PutMsgOpts, sizeof(message_buffer), message_buffer, &CompCode, &Reason);
    /*-------------------------------------*/
    /*  Check completion and reason codes. */
    /*-------------------------------------*/
    switch (CompCode)
        {
         case MQCC_OK:
             break;
         case MQCC_FAILED:
             switch (Reason)
                 {
                  case MQRC_Q_FULL:
                  case MQRC_MSG_TOO_BIG_FOR_Q:
                      break;
                  default:
                      break; /* Perform error processing */
                  }
             break;
         default:
             break;          /* Perform error processing */
        }
}