MessageQueue.Receive 메서드

정의

큐에 있는 첫 번째 메시지를 받고, 큐에서 제거합니다.

오버로드

Receive()

MessageQueue가 참조하는 큐에서 사용할 수 있는 첫 번째 메시지를 받습니다. 이 호출은 동기적이므로 메시지를 사용할 수 있을 때까지 현재 실행 스레드를 중단합니다.

Receive(MessageQueueTransaction)

MessageQueue가 참조하는 트랜잭션 큐에서 사용할 수 있는 첫 번째 메시지를 받습니다. 이 호출은 동기적이므로 메시지를 사용할 수 있을 때까지 현재 실행 스레드를 중단합니다.

Receive(MessageQueueTransactionType)

MessageQueue가 참조하는 큐에서 사용할 수 있는 첫 번째 메시지를 받습니다. 이 호출은 동기적이므로 메시지를 사용할 수 있을 때까지 현재 실행 스레드를 중단합니다.

Receive(TimeSpan)

MessageQueue가 참조하는 큐의 첫 번째 메시지를 받고, 메시지를 큐에서 사용할 수 있거나 제한 시간이 만료될 때까지 대기합니다.

Receive(TimeSpan, Cursor)

지정된 커서를 사용하여 큐에 있는 현재 메시지를 받습니다. 사용할 수 있는 메시지가 없는 경우 이 메서드는 메시지를 사용할 수 있거나 시간 제한이 만료될 때까지 대기합니다.

Receive(TimeSpan, MessageQueueTransaction)

MessageQueue가 참조하는 트랜잭션 큐의 첫 번째 메시지를 받으며, 메시지를 큐에서 사용할 수 있거나 제한 시간이 만료될 때까지 대기합니다.

Receive(TimeSpan, MessageQueueTransactionType)

MessageQueue가 참조하는 큐에서 사용할 수 있는 첫 번째 메시지를 받습니다. 이 호출은 동기적이므로 큐에 메시지를 사용할 수 있거나 제한 시간이 만료될 때까지 대기합니다.

Receive(TimeSpan, Cursor, MessageQueueTransaction)

지정된 커서를 사용하여 큐에 있는 현재 메시지를 받습니다. 사용할 수 있는 메시지가 없는 경우 이 메서드는 메시지를 사용할 수 있거나 시간 제한이 만료될 때까지 대기합니다.

Receive(TimeSpan, Cursor, MessageQueueTransactionType)

지정된 커서를 사용하여 큐에 있는 현재 메시지를 받습니다. 사용할 수 있는 메시지가 없는 경우 이 메서드는 메시지를 사용할 수 있거나 시간 제한이 만료될 때까지 대기합니다.

Receive()

MessageQueue가 참조하는 큐에서 사용할 수 있는 첫 번째 메시지를 받습니다. 이 호출은 동기적이므로 메시지를 사용할 수 있을 때까지 현재 실행 스레드를 중단합니다.

public:
 System::Messaging::Message ^ Receive();
public System.Messaging.Message Receive ();
member this.Receive : unit -> System.Messaging.Message
Public Function Receive () As Message

반환

큐에서 사용할 수 있는 첫 번째 메시지를 참조하는 Message를 반환합니다.

예외

메시지 큐 메서드에 액세스하는 동안 오류가 발생한 경우

예제

다음 코드 예제에서는 큐에서 메시지를 수신하고 해당 메시지에 대한 정보를 화면에 출력합니다.

#using <system.dll>
#using <system.messaging.dll>

using namespace System;
using namespace System::Messaging;

// This class represents an object the following example 
// sends to a queue and receives from a queue.
ref class Order
{
public:
   int orderId;
   DateTime orderTime;
};


/// <summary>
/// Provides a container class for the example.
/// </summary>
ref class MyNewQueue
{
public:

   //*************************************************
   // Sends an Order to a queue.
   //*************************************************
   void SendMessage()
   {
      // Create a new order and set values.
      Order^ sentOrder = gcnew Order;
      sentOrder->orderId = 3;
      sentOrder->orderTime = DateTime::Now;

      // Connect to a queue on the local computer.
      MessageQueue^ myQueue = gcnew MessageQueue( ".\\myQueue" );

      // Send the Order to the queue.
      myQueue->Send( sentOrder );
      return;
   }

   //*************************************************
   // Receives a message containing an Order.
   //*************************************************
   void ReceiveMessage()
   {
      // Connect to the a queue on the local computer.
      MessageQueue^ myQueue = gcnew MessageQueue( ".\\myQueue" );

      // Set the formatter to indicate body contains an Order.
      array<Type^>^p = gcnew array<Type^>(1);
      p[ 0 ] = Order::typeid;
      myQueue->Formatter = gcnew XmlMessageFormatter( p );
      try
      {
         // Receive and format the message. 
         Message^ myMessage = myQueue->Receive();
         Order^ myOrder = static_cast<Order^>(myMessage->Body);

         // Display message information.
         Console::WriteLine( "Order ID: {0}", myOrder->orderId );
         Console::WriteLine( "Sent: {0}", myOrder->orderTime );
      }
      catch ( MessageQueueException^ ) 
      {
         // Handle Message Queuing exceptions.
      }
      // Handle invalid serialization format.
      catch ( InvalidOperationException^ e ) 
      {
         Console::WriteLine( e->Message );
      }

      // Catch other exceptions as necessary.
      return;
   }
};

//*************************************************
// Provides an entry point into the application.
//         
// This example sends and receives a message from
// a queue.
//*************************************************
int main()
{
   // Create a new instance of the class.
   MyNewQueue^ myNewQueue = gcnew MyNewQueue;

   // Send a message to a queue.
   myNewQueue->SendMessage();

   // Receive a message from a queue.
   myNewQueue->ReceiveMessage();
   return 0;
}
using System;
using System.Messaging;

namespace MyProject
{

    // This class represents an object the following example
    // sends to a queue and receives from a queue.
    public class Order
    {
        public int orderId;
        public DateTime orderTime;
    };	

    /// <summary>
    /// Provides a container class for the example.
    /// </summary>
    public class MyNewQueue
    {

        //**************************************************
        // Provides an entry point into the application.
        //		
        // This example sends and receives a message from
        // a queue.
        //**************************************************

        public static void Main()
        {
            // Create a new instance of the class.
            MyNewQueue myNewQueue = new MyNewQueue();

            // Send a message to a queue.
            myNewQueue.SendMessage();

            // Receive a message from a queue.
            myNewQueue.ReceiveMessage();

            return;
        }

        //**************************************************
        // Sends an Order to a queue.
        //**************************************************
        
        public void SendMessage()
        {
            
            // Create a new order and set values.
            Order sentOrder = new Order();
            sentOrder.orderId = 3;
            sentOrder.orderTime = DateTime.Now;

            // Connect to a queue on the local computer.
            MessageQueue myQueue = new MessageQueue(".\\myQueue");

            // Send the Order to the queue.
            myQueue.Send(sentOrder);

            return;
        }

        //**************************************************
        // Receives a message containing an Order.
        //**************************************************
        
