Sending Messages that Request Acknowledgments

To request acknowledgment messages, the sending application must indicate the type of acknowledgment(s) it wants to receive, and the administration queue must indicate where the acknowledgment message will be placed. It can receive positive, negative, or a combination of positive and negative acknowledgment messages by setting PROPID_M_ACKNOWLEDGE and attaching it to the messages it sends.

Acknowledgment messages are generated by MSMQ or by connector applications (when sending messages to foreign queues) and are returned to the administration queue specified by PROPID_M_ADMIN_QUEUE.

Note  Each MSMQ message can have no more than 4 MB of data.

    To send a message requesting acknowledgment messages
  1. Call MQOpenQueue to open the queue with send access.
    //////////////////////////////
    // Open the destination queue
    // with send access.
    //////////////////////////////
    
    QUEUEHANDLE hQueue;
    hr = MQOpenQueue(szFormatName, MQ_SEND_ACCESS, 0, &hQueue);
    if (FAILED(hr))
    {
        fprintf(stderr, "Failed in MQOpenQueue, error = 0x%x\n", hr);
        return -1;
    }
    
  2. Set PROPID_M_ACKNOWLEDGE. This property specifies the type of acknowledgment messages that will be sent. The example below requests full-receive acknowledgments.
    /////////////////////////////
    // Set PROPID_M_ACKNOWLEDGE.
    /////////////////////////////
    aPropId[PropIdCount] = PROPID_M_ACKNOWLEDGE;          //PropId
    aVariant[PropIdCount].vt = VT_UI1;                    //Type
    aVariant[PropIdCount].bVal = MQMSG_ACKNOWLEDGMENT_FULL_RECEIVE;//Value
     
    PropIdCount++;
     
  3. Set PROPID_M_ADMIN_QUEUE. This property specifies the administration queue where the acknowledgment messages will be sent.
    /////////////////////////////////////////
    // Set the PROPID_M_ADMIN_QUEUE property.
    /////////////////////////////////////////
    aPropId[PropIdCount] = PROPID_M_ADMIN_QUEUE;         //PropId
    aVariant[PropIdCount].vt = VT_LPWSTR;                //Type
    aVariant[PropIdCount].pwszVal = szwAdminFormatName;  //An already obtained format name of the administration queue.
     
    PropIdCount++;
     
  4. Set other message properties, such as the message's body and its label.
  5. Set the MQMSGPROPS structure.
    ////////////////////////////////
    // Set the MQMSGPROPS structure.
    ////////////////////////////////
    MsgProps.cProp = PropIdCount;       //Number of properties.
    MsgProps.aPropID = aPropId;         //Ids of properties.
    MsgProps.aPropVar = aVariant;       //Values of properties.
    MsgProps.aStatus  = NULL;           //No Error report.
     
  6. Call MQSendMessage to send the message to the queue.
    /////////////////
    // Send message.
    /////////////////
    hr = MQSendMessage(
         hQueue,                  // Handle to the Queue.
         &MsgProps,               // Message properties to be sent.
         MQ_NO_TRANSACTION        // No transaction
         );
     

Example

The following example sends a message requesting full-receive acknowledgments.

MQMSGPROPS MsgProps;
PROPVARIANT aVariant[10];
MSGPROPID aPropId[10];
DWORD PropIdCount = 0;
 
HRESULT hr;
 
QUEUEHANDLE hQueue;
 
  //////////////////////////////
  // Open the destination queue
  // with send access.
  //////////////////////////////
  
  QUEUEHANDLE hQueue;
  hr = MQOpenQueue(szFormatName, MQ_SEND_ACCESS, 0, &hQueue);
  if (FAILED(hr))
  {
      fprintf(stderr, "Failed in MQOpenQueue, error = 0x%x\n", hr);
      return -1;
  }
    
/////////////////////////////
// Set PROPID_M_ACKNOWLEDGE.
/////////////////////////////
aPropId[PropIdCount] = PROPID_M_ACKNOWLEDGE;          //PropId
aVariant[PropIdCount].vt = VT_UI1;                    //Type
aVariant[PropIdCount].bVal = MQMSG_ACKNOWLEDGMENT_FULL_RECEIVE;//Value
 
PropIdCount++;
 
/////////////////////////////////////////
// Set the PROPID_M_ADMIN_QUEUE property.
/////////////////////////////////////////
aPropId[PropIdCount] = PROPID_M_ADMIN_QUEUE;         //PropId
aVariant[PropIdCount].vt = VT_LPWSTR;                //Type
aVariant[PropIdCount].pwszVal = szwAdminFormatName;  //An already obtained format name of the administration queue.
 
PropIdCount++;
 
////////////////////////////////////////
// Set other message properties, such
// as PROPID_M_BODY and PROPID_M_LABEL.
///////////////////////////////////////
 
////////////////////////////////
// Set the MQMSGPROPS structure.
////////////////////////////////
MsgProps.cProp = PropIdCount;       //Number of properties.
MsgProps.aPropID = aPropId;         //Ids of properties.
MsgProps.aPropVar = aVariant;       //Values of properties.
MsgProps.aStatus  = NULL;           //No Error report.
 
/////////////////
// Send message.
/////////////////
hr = MQSendMessage(
     hQueue,                  // handle to the Queue.
     &MsgProps,               // Message properties to be sent.
     MQ_NO_TRANSACTION        // No transaction
     );
 
if (FAILED(hr))
   {
    //
    // Handle error condition
    //
    }