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.
//////////////////////////////
// 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 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
);
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
//
}