        public  void ReceiveMessage()
        {
            // Connect to the a queue on the local computer.
            MessageQueue myQueue = new MessageQueue(".\\myQueue");

            // Set the formatter to indicate body contains an Order.
            myQueue.Formatter = new XmlMessageFormatter(new Type[]
                {typeof(MyProject.Order)});
            
            try
            {
                // Receive and format the message.
                Message myMessage =	myQueue.Receive();
                Order myOrder = (Order)myMessage.Body;

                // Display message information.
                Console.WriteLine("Order ID: " +
                    myOrder.orderId.ToString());
                Console.WriteLine("Sent: " +
                    myOrder.orderTime.ToString());
            }
            
            catch (MessageQueueException)
            {
                // Handle Message Queuing exceptions.
            }

            // Handle invalid serialization format.
            catch (InvalidOperationException e)
            {
                Console.WriteLine(e.Message);
            }
            
            // Catch other exceptions as necessary.

            return;
        }
    }
}
Imports System.Messaging

    ' This class represents an object the following example 
    ' sends to a queue and receives from a queue.
    Public Class Order
        Public orderId As Integer
        Public orderTime As DateTime
    End Class


   
    Public Class MyNewQueue


        '
        ' Provides an entry point into the application.
        '		 
        ' This example sends and receives a message from
        ' a qeue.
        '

        Public Shared Sub Main()

            ' Create a new instance of the class.
            Dim myNewQueue As New MyNewQueue()

            ' Send a message to a queue.
            myNewQueue.SendMessage()

            ' Receive a message from a queue.
            myNewQueue.ReceiveMessage()

            Return

        End Sub


        '
        ' Sends an Order to a queue.
        '

        Public Sub SendMessage()

            ' Create a new order and set values.
            Dim sentOrder As New Order()
            sentOrder.orderId = 3
            sentOrder.orderTime = DateTime.Now

            ' Connect to a queue on the local computer.
            Dim myQueue As New MessageQueue(".\myQueue")

            ' Send the Order to the queue.
            myQueue.Send(sentOrder)

            Return

        End Sub


        '
        ' Receives a message containing an Order.
        '

        Public Sub ReceiveMessage()

            ' Connect to the a queue on the local computer.
            Dim myQueue As New MessageQueue(".\myQueue")

            ' Set the formatter to indicate the body contains an Order.
            myQueue.Formatter = New XmlMessageFormatter(New Type() _
                {GetType(Order)})

            Try

                ' Receive and format the message. 
                Dim myMessage As Message = myQueue.Receive()
                Dim myOrder As Order = CType(myMessage.Body, Order)

                ' Display message information.
                Console.WriteLine(("Order ID: " + _
                    myOrder.orderId.ToString()))
                Console.WriteLine(("Sent: " + _
                    myOrder.orderTime.ToString()))

            Catch m As MessageQueueException
                ' Handle Message Queuing exceptions.

            Catch e As InvalidOperationException
                ' Handle invalid serialization format.
                Console.WriteLine(e.Message)


                ' Catch other exceptions as necessary.

            End Try

            Return

        End Sub

End Class

설명

이 오버로드를 사용하여 큐에서 메시지를 받거나 큐에 메시지가 있을 때까지 기다립니다.

메서드를 Receive 사용하면 메시지를 동기적으로 읽을 수 있으므로 큐에서 메시지를 제거할 수 있습니다. 에 대한 Receive 후속 호출은 큐에 오는 메시지 또는 우선 순위가 더 높은 새 메시지를 반환합니다.

큐에서 메시지를 제거하지 않고 큐의 첫 번째 메시지를 읽으려면 메서드를 Peek 사용합니다. 메서드는 Peek 항상 큐에서 첫 번째 메시지를 반환하므로 우선 순위가 높은 메시지가 큐에 도착하지 않는 한 메서드에 대한 후속 호출은 동일한 메시지를 반환합니다.

메시지가 큐에 Receive 도착할 때까지 기다리는 동안 현재 스레드가 차단될 수 있는 경우 호출을 사용합니다. 이 오버 로드는 Receive 메서드는 무기한 시간 제한을 지정, 애플리케이션이 무기한 대기 합니다. 애플리케이션 처리 메시지를 기다리지 않고 계속 해야 하는 경우 비동기 메서드를 사용 하 여 고려해 야 BeginReceive합니다.

다음 표에서는 이 메서드를 다양한 작업 그룹 모드에서 사용할 수 있는지 여부를 보여 줍니다.

작업 그룹 모드 사용 가능
수집 Yes
로컬 컴퓨터 및 직접 형식 이름 Yes
원격 컴퓨터 No
원격 컴퓨터 및 직접 형식 이름 Yes

추가 정보

적용 대상

Receive(MessageQueueTransaction)

MessageQueue가 참조하는 트랜잭션 큐에서 사용할 수 있는 첫 번째 메시지를 받습니다. 이 호출은 동기적이므로 메시지를 사용할 수 있을 때까지 현재 실행 스레드를 중단합니다.

public:
 System::Messaging::Message ^ Receive(System::Messaging::MessageQueueTransaction ^ transaction);
public System.Messaging.Message Receive (System.Messaging.MessageQueueTransaction transaction);
member this.Receive : System.Messaging.MessageQueueTransaction -> System.Messaging.Message
Public Function Receive (transaction As MessageQueueTransaction) As Message

매개 변수

반환

큐에서 사용할 수 있는 첫 번째 메시지를 참조하는 Message를 반환합니다.

예외

메시지 큐 메서드에 액세스하는 동안 오류가 발생한 경우

또는

비트랜잭션 큐입니다.

예제

다음 코드 예제에서는 로컬 컴퓨터의 트랜잭션 큐에 연결하고 큐에 메시지를 보냅니다. 그런 다음 주문이 포함된 메시지를 받습니다. 비 트랜잭션 큐가 발견되면 및 예외를 throw하고 트랜잭션을 롤백합니다.

#using <system.dll>
#using <system.messaging.dll>

using namespace System;
using namespace System::Messaging;

/// <summary>
/// Provides a container class for the example.
/// </summary>
ref class MyNewQueue
{
public:

   //*************************************************
   // Sends a message to a queue.
   //*************************************************
   void SendMessageTransactional()
   {
      // Connect to a queue on the local computer.
      MessageQueue^ myQueue = gcnew MessageQueue( ".\\myTransactionalQueue" );

      // Send a message to the queue.
      if ( myQueue->Transactional == true )
      {
         // Create a transaction.
         MessageQueueTransaction^ myTransaction = gcnew MessageQueueTransaction;

         // Begin the transaction.
         myTransaction->Begin();

         // Send the message.
         myQueue->Send( "My Message Data.", myTransaction );

         // Commit the transaction.
         myTransaction->Commit();
      }

      return;
   }


   //*************************************************
   // Receives a message containing an Order.
   //*************************************************
   void ReceiveMessageTransactional()
   {
      // Connect to a transactional queue on the local computer.
      MessageQueue^ myQueue = gcnew MessageQueue( ".\\myTransactionalQueue" );

      // Set the formatter.
      array<Type^>^p = gcnew array<Type^>(1);
      p[ 0 ] = String::typeid;
      myQueue->Formatter = gcnew XmlMessageFormatter( p );

      // Create a transaction.
      MessageQueueTransaction^ myTransaction = gcnew MessageQueueTransaction;
      try
      {
         // Begin the transaction.
         myTransaction->Begin();

         // Receive the message. 
         Message^ myMessage = myQueue->Receive( myTransaction );
         String^ myOrder = static_cast<String^>(myMessage->Body);

         // Display message information.
         Console::WriteLine( myOrder );

         // Commit the transaction.
         myTransaction->Commit();
      }
      catch ( MessageQueueException^ e ) 
      {
         // Handle nontransactional queues.
         if ( e->MessageQueueErrorCode == MessageQueueErrorCode::TransactionUsage )
         {
            Console::WriteLine( "Queue is not transactional." );
         }

         // Else catch other sources of a MessageQueueException.
         // Roll back the transaction.
         myTransaction->Abort();
      }

      // Catch other exceptions as necessary, such as 
      // InvalidOperationException, thrown when the formatter 
      // cannot deserialize the message.
      return;
   }
};

//*************************************************
// Provides an entry point into the application.
// 
// This example sends and receives a message from
// a transactional queue.
//*************************************************
int main()
{
   // Create a new instance of the class.
   MyNewQueue^ myNewQueue = gcnew MyNewQueue;

   // Send a message to a queue.
   myNewQueue->SendMessageTransactional();

   // Receive a message from a queue.
   myNewQueue->ReceiveMessageTransactional();
   return 0;
}
using System;
using System.Messaging;

namespace MyProject
{

    /// <summary>
    /// Provides a container class for the example.
    /// </summary>
    public class MyNewQueue
    {

        //**************************************************
        // Provides an entry point into the application.
        //
        // This example sends and receives a message from
        // a transactional queue.
        //**************************************************

        public static void Main()
        {
            // Create a new instance of the class.
            MyNewQueue myNewQueue = new MyNewQueue();

            // Send a message to a queue.
            myNewQueue.SendMessageTransactional();

            // Receive a message from a queue.
            myNewQueue.ReceiveMessageTransactional();

            return;
        }

