Message::AcknowledgeType Property
Gets or sets the type of acknowledgment message to be returned to the sending application.
Assembly: System.Messaging (in System.Messaging.dll)
public: [MessagingDescriptionAttribute("MsgAcknowledgeType")] property AcknowledgeTypes AcknowledgeType { AcknowledgeTypes get(); void set(AcknowledgeTypes value); }
Property Value
Type: System.Messaging::AcknowledgeTypesOne of the AcknowledgeTypes values, which represent both the types of acknowledgment messages the system posts in the administration queue and the conditions under which acknowledgments are returned to the sending application. The default is None.
| Exception | Condition |
|---|---|
| InvalidOperationException | The message is filtered to ignore the AcknowledgeType property. |
The AcknowledgeType property specifies the type of acknowledgment messages requested by the sending application. Set the AcknowledgeType property before sending the message to request notification of certain occurrences—for example, a message reaching its destination queue, a message being retrieved, or a time-out preventing a message from reaching or being retrieved from the destination queue.
Message Queuing returns notification by sending acknowledgment messages to the AdministrationQueue property specified by the original message. An acknowledgment message's Acknowledgment property indicates the type of acknowledgment that it represents. For example, if an acknowledgment message was sent because a message did not reach the destination before the TimeToReachQueue interval expired, the Acknowledgment property of the acknowledgment message would contain the value ReachQueueTimeout.
The following code example sends and receives a message containing an order to and from a queue. It specifically requests a positive acknowledgment when the original message reaches or is retrieved from the queue.
#using <system.dll> #using <system.messaging.dll> using namespace System; using namespace System::Messaging; ref class MyNewQueue { public: static void CreateQueue( String^ queuePath ) { try { if ( !MessageQueue::Exists( queuePath ) ) { MessageQueue::Create( queuePath ); } else { Console::WriteLine( "{0} already exists.", queuePath ); } } catch ( MessageQueueException^ e ) { Console::WriteLine( e->Message ); } } void SendMessage() { // Connect to a queue on the local computer. MessageQueue^ myQueue = gcnew MessageQueue( ".\\myQueue" ); // Create a new message. Message^ myMessage = gcnew Message( "Original Message" ); myMessage->AdministrationQueue = gcnew MessageQueue( ".\\myAdministrationQueue" ); myMessage->AcknowledgeType = (AcknowledgeTypes)(AcknowledgeTypes::PositiveReceive | AcknowledgeTypes::PositiveArrival); // Send the Order to the queue. myQueue->Send( myMessage ); return; } String^ ReceiveMessage() { // Connect to the a queue on the local computer. MessageQueue^ myQueue = gcnew MessageQueue( ".\\myQueue" ); myQueue->MessageReadPropertyFilter->CorrelationId = true; array<Type^>^p = gcnew array<Type^>(1); p[ 0 ] = String::typeid; myQueue->Formatter = gcnew XmlMessageFormatter( p ); String^ returnString = nullptr; try { // Receive and format the message. Message^ myMessage = myQueue->Receive(); // Display message information. Console::WriteLine( "____________________________________________" ); Console::WriteLine( "Original message information--" ); Console::WriteLine( "Body: {0}", myMessage->Body ); Console::WriteLine( "Id: {0}", myMessage->Id ); Console::WriteLine( "____________________________________________" ); returnString = myMessage->Id; } catch ( MessageQueueException^ ) { // Handle Message Queuing exceptions. } // Handle invalid serialization format. catch ( InvalidOperationException^ e ) { Console::WriteLine( e->Message ); } // Catch other exceptions as necessary. return returnString; } void ReceiveAcknowledgment( String^ messageId, String^ queuePath ) { bool found = false; MessageQueue^ queue = gcnew MessageQueue( queuePath ); queue->MessageReadPropertyFilter->CorrelationId = true; queue->MessageReadPropertyFilter->Acknowledgment = true; try { while ( queue->PeekByCorrelationId( messageId ) != nullptr ) { Message^ myAcknowledgmentMessage = queue->ReceiveByCorrelationId( messageId ); // Output acknowledgment message information. The correlation Id is identical // to the id of the original message. Console::WriteLine( "Acknowledgment Message Information--" ); Console::WriteLine( "Correlation Id: {0}", myAcknowledgmentMessage->CorrelationId ); Console::WriteLine( "Id: {0}", myAcknowledgmentMessage->Id ); Console::WriteLine( "Acknowledgment Type: {0}", myAcknowledgmentMessage->Acknowledgment ); Console::WriteLine( "____________________________________________" ); found = true; } } catch ( InvalidOperationException^ e ) { // This exception would be thrown if there is no (further) acknowledgment message // with the specified correlation Id. Only output a message if there are no messages; // not if the loop has found at least one. if ( found == false ) { Console::WriteLine( e->Message ); } // Handle other causes of invalid operation exception. } } }; int main() { // Create a new instance of the class. MyNewQueue^ myNewQueue = gcnew MyNewQueue; // Create new queues. MyNewQueue::CreateQueue( ".\\myQueue" ); MyNewQueue::CreateQueue( ".\\myAdministrationQueue" ); // Send messages to a queue. myNewQueue->SendMessage(); // Receive messages from a queue. String^ messageId = myNewQueue->ReceiveMessage(); // Receive acknowledgment message. if ( messageId != nullptr ) { myNewQueue->ReceiveAcknowledgment( messageId, ".\\myAdministrationQueue" ); } return 0; }
Available since 1.1