Share via


Visual Basic Code Example: Returning Acknowledgment Messages (Connector Applications)

 

Applies To: Windows 10, Windows 7, Windows 8, Windows 8.1, Windows Server 2008, Windows Server 2008 R2, Windows Server 2012, Windows Server 2012 R2, Windows Server Technical Preview, Windows Vista

This example provides a private Sub procedure that returns an acknowledgment message to the specified administration queue.

Note

This function can only be called from a connector application.

To filter acknowledgment messages

  1. Declare variables and the objects needed to send the message that requests acknowledgments. The procedure declares the MSMQMessage object (for the message that requests acknowledgment messages).

  2. Set the default values required for acknowledgment messages.

  3. Set all other message properties to the property values of the original message.

  4. Set connector type property.

  5. Call MSMQMessage.Send to sent the message to the administration queue specified in the original message.

Code Example

The following code example requires MSMQ 2.0 or later.

Private Sub AckMessage( _  
                       msgOrig As MSMQMessage, _  
                       AckValue As MQMSGCLASS, _  
                       guidConnectorType As GUID _  
                       )  
  
  'Declare variables.  
  Dim msgRet As New MSMQMessage  
  Dim fEncrypted As Boolean  
  Dim fNack As Boolean  
  
  On Error GoTo ErrorHandler  
  
  'Set the acknowledgment default values.  
  msgRet.MsgClass = AckValue  
  msgRet.Ack = MQMSG_ACKNOWLEDGMENT_NONE  
  msgRet.MaxTimeToReceive = -1  
  msgRet.MaxTimeToReachQueue = -1  
  msgRet.Journal = MQMSG_JOURNAL_NONE  
  
  'Set all other message properties to the values of the original message.  
  msgRet.Extension = msgOrig.Extension  
  msgRet.SenderId = msgOrig.SenderId  
  msgRet.CorrelationId = msgOrig.Id  
  msgRet.Priority = msgOrig.Priority  
  msgRet.Delivery = msgOrig.Delivery  
  msgRet.AppSpecific = msgOrig.AppSpecific  
  msgRet.Label = msgOrig.Label  
  Set msgRet.ResponseDestination = msgOrig.Destination  
  
  If AckValue = MQMSG_CLASS_ACK_REACH_QUEUE Or AckValue = MQMSG_CLASS_ACK_RECEIVE _  
          Or AckValue = MQMSG_CLASS_NORMAL Or AckValue = MQMSG_CLASS_REPORT Then  
    fNack = False  
  Else  
    fNack = True  
  End If  
  
  If msgOrig.PrivLevel = MQMSG_PRIV_LEVEL_BODY_BASE Then  
    fEncrypted = True  
  Else  
    fEncrypted = False  
  End If  
  
  If Not fEncrypted And fNack Then  
    msgRet.Body = msgOrig.Body  
  End If  
  
  'Set the connector type identifier.  
  msgRet.ConnectorTypeGuid = guidConnectorType  
  
  'Send the acknowledgment message to the administration queue.  
  msgRet.Send DestinationQueue:=msgOrig.AdminDestination  
  
  Exit Sub  
  
ErrorHandler:  
  MsgBox "Error " + Hex(Err.Number) + " was returned." _  
         + Chr(13) + Err.Description  
End Sub