        //**************************************************
        // Sends a message to a queue.
        //**************************************************
        
        public void SendMessageTransactional()
        {
                        
            // Connect to a queue on the local computer.
            MessageQueue myQueue = new
                MessageQueue(".\\myTransactionalQueue");

            // Send a message to the queue.
            if (myQueue.Transactional == true)
            {
                // Create a transaction.
                MessageQueueTransaction myTransaction = new
                    MessageQueueTransaction();

                // Begin the transaction.
                myTransaction.Begin();

                // Send the message.
                myQueue.Send("My Message Data.", myTransaction);

                // Commit the transaction.
                myTransaction.Commit();
            }

            return;
        }

        //**************************************************
        // Receives a message containing an Order.
        //**************************************************
        
        public  void ReceiveMessageTransactional()
        {
            // Connect to a transactional queue on the local computer.
            MessageQueue myQueue = new
                MessageQueue(".\\myTransactionalQueue");

            // Set the formatter.
            myQueue.Formatter = new XmlMessageFormatter(new Type[]
                {typeof(String)});
            
            // Create a transaction.
            MessageQueueTransaction myTransaction = new
                MessageQueueTransaction();

            try
            {
                // Begin the transaction.
                myTransaction.Begin();
                
                // Receive the message.
                Message myMessage =	myQueue.Receive(myTransaction);
                String myOrder = (String)myMessage.Body;

                // Display message information.
                Console.WriteLine(myOrder);

                // Commit the transaction.
                myTransaction.Commit();
            }
            
            catch (MessageQueueException e)
            {
                // Handle nontransactional queues.
                if (e.MessageQueueErrorCode ==
                    MessageQueueErrorCode.TransactionUsage)
                {
                    Console.WriteLine("Queue is not transactional.");
                }
                
                // Else catch other sources of a MessageQueueException.

                // Roll back the transaction.
                myTransaction.Abort();
            }

            // Catch other exceptions as necessary, such as
            // InvalidOperationException, thrown when the formatter
            // cannot deserialize the message.

            return;
        }
    }
}
Imports System.Messaging

Public Class MyNewQueue


        '
        ' Provides an entry point into the application.
        ' 
        ' This example sends and receives a message from
        ' a transactional queue.
        '

        Public Shared Sub Main()

            ' Create a new instance of the class.
            Dim myNewQueue As New MyNewQueue

            ' Send a message to a queue.
            myNewQueue.SendMessageTransactional()

            ' Receive a message from a queue.
            myNewQueue.ReceiveMessageTransactional()

            Return

        End Sub


        '
        ' Sends a message to a queue.
        '

        Public Sub SendMessageTransactional()

            ' Connect to a queue on the local computer.
            Dim myQueue As New MessageQueue(".\myTransactionalQueue")

            ' Send a message to the queue.
            If myQueue.Transactional = True Then

                ' Create a transaction.
                Dim myTransaction As New MessageQueueTransaction

                ' Begin the transaction.
                myTransaction.Begin()

                ' Send the message.
                myQueue.Send("My Message Data.", myTransaction)

                ' Commit the transaction.
                myTransaction.Commit()

            End If

            Return

        End Sub


        '
        ' Receives a message containing an Order.
        '

        Public Sub ReceiveMessageTransactional()

            ' Connect to a transactional queue on the local computer.
            Dim myQueue As New MessageQueue(".\myTransactionalQueue")

            ' Set the formatter.
            myQueue.Formatter = New XmlMessageFormatter(New Type() _
                {GetType([String])})

            ' Create a transaction.
            Dim myTransaction As New MessageQueueTransaction

            Try

                ' Begin the transaction.
                myTransaction.Begin()

                ' Receive the message. 
                Dim myMessage As Message = _
                    myQueue.Receive(myTransaction)
                Dim myOrder As [String] = CType(myMessage.Body, _
                    [String])

                ' Display message information.
                Console.WriteLine(myOrder)

                ' Commit the transaction.
                myTransaction.Commit()


            Catch e As MessageQueueException

                ' Handle nontransactional queues.
                If e.MessageQueueErrorCode = _
                    MessageQueueErrorCode.TransactionUsage Then

                    Console.WriteLine("Queue is not transactional.")

                End If

                ' Else catch other sources of a MessageQueueException.


                ' Roll back the transaction.
                myTransaction.Abort()


                ' Catch other exceptions as necessary, such as 
                ' InvalidOperationException, thrown when the formatter
                ' cannot deserialize the message.

            End Try

            Return

        End Sub

End Class

설명

이 오버로드를 사용하여 매개 변수로 정의된 transaction 내부 트랜잭션 컨텍스트를 사용하여 트랜잭션 큐에서 메시지를 받거나 큐에 메시지가 있을 때까지 기다립니다.

메서드를 Receive 사용하면 메시지를 동기적으로 읽을 수 있으므로 큐에서 메시지를 제거할 수 있습니다. 에 대한 Receive 후속 호출은 큐에 오는 메시지를 반환합니다.

이 메서드는 트랜잭션 큐에서 호출되므로 트랜잭션이 중단되면 수신된 메시지가 큐로 반환됩니다. 트랜잭션이 커밋될 때까지 메시지는 큐에서 영구적으로 제거되지 않습니다.

큐에서 메시지를 제거하지 않고 큐의 첫 번째 메시지를 읽으려면 메서드를 Peek 사용합니다. 메서드는 Peek 항상 큐에서 첫 번째 메시지를 반환하므로 우선 순위가 높은 메시지가 큐에 도착하지 않는 한 메서드에 대한 후속 호출은 동일한 메시지를 반환합니다. 에 대한 호출 Peek에서 반환된 메시지와 연결된 트랜잭션 컨텍스트가 없습니다. Peek 큐에서 메시지를 제거하지 않으므로 에 대한 호출Abort로 롤백할 필요가 없습니다.

메시지가 큐에 Receive 도착할 때까지 기다리는 동안 현재 스레드가 차단될 수 있는 경우 호출을 사용합니다. 이 오버 로드는 Receive 메서드는 무기한 시간 제한을 지정, 애플리케이션이 무기한 대기 합니다. 애플리케이션 처리 메시지를 기다리지 않고 계속 해야 하는 경우 비동기 메서드를 사용 하 여 고려해 야 BeginReceive합니다.

다음 표에서는 이 메서드를 다양한 작업 그룹 모드에서 사용할 수 있는지 여부를 보여 줍니다.

작업 그룹 모드 사용 가능
수집 Yes
로컬 컴퓨터 및 직접 형식 이름 Yes
원격 컴퓨터 No
원격 컴퓨터 및 직접 형식 이름 Yes

추가 정보

적용 대상

Receive(MessageQueueTransactionType)

MessageQueue가 참조하는 큐에서 사용할 수 있는 첫 번째 메시지를 받습니다. 이 호출은 동기적이므로 메시지를 사용할 수 있을 때까지 현재 실행 스레드를 중단합니다.

public:
 System::Messaging::Message ^ Receive(System::Messaging::MessageQueueTransactionType transactionType);
public System.Messaging.Message Receive (System.Messaging.MessageQueueTransactionType transactionType);
member this.Receive : System.Messaging.MessageQueueTransactionType -> System.Messaging.Message
Public Function Receive (transactionType As MessageQueueTransactionType) As Message

매개 변수

transactionType
MessageQueueTransactionType

MessageQueueTransactionType 값 중 하나로, 메시지와 연결할 트랜잭션 컨텍스트 형식을 설명합니다.

반환

큐에서 사용할 수 있는 첫 번째 메시지를 참조하는 Message를 반환합니다.

예외

메시지 큐 메서드에 액세스하는 동안 오류가 발생한 경우

transactionType 매개 변수가 MessageQueueTransactionType 멤버 중 하나가 아닌 경우

예제

다음 코드 예제에서는 Receive(MessageQueueTransactionType)의 사용법을 보여줍니다.


// Connect to a transactional queue on the local computer.
MessageQueue^ queue = gcnew MessageQueue(".\\exampleTransQueue");

