Message::AdministrationQueue Property
Gets or sets the queue that receives the acknowledgement messages that Message Queuing generates.
Assembly: System.Messaging (in System.Messaging.dll)
public: [MessagingDescriptionAttribute("MsgAdministrationQueue")] property MessageQueue^ AdministrationQueue { MessageQueue^ get(); void set(MessageQueue^ value); }
Property Value
Type: System.Messaging::MessageQueue^The MessageQueue that specifies the administration queue used for system-generated acknowledgment messages. The default is null.
| Exception | Condition |
|---|---|
| InvalidOperationException | The message queue is filtered to ignore the AdministrationQueue property. |
The queue specified in the AdministrationQueue property can be any non-transactional queue. The acknowledgment messages sent to the administration queue can indicate whether the original message reached its destination queue and whether it was removed from the queue.
When the AcknowledgeType property has any value other than None, the sending application must specify the queue to use as the administration queue.
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