MessageQueue.Receive 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
큐에서 첫 번째 메시지를 수신하여 큐에서 제거합니다.
오버로드
| Name | Description |
|---|---|
| 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 큐에서 사용할 수 있는 첫 번째 메시지를 참조하는 A입니다.
예외
메시지 큐 메서드에 액세스할 때 오류가 발생했습니다.
예제
다음 코드 예제에서는 큐에서 메시지를 수신 하 고 화면에 해당 메시지에 대 한 정보를 출력 합니다.
#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
매개 변수
- transaction
- MessageQueueTransaction
반품
Message 큐에서 사용할 수 있는 첫 번째 메시지를 참조하는 A입니다.
예외
예제
다음 코드 예제에서는 로컬 컴퓨터의 트랜잭션 큐에 연결 하 고 큐에 메시지를 보냅니다. 그런 다음 주문이 포함된 메시지를 받습니다. 비트랜잭션 큐가 발견되면 트랜잭션을 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 )
{
// 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)
{
// 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 큐에서 사용할 수 있는 첫 번째 메시지를 참조하는 A입니다.
예외
메시지 큐 메서드에 액세스할 때 오류가 발생했습니다.
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 메시지가 있을 때까지 기다립니다.
Automatic 메시지를 받는 데 사용할 스레드에 연결된 외부 트랜잭션 컨텍스트가 이미 있는 경우 매개 변수를 지정 transactionType 합니다.
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
매개 변수
반품
Message 큐에서 사용할 수 있는 첫 번째 메시지를 참조하는 A입니다.
예외
매개 변수에 timeout 지정된 값이 잘못 timeoutZeroInfiniteTimeout되었습니다.
예제
다음 코드 예제에서는 큐에서 메시지를 수신 하 고 화면에 해당 메시지에 대 한 정보를 출력 합니다. 이 예제에서는 큐에 메시지가 도착할 때까지 기다리는 동안 최대 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
매개 변수
반품
Message 큐에서 사용할 수 있는 첫 번째 메시지를 참조하는 A입니다.
예외
매개 변수에 timeout 지정된 값이 잘못 timeoutZeroInfiniteTimeout되었습니다.
제한 시간이 만료되기 전에 메시지가 큐에 도착하지 않았습니다.
-또는-
메시지 큐 메서드에 액세스할 때 오류가 발생했습니다.
이 오버로드를 사용하여 메시지를 수신하고 큐에 메시지가 없는 경우 지정된 기간 동안 반환합니다.
적용 대상
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
매개 변수
- transaction
- MessageQueueTransaction
반품
Message 큐에서 사용할 수 있는 첫 번째 메시지를 참조하는 A입니다.
예외
매개 변수에 timeout 지정된 값이 잘못 timeoutZeroInfiniteTimeout되었습니다.
제한 시간이 만료되기 전에 메시지가 큐에 도착하지 않았습니다.
-또는-
큐가 트랜잭션이 아닌 경우
-또는-
메시지 큐 메서드에 액세스할 때 오류가 발생했습니다.
예제
다음 코드 예제에서는이 메서드의 사용을 보여 줍니다.
#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)
{
// 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)
{
// 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
매개 변수
- transactionType
- MessageQueueTransactionType
MessageQueueTransactionType 메시지와 연결할 트랜잭션 컨텍스트의 형식을 설명하는 값 중 하나입니다.
반품
Message 큐에서 사용할 수 있는 첫 번째 메시지를 참조하는 A입니다.
예외
매개 변수에 timeout 지정된 값이 잘못 timeoutZeroInfiniteTimeout되었습니다.
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 트랜잭션 컨텍스트를 사용하여 큐에서 메시지를 수신하고 큐에 메시지가 없는 경우 지정된 기간 동안 반환합니다.
Automatic 메시지를 받는 데 사용할 스레드에 연결된 외부 트랜잭션 컨텍스트가 이미 있는 경우 매개 변수를 지정 transactionType 합니다.
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
매개 변수
- transaction
- MessageQueueTransaction
반품
Message 큐의 메시지를 참조하는 A.
예외
timeout 매개 변수에 지정된 값이 잘못되었습니다. 이 timeout 보다 Zero 작거나 클 수 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
매개 변수
- transactionType
- MessageQueueTransactionType
MessageQueueTransactionType 메시지와 연결할 트랜잭션 컨텍스트의 형식을 설명하는 값 중 하나입니다.
반품
Message 큐의 메시지를 참조하는 A.
예외
매개 변수는 cursor .입니다 null.
timeout 매개 변수에 지정된 값이 잘못되었습니다. 이 timeout 보다 Zero 작거나 클 수 InfiniteTimeout있습니다.
transactionType 매개 변수가 멤버 중 MessageQueueTransactionType 하나가 아닙니다.
설명
이 오버로드를 사용하여 매개 변수에 정의된 transactionType 트랜잭션 컨텍스트를 사용하여 큐에서 메시지를 수신하고 큐에 메시지가 없는 경우 지정된 기간 동안 반환합니다.
Automatic 메시지를 받는 데 사용할 스레드에 연결된 외부 트랜잭션 컨텍스트가 이미 있는 경우 매개 변수를 지정 transactionType 합니다.
Single 메시지를 단일 내부 트랜잭션으로 받을지 지정합니다. 트랜잭션 컨텍스트 외부의 트랜잭션 큐에서 메시지를 받을 것인지 지정할 None 수 있습니다.
이 Receive 메서드를 사용하면 메시지를 동기식으로 읽을 수 있으므로 큐에서 메시지를 제거할 수 있습니다. 큐에서 이어지는 메시지를 반환하기 위한 Receive 후속 호출입니다.
트랜잭션 큐에서 메시지를 수신하기 위해 이 메서드를 호출하면 트랜잭션이 중단된 경우 수신된 메시지가 큐로 반환됩니다. 트랜잭션이 커밋될 때까지 메시지는 큐에서 영구적으로 제거되지 않습니다.
큐에서 메시지를 제거하지 않고 큐에서 메시지를 읽으려면 이 메서드를 Peek 사용합니다. 호출 Peek에서 반환된 메시지와 연결된 트랜잭션 컨텍스트가 없습니다. Peek 큐에서 메시지를 제거하지 않으므로 호출Abort을 통해 롤백할 항목이 없습니다.
메시지가 큐에 Receive 도착할 때까지 기다리는 동안 현재 스레드가 차단되는 것이 허용되는 경우 호출을 사용합니다. 스레드는 지정된 기간 동안 차단되거나 매개 변수 값을 지정한 경우 무기한으로 차단됩니다 InfiniteTimeouttimeout . 메시지를 기다리지 않고 애플리케이션 처리를 계속해야 하는 경우 비동기 메서드 BeginReceive를 사용하는 것이 좋습니다.
다음 표에서는 이 메서드를 다양한 작업 그룹 모드에서 사용할 수 있는지 여부를 보여 줍니다.
| 작업 그룹 모드 | 사용 가능 |
|---|---|
| 로컬 컴퓨터 | Yes |
| 로컬 컴퓨터 및 직접 형식 이름 | Yes |
| 원격 컴퓨터 | No |
| 원격 컴퓨터 및 직접 형식 이름 | Yes |
추가 정보
적용 대상
스레드 보안
이 메서드는 스레드로부터 안전하지 않습니다.