// Create a new message.
Message^ msg = gcnew Message("Example Message Body");

// Send the message.
queue->Send(msg, MessageQueueTransactionType::Single);

// Simulate doing other work so the message has time to arrive.
System::Threading::Thread::Sleep(TimeSpan::FromSeconds(10.0));

// Set the formatter to indicate the message body contains a String.
queue->Formatter = gcnew XmlMessageFormatter(
    gcnew array<Type^>{String::typeid});

// Receive the message from the queue.  Because the Id of the message
// , it might not be the message just sent.
msg = queue->Receive(MessageQueueTransactionType::Single);

queue->Close();

// Connect to a transactional queue on the local computer.
MessageQueue queue = new MessageQueue(".\\exampleTransQueue");

// Create a new message.
Message msg = new Message("Example Message Body");

// Send the message.
queue.Send(msg, MessageQueueTransactionType.Single);

// Simulate doing other work so the message has time to arrive.
System.Threading.Thread.Sleep(TimeSpan.FromSeconds(10.0));

// Set the formatter to indicate the message body contains a String.
queue.Formatter = new XmlMessageFormatter(new Type[]
    {typeof(String)});

// Receive the message from the queue.  Because the Id of the message
// , it might not be the message just sent.
msg = queue.Receive(MessageQueueTransactionType.Single);

설명

이 오버로드를 사용하여 매개 변수로 정의된 transactionType 트랜잭션 컨텍스트를 사용하여 큐에서 메시지를 받거나 큐에 메시지가 있을 때까지 기다립니다.

메시지를 수신하는 transactionType 데 사용할 스레드에 연결된 외부 트랜잭션 컨텍스트가 이미 있는 경우 매개 변수를 지정 Automatic 합니다. Single 메시지를 단일 내부 트랜잭션으로 받을지 지정합니다. 트랜잭션 컨텍스트 외부의 트랜잭션 큐에서 메시지를 받을지 지정할 수 있습니다 None .

메서드를 Receive 사용하면 메시지를 동기적으로 읽을 수 있으므로 큐에서 메시지를 제거할 수 있습니다. 에 대한 Receive 후속 호출은 큐에 오는 메시지를 반환합니다.

트랜잭션 큐에서 메시지를 수신하기 위해 이 메서드를 호출하면 트랜잭션이 중단된 경우 수신된 메시지가 큐로 반환됩니다. 트랜잭션이 커밋될 때까지 메시지는 큐에서 영구적으로 제거되지 않습니다.

큐에서 메시지를 제거하지 않고 큐의 첫 번째 메시지를 읽으려면 메서드를 Peek 사용합니다. 메서드는 Peek 항상 큐에서 첫 번째 메시지를 반환하므로 우선 순위가 높은 메시지가 큐에 도착하지 않는 한 메서드에 대한 후속 호출은 동일한 메시지를 반환합니다. 에 대한 호출 Peek에서 반환된 메시지와 연결된 트랜잭션 컨텍스트가 없습니다. Peek 큐에서 메시지를 제거하지 않으므로 에 대한 호출Abort로 롤백할 필요가 없습니다.

메시지가 큐에 Receive 도착할 때까지 기다리는 동안 현재 스레드가 차단될 수 있는 경우 호출을 사용합니다. 이 오버 로드는 Receive 메서드는 무기한 시간 제한을 지정, 애플리케이션이 무기한 대기 합니다. 애플리케이션 처리 메시지를 기다리지 않고 계속 해야 하는 경우 비동기 메서드를 사용 하 여 고려해 야 BeginReceive합니다.

다음 표에서는 이 메서드를 다양한 작업 그룹 모드에서 사용할 수 있는지 여부를 보여 줍니다.

작업 그룹 모드 사용 가능
수집 Yes
로컬 컴퓨터 및 직접 형식 이름 Yes
원격 컴퓨터 No
원격 컴퓨터 및 직접 형식 이름 Yes

추가 정보

적용 대상

Receive(TimeSpan)

MessageQueue가 참조하는 큐의 첫 번째 메시지를 받고, 메시지를 큐에서 사용할 수 있거나 제한 시간이 만료될 때까지 대기합니다.

public:
 System::Messaging::Message ^ Receive(TimeSpan timeout);
public System.Messaging.Message Receive (TimeSpan timeout);
member this.Receive : TimeSpan -> System.Messaging.Message
Public Function Receive (timeout As TimeSpan) As Message

매개 변수

timeout
TimeSpan

새 메시지를 검사할 수 있을 때까지 기다리는 시간을 나타내는 TimeSpan입니다.

반환

큐에서 사용할 수 있는 첫 번째 메시지를 참조하는 Message를 반환합니다.

예외

timeout 매개 변수에 지정된 값이 잘못된 경우. timeoutZero보다 작거나 InfiniteTimeout보다 클 수 있습니다.

제한 시간이 만료되기 전에 큐에 메시지가 도착하지 않았습니다.

또는

메시지 큐 메서드에 액세스하는 동안 오류가 발생한 경우

예제

다음 코드 예제에서는 큐에서 메시지를 수신하고 해당 메시지에 대한 정보를 화면에 출력합니다. 이 예제에서는 큐에 메시지가 도착할 때까지 기다리는 동안 최대 5초 동안 실행을 일시 중지합니다.

#using <system.dll>
#using <system.messaging.dll>

using namespace System;
using namespace System::Messaging;

// This class represents an object the following example 
// receives from a queue.
ref class Order
{
public:
   int orderId;
   DateTime orderTime;
};


/// <summary>
/// Provides a container class for the example.
/// </summary>
ref class MyNewQueue
{
public:

   //*************************************************
   // Receives a message containing an Order.
   //*************************************************
   void ReceiveMessage()
   {
      // Connect to the a queue on the local computer.
      MessageQueue^ myQueue = gcnew MessageQueue( ".\\myQueue" );

      // Set the formatter to indicate body contains an Order.
      array<Type^>^p = gcnew array<Type^>(1);
      p[ 0 ] = Order::typeid;
      myQueue->Formatter = gcnew XmlMessageFormatter( p );
      try
      {
         // Receive and format the message. 
         // Wait 5 seconds for a message to arrive.
         Message^ myMessage = myQueue->Receive( TimeSpan(0,0,5) );
         Order^ myOrder = static_cast<Order^>(myMessage->Body);

         // Display message information.
         Console::WriteLine( "Order ID: {0}", myOrder->orderId );
         Console::WriteLine( "Sent: {0}", myOrder->orderTime );
      }
      catch ( MessageQueueException^ e ) 
      {
         // Handle no message arriving in the queue.
         if ( e->MessageQueueErrorCode == MessageQueueErrorCode::IOTimeout )
         {
            Console::WriteLine( "No message arrived in queue." );
         }

         // Handle other sources of a MessageQueueException.
      }
      // Handle invalid serialization format.
      catch ( InvalidOperationException^ e ) 
      {
         Console::WriteLine( e->Message );
      }

      // Catch other exceptions as necessary.
      return;
   }
};

//*************************************************
// Provides an entry point into the application.
//         
// This example receives a message from a queue.
//*************************************************
int main()
{
   // Create a new instance of the class.
   MyNewQueue^ myNewQueue = gcnew MyNewQueue;

   // Receive a message from a queue.
   myNewQueue->ReceiveMessage();
   return 0;
}
using System;
using System.Messaging;

namespace MyProject
{
    // This class represents an object the following example
    // receives from a queue.

    public class Order
    {
        public int orderId;
        public DateTime orderTime;
    };	

    /// <summary>
    /// Provides a container class for the example.
    /// </summary>
    public class MyNewQueue
    {

        //**************************************************
        // Provides an entry point into the application.
        //		
        // This example receives a message from a queue.
        //**************************************************

        public static void Main()
        {
            // Create a new instance of the class.
            MyNewQueue myNewQueue = new MyNewQueue();

            // Receive a message from a queue.
            myNewQueue.ReceiveMessage();

            return;
        }

        //**************************************************
        // Receives a message containing an Order.
        //**************************************************

        public void ReceiveMessage()
        {
            // Connect to the a queue on the local computer.
            MessageQueue myQueue = new MessageQueue(".\\myQueue");

            // Set the formatter to indicate body contains an Order.
            myQueue.Formatter = new XmlMessageFormatter(new Type[]
                {typeof(MyProject.Order)});
            
            try
            {
                // Receive and format the message.
                // Wait 5 seconds for a message to arrive.
                Message myMessage =	myQueue.Receive(new
                    TimeSpan(0,0,5));
                Order myOrder = (Order)myMessage.Body;

                // Display message information.
                Console.WriteLine("Order ID: " +
                    myOrder.orderId.ToString());
                Console.WriteLine("Sent: " +
                    myOrder.orderTime.ToString());
            }

            catch (MessageQueueException e)
            {
                // Handle no message arriving in the queue.
                if (e.MessageQueueErrorCode ==
                    MessageQueueErrorCode.IOTimeout)
                {
                    Console.WriteLine("No message arrived in queue.");
                }			

                // Handle other sources of a MessageQueueException.
            }
            
            // Handle invalid serialization format.
            catch (InvalidOperationException e)
            {
                Console.WriteLine(e.Message);
            }
            
            // Catch other exceptions as necessary.

            return;
        }
    }
}
Imports System.Messaging

' This class represents an object the following example 
' receives from a queue.
Public Class Order
        Public orderId As Integer
        Public orderTime As DateTime
End Class


   
Public Class MyNewQueue


        '
        ' Provides an entry point into the application.
        '		 
        ' This example receives a message from a queue.
        '

        Public Shared Sub Main()

            ' Create a new instance of the class.
            Dim myNewQueue As New MyNewQueue()

            ' Receive a message from a queue.
            myNewQueue.ReceiveMessage()

            Return

        End Sub


        '
        ' Receives a message containing an Order.
        '

        Public Sub ReceiveMessage()

            ' Connect to the a queue on the local computer.
            Dim myQueue As New MessageQueue(".\myQueue")

            ' Set the formatter to indicate body contains an Order.
            myQueue.Formatter = New XmlMessageFormatter(New Type() _
                {GetType(Order)})

            Try

                ' Receive and format the message. 
                ' Wait 5 seconds for a message to arrive.
                Dim myMessage As Message = myQueue.Receive(New _
                    TimeSpan(0, 0, 5))
                Dim myOrder As Order = CType(myMessage.Body, Order)

                ' Display message information.
                Console.WriteLine(("Order ID: " + _
                    myOrder.orderId.ToString()))
                Console.WriteLine(("Sent: " + _
                    myOrder.orderTime.ToString()))

            Catch e As MessageQueueException
                ' Handle no message arriving in the queue.
                If e.MessageQueueErrorCode = _
                    MessageQueueErrorCode.IOTimeout Then

                    Console.WriteLine("No message arrived in queue.")

                End If

                ' Handle other sources of a MessageQueueException.

            Catch e As InvalidOperationException
                ' Handle invalid serialization format.
                Console.WriteLine(e.Message)

                ' Catch other exceptions as necessary.

            End Try

            Return

        End Sub

End Class

설명

이 오버로드를 사용하여 메시지를 받고, 큐에 메시지가 없는 경우에는 지정된 시간 내에 반환합니다.

메서드를 Receive 사용하면 메시지를 동기적으로 읽고 큐에서 메시지를 제거할 수 있습니다. 에 대한 Receive 후속 호출은 큐에 오는 메시지 또는 우선 순위가 더 높은 새 메시지를 반환합니다.

큐에서 메시지를 제거하지 않고 큐의 첫 번째 메시지를 읽으려면 메서드를 Peek 사용합니다. 메서드는 Peek 항상 큐에서 첫 번째 메시지를 반환하므로 우선 순위가 높은 메시지가 큐에 도착하지 않는 한 메서드에 대한 후속 호출은 동일한 메시지를 반환합니다.

메시지가 큐에 Receive 도착할 때까지 기다리는 동안 현재 스레드가 차단될 수 있는 경우 호출을 사용합니다. 스레드는 지정된 기간 동안 차단되거나 매개 변수의 값을 InfiniteTimeouttimeout 지정한 경우 무기한 차단됩니다. 애플리케이션 처리 메시지를 기다리지 않고 계속 해야 하는 경우 비동기 메서드를 사용 하 여 고려해 야 BeginReceive합니다.

다음 표에서는 이 메서드를 다양한 작업 그룹 모드에서 사용할 수 있는지 여부를 보여 줍니다.

작업 그룹 모드 사용 가능
수집 Yes
로컬 컴퓨터 및 직접 형식 이름 Yes
원격 컴퓨터 No
원격 컴퓨터 및 직접 형식 이름 Yes

추가 정보

적용 대상

Receive(TimeSpan, Cursor)

지정된 커서를 사용하여 큐에 있는 현재 메시지를 받습니다. 사용할 수 있는 메시지가 없는 경우 이 메서드는 메시지를 사용할 수 있거나 시간 제한이 만료될 때까지 대기합니다.

public:
 System::Messaging::Message ^ Receive(TimeSpan timeout, System::Messaging::Cursor ^ cursor);
public System.Messaging.Message Receive (TimeSpan timeout, System.Messaging.Cursor cursor);
member this.Receive : TimeSpan * System.Messaging.Cursor -> System.Messaging.Message
Public Function Receive (timeout As TimeSpan, cursor As Cursor) As Message

매개 변수

timeout
TimeSpan

새 메시지를 검사할 수 있을 때까지 기다리는 시간을 나타내는 TimeSpan입니다.

cursor
Cursor

메시지 큐에서 특정 위치를 유지하는 Cursor입니다.

반환

큐에서 사용할 수 있는 첫 번째 메시지를 참조하는 Message를 반환합니다.

예외

timeout 매개 변수에 지정된 값이 잘못된 경우. timeoutZero보다 작거나 InfiniteTimeout보다 클 수 있습니다.

제한 시간이 만료되기 전에 큐에 메시지가 도착하지 않았습니다.

또는

메시지 큐 메서드에 액세스하는 동안 오류가 발생한 경우

이 오버로드를 사용하여 메시지를 받고, 큐에 메시지가 없는 경우에는 지정된 시간 내에 반환합니다.

적용 대상

Receive(TimeSpan, MessageQueueTransaction)

MessageQueue가 참조하는 트랜잭션 큐의 첫 번째 메시지를 받으며, 메시지를 큐에서 사용할 수 있거나 제한 시간이 만료될 때까지 대기합니다.

public:
 System::Messaging::Message ^ Receive(TimeSpan timeout, System::Messaging::MessageQueueTransaction ^ transaction);
public System.Messaging.Message Receive (TimeSpan timeout, System.Messaging.MessageQueueTransaction transaction);
member this.Receive : TimeSpan * System.Messaging.MessageQueueTransaction -> System.Messaging.Message
Public Function Receive (timeout As TimeSpan, transaction As MessageQueueTransaction) As Message

매개 변수

timeout
TimeSpan

새 메시지를 검사할 수 있을 때까지 기다리는 시간을 나타내는 TimeSpan입니다.

반환

큐에서 사용할 수 있는 첫 번째 메시지를 참조하는 Message를 반환합니다.

예외

timeout 매개 변수에 지정된 값이 잘못된 경우. timeoutZero보다 작거나 InfiniteTimeout보다 클 수 있습니다.

제한 시간이 만료되기 전에 큐에 메시지가 도착하지 않았습니다.

또는

비트랜잭션 큐입니다.

또는

메시지 큐 메서드에 액세스하는 동안 오류가 발생한 경우

예제

다음 코드 예제에서는이 메서드를 사용 하는 방법을 보여 줍니다.

#using <system.dll>
#using <system.messaging.dll>

using namespace System;
using namespace System::Messaging;

/// <summary>
/// Provides a container class for the example.
/// </summary>
ref class MyNewQueue
{
public:

   //*************************************************
   // Sends a message to a transactional queue.
   //*************************************************
   void SendMessageTransactional()
   {
      // Connect to a queue on the local computer.
      MessageQueue^ myQueue = gcnew MessageQueue( ".\\myTransactionalQueue" );

      // Send a message to the queue.
      if ( myQueue->Transactional == true )
      {
         // Create a transaction.
         MessageQueueTransaction^ myTransaction = gcnew MessageQueueTransaction;

         // Begin the transaction.
         myTransaction->Begin();

         // Send the message.
         myQueue->Send( "My Message Data.", myTransaction );

         // Commit the transaction.
         myTransaction->Commit();
      }

      return;
   }

   //*************************************************
   // Receives a message from the transactional queue.
   //*************************************************
   void ReceiveMessageTransactional()
   {
      // Connect to a transactional queue on the local computer.
      MessageQueue^ myQueue = gcnew MessageQueue( ".\\myTransactionalQueue" );

      // Set the formatter.
      array<Type^>^p = gcnew array<Type^>(1);
      p[ 0 ] = String::typeid;
      myQueue->Formatter = gcnew XmlMessageFormatter( p );

      // Create a transaction.
      MessageQueueTransaction^ myTransaction = gcnew MessageQueueTransaction;
      try
      {
         // Begin the transaction.
         myTransaction->Begin();

         // Receive the message. 
         // Wait five seconds for a message to arrive. 
         Message^ myMessage = myQueue->Receive( TimeSpan(0,0,5), myTransaction );
         String^ myOrder = static_cast<String^>(myMessage->Body);

         // Display message information.
         Console::WriteLine( myOrder );

         // Commit the transaction.
         myTransaction->Commit();
      }
      catch ( MessageQueueException^ e ) 
      {
         // Handle nontransactional queues.
         if ( e->MessageQueueErrorCode == MessageQueueErrorCode::TransactionUsage )
         {
            Console::WriteLine( "Queue is not transactional." );
         }
         // Handle no message arriving in the queue.
         else

         // Handle no message arriving in the queue.
         if ( e->MessageQueueErrorCode == MessageQueueErrorCode::IOTimeout )
         {
            Console::WriteLine( "No message in queue." );
         }

         // Else catch other sources of MessageQueueException.
         // Roll back the transaction.
         myTransaction->Abort();
      }

      // Catch other exceptions as necessary, such as 
      // InvalidOperationException, thrown when the formatter 
      // cannot deserialize the message.
      return;
   }
};

//*************************************************
// Provides an entry point into the application.
// 
// This example sends and receives a message from
// a transactional queue.
//*************************************************
int main()
{
   // Create a new instance of the class.
   MyNewQueue^ myNewQueue = gcnew MyNewQueue;

   // Send a message to a queue.
   myNewQueue->SendMessageTransactional();

   // Receive a message from a queue.
   myNewQueue->ReceiveMessageTransactional();
   return 0;
}
using System;
using System.Messaging;

namespace MyProject
{

    /// <summary>
    /// Provides a container class for the example.
    /// </summary>
    public class MyNewQueue
    {

        //**************************************************
        // Provides an entry point into the application.
        //
        // This example sends and receives a message from
        // a transactional queue.
        //**************************************************

        public static void Main()
        {
            // Create a new instance of the class.
            MyNewQueue myNewQueue = new MyNewQueue();

            // Send a message to a queue.
            myNewQueue.SendMessageTransactional();

            // Receive a message from a queue.
            myNewQueue.ReceiveMessageTransactional();

            return;
        }

        //**************************************************
        // Sends a message to a transactional queue.
        //**************************************************
        
        public void SendMessageTransactional()
        {
                        
            // Connect to a queue on the local computer.
            MessageQueue myQueue = new
                MessageQueue(".\\myTransactionalQueue");

            // Send a message to the queue.
            if (myQueue.Transactional == true)
            {
                // Create a transaction.
                MessageQueueTransaction myTransaction = new
                    MessageQueueTransaction();

                // Begin the transaction.
                myTransaction.Begin();

                // Send the message.
                myQueue.Send("My Message Data.", myTransaction);

                // Commit the transaction.
                myTransaction.Commit();
            }

            return;
        }

        //**************************************************
        // Receives a message from the transactional queue.
        //**************************************************
        
        public  void ReceiveMessageTransactional()
        {
            // Connect to a transactional queue on the local computer.
            MessageQueue myQueue = new
                MessageQueue(".\\myTransactionalQueue");

            // Set the formatter.
            myQueue.Formatter = new XmlMessageFormatter(new Type[]
                {typeof(String)});
            
            // Create a transaction.
            MessageQueueTransaction myTransaction = new
                MessageQueueTransaction();

            try
            {
                // Begin the transaction.
                myTransaction.Begin();
                
                // Receive the message.
                // Wait five seconds for a message to arrive.
                Message myMessage =	myQueue.Receive(new
                    TimeSpan(0,0,5), myTransaction);
                
                String myOrder = (String)myMessage.Body;

                // Display message information.
                Console.WriteLine(myOrder);

                // Commit the transaction.
                myTransaction.Commit();
            }
            
            catch (MessageQueueException e)
            {
                // Handle nontransactional queues.
                if (e.MessageQueueErrorCode ==
                    MessageQueueErrorCode.TransactionUsage)
                {
                    Console.WriteLine("Queue is not transactional.");
                }

                    // Handle no message arriving in the queue.
                else if (e.MessageQueueErrorCode ==
                    MessageQueueErrorCode.IOTimeout)
                {
                    Console.WriteLine("No message in queue.");
                }
                
                // Else catch other sources of MessageQueueException.

                // Roll back the transaction.
                myTransaction.Abort();
            }

            // Catch other exceptions as necessary, such as
            // InvalidOperationException, thrown when the formatter
            // cannot deserialize the message.

            return;
        }
    }
}
Imports System.Messaging

Namespace MyProj


   
    Public Class MyNewQueue


        '**************************************************
        ' Provides an entry point into the application.
        ' 
        ' This example sends and receives a message from
        ' a transactional queue.
        '**************************************************

        Public Shared Sub Main()

            ' Create a new instance of the class.
            Dim myNewQueue As New MyNewQueue

            ' Send a message to a queue.
            myNewQueue.SendMessageTransactional()

            ' Receive a message from a queue.
            myNewQueue.ReceiveMessageTransactional()

            Return

        End Sub


        '**************************************************
        ' Sends a message to a transactional queue.
        '**************************************************

        Public Sub SendMessageTransactional()

            ' Connect to a queue on the local computer.
            Dim myQueue As New MessageQueue(".\myTransactionalQueue")

            ' Send a message to the queue.
            If myQueue.Transactional = True Then

                ' Create a transaction.
                Dim myTransaction As New MessageQueueTransaction

                ' Begin the transaction.
                myTransaction.Begin()

                ' Send the message.
                myQueue.Send("My Message Data.", myTransaction)

                ' Commit the transaction.
                myTransaction.Commit()

            End If

            Return

        End Sub


        '**************************************************
        ' Receives a message from the transactional queue.
        '**************************************************

        Public Sub ReceiveMessageTransactional()

            ' Connect to a transactional queue on the local computer.
            Dim myQueue As New MessageQueue(".\myTransactionalQueue")

            ' Set the formatter.
            myQueue.Formatter = New XmlMessageFormatter(New Type() _
                {GetType([String])})

            ' Create a transaction.
            Dim myTransaction As New MessageQueueTransaction

            Try

                ' Begin the transaction.
                myTransaction.Begin()

                ' Receive the message. 
                ' Wait five seconds for a message to arrive. 
                Dim myMessage As Message = myQueue.Receive(New _
                    TimeSpan(0, 0, 5), myTransaction)
                Dim myOrder As [String] = CType(myMessage.Body, _
                    [String])

                ' Display message information.
                Console.WriteLine(myOrder)

                ' Commit the transaction.
                myTransaction.Commit()


            Catch e As MessageQueueException

                ' Handle nontransactional queues.
                If e.MessageQueueErrorCode = _
                    MessageQueueErrorCode.TransactionUsage Then

                    Console.WriteLine("Queue is not transactional.")

                Else
                    ' Handle no message arriving in the queue.
                    If e.MessageQueueErrorCode = _
                        MessageQueueErrorCode.IOTimeout Then

                        Console.WriteLine("No message in queue.")

                    End If
                End If

                ' Else catch other sources of a MessageQueueException.

                ' Roll back the transaction.
                myTransaction.Abort()


                ' Catch other exceptions as necessary, such as InvalidOperationException,
                ' thrown when the formatter cannot deserialize the message.

            End Try

            Return

        End Sub

    End Class
End Namespace 'MyProj

설명

이 오버로드를 사용하여 매개 변수로 정의된 내부 트랜잭션 컨텍스트를 사용하여 트랜잭션 큐에서 메시지를 수신하고 큐에 transaction 메시지가 없는 경우 지정된 기간 내에 반환합니다.

메서드를 Receive 사용하면 메시지를 동기적으로 읽을 수 있으므로 큐에서 메시지를 제거할 수 있습니다. 에 대한 Receive 후속 호출은 큐에 오는 메시지를 반환합니다.

이 메서드는 트랜잭션 큐에서 호출되므로 트랜잭션이 중단되면 수신된 메시지가 큐로 반환됩니다. 트랜잭션이 커밋될 때까지 메시지는 큐에서 영구적으로 제거되지 않습니다.

큐에서 메시지를 제거하지 않고 큐의 첫 번째 메시지를 읽으려면 메서드를 Peek 사용합니다. 메서드는 Peek 항상 큐에서 첫 번째 메시지를 반환하므로 우선 순위가 높은 메시지가 큐에 도착하지 않는 한 메서드에 대한 후속 호출은 동일한 메시지를 반환합니다. 에 대한 호출 Peek에서 반환된 메시지와 연결된 트랜잭션 컨텍스트가 없습니다. Peek 큐에서 메시지를 제거하지 않으므로 에 대한 호출Abort로 롤백할 필요가 없습니다.

메시지가 큐에 Receive 도착할 때까지 기다리는 동안 현재 스레드가 차단될 수 있는 경우 호출을 사용합니다. 스레드는 지정된 기간 동안 차단되거나 매개 변수의 값을 InfiniteTimeouttimeout 지정한 경우 무기한 차단됩니다. 애플리케이션 처리 메시지를 기다리지 않고 계속 해야 하는 경우 비동기 메서드를 사용 하 여 고려해 야 BeginReceive합니다.

다음 표에서는 이 메서드를 다양한 작업 그룹 모드에서 사용할 수 있는지 여부를 보여 줍니다.

작업 그룹 모드 사용 가능
수집 Yes
로컬 컴퓨터 및 직접 형식 이름 Yes
원격 컴퓨터 No
원격 컴퓨터 및 직접 형식 이름 Yes

추가 정보

적용 대상

Receive(TimeSpan, MessageQueueTransactionType)

MessageQueue가 참조하는 큐에서 사용할 수 있는 첫 번째 메시지를 받습니다. 이 호출은 동기적이므로 큐에 메시지를 사용할 수 있거나 제한 시간이 만료될 때까지 대기합니다.

public:
 System::Messaging::Message ^ Receive(TimeSpan timeout, System::Messaging::MessageQueueTransactionType transactionType);
public System.Messaging.Message Receive (TimeSpan timeout, System.Messaging.MessageQueueTransactionType transactionType);
member this.Receive : TimeSpan * System.Messaging.MessageQueueTransactionType -> System.Messaging.Message
Public Function Receive (timeout As TimeSpan, transactionType As MessageQueueTransactionType) As Message

매개 변수

timeout
TimeSpan

새 메시지를 검사할 수 있을 때까지 기다리는 시간을 나타내는 TimeSpan입니다.

transactionType
MessageQueueTransactionType

MessageQueueTransactionType 값 중 하나로, 메시지와 연결할 트랜잭션 컨텍스트 형식을 설명합니다.

반환

큐에서 사용할 수 있는 첫 번째 메시지를 참조하는 Message를 반환합니다.

예외

timeout 매개 변수에 지정된 값이 잘못된 경우. timeoutZero보다 작거나 InfiniteTimeout보다 클 수 있습니다.

transactionType 매개 변수가 MessageQueueTransactionType 멤버 중 하나가 아닌 경우

제한 시간이 만료되기 전에 큐에 메시지가 도착하지 않았습니다.

또는

메시지 큐 메서드에 액세스하는 동안 오류가 발생한 경우

예제

다음 코드 예제에서는이 메서드를 사용 하는 방법을 보여 줍니다.


// Connect to a transactional queue on the local computer.
MessageQueue^ queue = gcnew MessageQueue(".\\exampleTransQueue");

// Create a new message.
Message^ msg = gcnew Message("Example Message Body");

// Send the message.
queue->Send(msg, MessageQueueTransactionType::Single);

// Set the formatter to indicate the message body contains a String.
queue->Formatter = gcnew XmlMessageFormatter(
    gcnew array<Type^>{String::typeid});

// Receive the message from the queue. Because the Id of the message
// is not specified, it might not be the message just sent.
msg = queue->Receive(TimeSpan::FromSeconds(10.0),
    MessageQueueTransactionType::Single);

queue->Close();

// Connect to a transactional queue on the local computer.
MessageQueue queue = new MessageQueue(".\\exampleTransQueue");

// Create a new message.
Message msg = new Message("Example Message Body");

// Send the message.
queue.Send(msg, MessageQueueTransactionType.Single);

// Set the formatter to indicate the message body contains a String.
queue.Formatter = new XmlMessageFormatter(new Type[]
    {typeof(String)});

// Receive the message from the queue. Because the Id of the message
// is not specified, it might not be the message just sent.
msg = queue.Receive(TimeSpan.FromSeconds(10.0),
    MessageQueueTransactionType.Single);

설명

이 오버로드를 사용하여 매개 변수로 정의된 transactionType 트랜잭션 컨텍스트를 사용하여 큐에서 메시지를 수신하고 큐에 메시지가 없는 경우 지정된 기간 동안 반환합니다.

메시지를 수신하는 transactionType 데 사용할 스레드에 연결된 외부 트랜잭션 컨텍스트가 이미 있는 경우 매개 변수를 지정 Automatic 합니다. Single 메시지를 단일 내부 트랜잭션으로 받을지 지정합니다. 트랜잭션 컨텍스트 외부의 트랜잭션 큐에서 메시지를 받을지 지정할 수 있습니다 None .

메서드를 Receive 사용하면 메시지를 동기적으로 읽을 수 있으므로 큐에서 메시지를 제거할 수 있습니다. 에 대한 Receive 후속 호출은 큐에 오는 메시지를 반환합니다.

트랜잭션 큐에서 메시지를 수신하기 위해 이 메서드를 호출하면 트랜잭션이 중단된 경우 수신된 메시지가 큐로 반환됩니다. 트랜잭션이 커밋될 때까지 메시지는 큐에서 영구적으로 제거되지 않습니다.

큐에서 메시지를 제거하지 않고 큐의 첫 번째 메시지를 읽으려면 메서드를 Peek 사용합니다. 메서드는 Peek 항상 큐에서 첫 번째 메시지를 반환하므로 우선 순위가 높은 메시지가 큐에 도착하지 않는 한 메서드에 대한 후속 호출은 동일한 메시지를 반환합니다. 에 대한 호출 Peek에서 반환된 메시지와 연결된 트랜잭션 컨텍스트가 없습니다. Peek 큐에서 메시지를 제거하지 않으므로 에 대한 호출Abort로 롤백할 필요가 없습니다.

메시지가 큐에 Receive 도착할 때까지 기다리는 동안 현재 스레드가 차단될 수 있는 경우 호출을 사용합니다. 스레드는 지정된 기간 동안 차단되거나 매개 변수의 값을 InfiniteTimeouttimeout 지정한 경우 무기한 차단됩니다. 애플리케이션 처리 메시지를 기다리지 않고 계속 해야 하는 경우 비동기 메서드를 사용 하 여 고려해 야 BeginReceive합니다.

다음 표에서는 이 메서드를 다양한 작업 그룹 모드에서 사용할 수 있는지 여부를 보여 줍니다.

작업 그룹 모드 사용 가능
수집 Yes
로컬 컴퓨터 및 직접 형식 이름 Yes
원격 컴퓨터 No
원격 컴퓨터 및 직접 형식 이름 Yes

추가 정보

적용 대상

Receive(TimeSpan, Cursor, MessageQueueTransaction)

지정된 커서를 사용하여 큐에 있는 현재 메시지를 받습니다. 사용할 수 있는 메시지가 없는 경우 이 메서드는 메시지를 사용할 수 있거나 시간 제한이 만료될 때까지 대기합니다.

public:
 System::Messaging::Message ^ Receive(TimeSpan timeout, System::Messaging::Cursor ^ cursor, System::Messaging::MessageQueueTransaction ^ transaction);
public System.Messaging.Message Receive (TimeSpan timeout, System.Messaging.Cursor cursor, System.Messaging.MessageQueueTransaction transaction);
member this.Receive : TimeSpan * System.Messaging.Cursor * System.Messaging.MessageQueueTransaction -> System.Messaging.Message
Public Function Receive (timeout As TimeSpan, cursor As Cursor, transaction As MessageQueueTransaction) As Message

매개 변수

timeout
TimeSpan

새 메시지를 검사할 수 있을 때까지 기다리는 시간을 나타내는 TimeSpan입니다.

cursor
Cursor

메시지 큐에서 특정 위치를 유지하는 Cursor입니다.

반환

큐에 있는 메시지를 참조하는 Message입니다.

예외

cursor 매개 변수가 null인 경우

또는

transaction 매개 변수가 null인 경우

timeout 매개 변수에 지정된 값이 잘못된 경우 timeoutZero보다 작거나 InfiniteTimeout보다 클 수 있습니다.

제한 시간이 만료되기 전에 큐에 메시지가 도착하지 않았습니다.

또는

비트랜잭션 큐입니다.

또는

메시지 큐 메서드에 액세스하는 동안 오류가 발생한 경우

설명

이 오버로드를 사용하여 매개 변수로 정의된 내부 트랜잭션 컨텍스트를 사용하여 트랜잭션 큐에서 메시지를 수신하고 큐에 transaction 메시지가 없는 경우 지정된 기간 내에 반환합니다.

메서드를 Receive 사용하면 메시지를 동기적으로 읽을 수 있으므로 큐에서 메시지를 제거할 수 있습니다. 큐에 오는 메시지를 반환하기 위한 Receive 후속 호출입니다.

이 메서드는 트랜잭션 큐에서 호출되므로 트랜잭션이 중단되면 수신된 메시지가 큐로 반환됩니다. 트랜잭션이 커밋될 때까지 메시지는 큐에서 영구적으로 제거되지 않습니다.

큐에서 메시지를 제거하지 않고 큐에서 메시지를 읽으려면 메서드를 Peek 사용합니다. 에 대한 호출 Peek에서 반환된 메시지와 연결된 트랜잭션 컨텍스트가 없습니다. Peek 큐에서 메시지를 제거하지 않으므로 를 호출Abort하여 롤백할 것이 없습니다.

메시지가 큐에 Receive 도착할 때까지 기다리는 동안 현재 스레드가 차단될 수 있는 경우 호출을 사용합니다. 스레드는 지정된 기간 동안 차단되거나 매개 변수의 값을 InfiniteTimeouttimeout 지정한 경우 무기한 차단됩니다. 애플리케이션 처리 메시지를 기다리지 않고 계속 해야 하는 경우 비동기 메서드를 사용 하 여 고려해 야 BeginReceive합니다.

다음 표에서는 이 메서드를 다양한 작업 그룹 모드에서 사용할 수 있는지 여부를 보여 줍니다.

작업 그룹 모드 사용 가능
수집 Yes
로컬 컴퓨터 및 직접 형식 이름 Yes
원격 컴퓨터 No
원격 컴퓨터 및 직접 형식 이름 Yes

추가 정보

적용 대상

Receive(TimeSpan, Cursor, MessageQueueTransactionType)

지정된 커서를 사용하여 큐에 있는 현재 메시지를 받습니다. 사용할 수 있는 메시지가 없는 경우 이 메서드는 메시지를 사용할 수 있거나 시간 제한이 만료될 때까지 대기합니다.

public:
 System::Messaging::Message ^ Receive(TimeSpan timeout, System::Messaging::Cursor ^ cursor, System::Messaging::MessageQueueTransactionType transactionType);
public System.Messaging.Message Receive (TimeSpan timeout, System.Messaging.Cursor cursor, System.Messaging.MessageQueueTransactionType transactionType);
member this.Receive : TimeSpan * System.Messaging.Cursor * System.Messaging.MessageQueueTransactionType -> System.Messaging.Message
Public Function Receive (timeout As TimeSpan, cursor As Cursor, transactionType As MessageQueueTransactionType) As Message

매개 변수

timeout
TimeSpan

새 메시지를 검사할 수 있을 때까지 기다리는 시간을 나타내는 TimeSpan입니다.

cursor
Cursor

메시지 큐에서 특정 위치를 유지하는 Cursor입니다.

transactionType
MessageQueueTransactionType

메시지와 연결할 트랜잭션 컨텍스트 형식을 설명하는 MessageQueueTransactionType 값 중 하나입니다.

반환

큐에 있는 메시지를 참조하는 Message입니다.

예외

cursor 매개 변수가 null인 경우

timeout 매개 변수에 지정된 값이 잘못된 경우 timeoutZero보다 작거나 InfiniteTimeout보다 클 수 있습니다.

transactionType 매개 변수가 MessageQueueTransactionType 멤버 중 하나가 아닌 경우

제한 시간이 만료되기 전에 큐에 메시지가 도착하지 않았습니다.

또는

메시지 큐 메서드에 액세스하는 동안 오류가 발생한 경우

설명

이 오버로드를 사용하여 매개 변수로 정의된 transactionType 트랜잭션 컨텍스트를 사용하여 큐에서 메시지를 수신하고 큐에 메시지가 없는 경우 지정된 기간 동안 반환합니다.

메시지를 수신하는 transactionType 데 사용할 스레드에 연결된 외부 트랜잭션 컨텍스트가 이미 있는 경우 매개 변수를 지정 Automatic 합니다. Single 메시지를 단일 내부 트랜잭션으로 받을지 지정합니다. 트랜잭션 컨텍스트 외부의 트랜잭션 큐에서 메시지를 받을지 지정할 수 있습니다 None .

메서드를 Receive 사용하면 메시지를 동기적으로 읽을 수 있으므로 큐에서 메시지를 제거할 수 있습니다. 큐에 오는 메시지를 반환하기 위한 Receive 후속 호출입니다.

트랜잭션 큐에서 메시지를 수신하기 위해 이 메서드를 호출하면 트랜잭션이 중단된 경우 수신된 메시지가 큐로 반환됩니다. 트랜잭션이 커밋될 때까지 메시지는 큐에서 영구적으로 제거되지 않습니다.

큐에서 메시지를 제거하지 않고 큐에서 메시지를 읽으려면 메서드를 Peek 사용합니다. 에 대한 호출 Peek에서 반환된 메시지와 연결된 트랜잭션 컨텍스트가 없습니다. Peek 큐에서 메시지를 제거하지 않으므로 를 호출Abort하여 롤백할 것이 없습니다.

메시지가 큐에 Receive 도착할 때까지 기다리는 동안 현재 스레드가 차단될 수 있는 경우 호출을 사용합니다. 스레드는 지정된 기간 동안 차단되거나 매개 변수의 값을 InfiniteTimeouttimeout 지정한 경우 무기한 차단됩니다. 애플리케이션 처리 메시지를 기다리지 않고 계속 해야 하는 경우 비동기 메서드를 사용 하 여 고려해 야 BeginReceive합니다.

다음 표에서는 이 메서드를 다양한 작업 그룹 모드에서 사용할 수 있는지 여부를 보여 줍니다.

작업 그룹 모드 사용 가능
수집 Yes
로컬 컴퓨터 및 직접 형식 이름 Yes
원격 컴퓨터 No
원격 컴퓨터 및 직접 형식 이름 Yes

추가 정보

적용 대상

스레드 보안

메서드는 스레드로부터 안전하지 않습니다.