MessageQueue.ReceiveById 메서드

정의

주어진 식별자를 갖는 메시지를 받고, 큐에서 제거합니다.

오버로드

ReceiveById(String)

주어진 식별자를 갖는 메시지를 비트랜잭션 큐로부터 받습니다. 지정된 식별자가 들어 있는 메시지가 큐에 현재 없는 경우에는 바로 예외가 발생합니다.

ReceiveById(String, MessageQueueTransaction)

주어진 식별자를 갖는 메시지를 트랜잭션 큐로부터 받습니다. 지정된 식별자가 포함된 메시지가 큐에 현재 없는 경우에는 바로 예외가 발생합니다.

ReceiveById(String, MessageQueueTransactionType)

주어진 식별자를 갖는 메시지를 받습니다. 지정된 식별자가 포함된 메시지가 큐에 현재 없는 경우에는 바로 예외가 발생합니다.

ReceiveById(String, TimeSpan)

주어진 식별자를 갖는 메시지를 비트랜잭션 큐로부터 받고, 지정된 식별자가 포함된 메시지를 큐에서 사용할 수 있거나 제한 시간이 만료될 때까지 대기합니다.

ReceiveById(String, TimeSpan, MessageQueueTransaction)

주어진 식별자를 갖는 메시지를 트랜잭션 큐로부터 받고, 지정된 식별자가 포함된 메시지를 큐에서 사용할 수 있거나 제한 시간이 만료될 때까지 대기합니다.

ReceiveById(String, TimeSpan, MessageQueueTransactionType)

주어진 식별자를 갖는 메시지를 받고, 지정된 식별자가 포함된 메시지를 큐에서 사용할 수 있거나 제한 시간이 만료될 때까지 대기합니다.

ReceiveById(String)

주어진 식별자를 갖는 메시지를 비트랜잭션 큐로부터 받습니다. 지정된 식별자가 들어 있는 메시지가 큐에 현재 없는 경우에는 바로 예외가 발생합니다.

public:
 System::Messaging::Message ^ ReceiveById(System::String ^ id);
public System.Messaging.Message ReceiveById (string id);
member this.ReceiveById : string -> System.Messaging.Message
Public Function ReceiveById (id As String) As Message

매개 변수

id
String

받을 메시지의 Id입니다.

반환

전달된 id 매개 변수와 Message 속성이 일치하는 Id를 반환합니다.

예외

id 매개 변수가 null인 경우

지정된 id의 메시지를 찾을 수 없는 경우

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

예제

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


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

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

// Send the message.
queue->Send(msg, "Example Message Label");

// Get the message's Id property value.
String^ id = msg->Id;

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

// Receive the message from the queue.
msg = queue->ReceiveById(id);

queue->Close();

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

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

// Send the message.
queue.Send(msg, "Example Message Label");

// Get the message's Id property value.
string id = msg.Id;

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

// Receive the message from the queue.
msg = queue.ReceiveById(id);

설명

이 메서드를 사용하여 알려진 식별자가 있는 메시지를 읽고 큐에서 제거합니다. 이 메서드는 메시지가 큐에 없는 경우 즉시 예외를 throw합니다.

메시지의 속성은 Id 메시지 큐 엔터프라이즈에서 고유하므로 큐에 지정된 id 매개 변수와 일치하는 최대 하나의 메시지가 있습니다.

다른 두 가지 메서드를 사용하면 큐에서 메시지를 받을 수 있습니다. 합니다 Receive 큐의 첫 번째 메시지를 반환 하는 메서드 및 ReceiveByCorrelationId(String) 메서드는 승인, 보고서 또는 큐로 보낸 메시지의 결과로 생성 된 애플리케이션에서 생성 한 응답 메시지를 검색 하는 합니다.

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

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

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

추가 정보

적용 대상

ReceiveById(String, MessageQueueTransaction)

주어진 식별자를 갖는 메시지를 트랜잭션 큐로부터 받습니다. 지정된 식별자가 포함된 메시지가 큐에 현재 없는 경우에는 바로 예외가 발생합니다.

public:
 System::Messaging::Message ^ ReceiveById(System::String ^ id, System::Messaging::MessageQueueTransaction ^ transaction);
public System.Messaging.Message ReceiveById (string id, System.Messaging.MessageQueueTransaction transaction);
member this.ReceiveById : string * System.Messaging.MessageQueueTransaction -> System.Messaging.Message
Public Function ReceiveById (id As String, transaction As MessageQueueTransaction) As Message

매개 변수

id
String

받을 메시지의 Id입니다.

반환

전달된 id 매개 변수와 Message 속성이 일치하는 Id를 반환합니다.

예외

id 매개 변수가 null인 경우

또는

transaction 매개 변수가 null인 경우

지정된 id의 메시지를 찾을 수 없는 경우

비트랜잭션 큐입니다.

또는

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

예제

다음 코드 예제에서는 ReceiveById(String, MessageQueueTransaction)의 사용법을 보여줍니다.


// 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, "Example Message Label",
    MessageQueueTransactionType::Single);

// Get the message's Id property value.
String^ id = msg->Id;

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

// Create a message queuing transaction.
MessageQueueTransaction^ transaction = gcnew MessageQueueTransaction();

try
{
    // Begin a transaction.
    transaction->Begin();

    // Receive the message from the queue.
    msg = queue->ReceiveById(id, transaction);

    // Commit the transaction.
    transaction->Commit();
}
catch (Exception^ ex)
{
    // Cancel the transaction.
    transaction->Abort();

    // Propagate the exception.
    throw ex;
}
finally
{
    // Dispose of the transaction object.
    delete transaction;
    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, "Example Message Label",
    MessageQueueTransactionType.Single);

// Get the message's Id property value.
string id = msg.Id;

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

// Create a message queuing transaction.
MessageQueueTransaction transaction = new MessageQueueTransaction();

try
{
    // Begin a transaction.
    transaction.Begin();

    // Receive the message from the queue.
    msg = queue.ReceiveById(id, transaction);

    // Commit the transaction.
    transaction.Commit();
}
catch(System.Exception e)
{
    // Cancel the transaction.
    transaction.Abort();

    // Propagate the exception.
    throw e;
}
finally
{
    // Dispose of the transaction object.
    transaction.Dispose();
}

설명

이 메서드를 사용하여 알려진 식별자가 있는 메시지를 읽고 매개 변수로 정의된 transaction 내부 트랜잭션 컨텍스트를 사용하여 큐에서 제거합니다. 메시지가 큐에 없는 경우 이 메서드는 즉시 예외를 throw합니다.

메시지의 속성은 Id 메시지 큐 엔터프라이즈에서 고유하므로 큐에 지정된 id 매개 변수와 일치하는 최대 하나의 메시지가 있습니다.

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

다른 두 가지 메서드를 사용하면 큐에서 메시지를 받을 수 있습니다. 합니다 Receive 큐의 첫 번째 메시지를 반환 하는 메서드 및 ReceiveByCorrelationId(String) 메서드는 승인, 보고서 또는 큐로 보낸 메시지의 결과로 생성 된 애플리케이션에서 생성 한 응답 메시지를 검색 하는 합니다.

지정된 식별자가 있는 메시지를 큐에서 제거하지 않고 읽으려면 메서드를 PeekById(String) 사용합니다. 메서드는 PeekById(String) 항상 큐에서 첫 번째 메시지를 반환하므로 우선 순위가 높은 메시지가 큐에 도착하지 않는 한 메서드에 대한 후속 호출은 동일한 메시지를 반환합니다. 에 대한 호출 PeekById(String)에서 반환된 메시지와 연결된 트랜잭션 컨텍스트가 없습니다. 는 PeekById(String) 큐에서 메시지를 제거하지 않으므로 트랜잭션이 중단된 경우 롤백할 것이 없습니다.

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

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

추가 정보

적용 대상

ReceiveById(String, MessageQueueTransactionType)

주어진 식별자를 갖는 메시지를 받습니다. 지정된 식별자가 포함된 메시지가 큐에 현재 없는 경우에는 바로 예외가 발생합니다.

public:
 System::Messaging::Message ^ ReceiveById(System::String ^ id, System::Messaging::MessageQueueTransactionType transactionType);
public System.Messaging.Message ReceiveById (string id, System.Messaging.MessageQueueTransactionType transactionType);
member this.ReceiveById : string * System.Messaging.MessageQueueTransactionType -> System.Messaging.Message
Public Function ReceiveById (id As String, transactionType As MessageQueueTransactionType) As Message

매개 변수

id
String

받을 메시지의 Id입니다.

transactionType
MessageQueueTransactionType

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

반환

전달된 id 매개 변수와 Message 속성이 일치하는 Id를 반환합니다.

예외

id 매개 변수가 null인 경우

지정된 id의 메시지를 찾을 수 없는 경우

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

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

예제

다음 코드 예제에서는 ReceiveById(String, 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, "Example Message Label",
    MessageQueueTransactionType::Single);

// Get the message's Id property value.
String^ id = msg->Id;

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

// Receive the message from the queue.
msg = queue->ReceiveById(id, 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, "Example Message Label",
    MessageQueueTransactionType.Single);

// Get the message's Id property value.
string id = msg.Id;

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

// Receive the message from the queue.
msg = queue.ReceiveById(id, MessageQueueTransactionType.Single);

설명

이 메서드를 사용하여 알려진 식별자가 있는 메시지를 읽고 큐에서 제거합니다. 이 메서드는 메시지가 큐에 없는 경우 즉시 예외를 throw합니다. 메시지 큐에서 제거 되 고 정의한 트랜잭션 컨텍스트를 사용 하 여 애플리케이션에 반환 되는 고, 그렇지는 transactionType 매개 변수입니다.

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

메시지의 속성은 Id 메시지 큐 엔터프라이즈에서 고유하므로 큐에 지정된 id 매개 변수와 일치하는 최대 하나의 메시지가 있습니다. 지정된 식별자가 있는 메시지가 이 MessageQueue instance 연결된 메시지 이외의 큐에 있으면 메시지를 찾을 수 없습니다.

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

다른 두 가지 메서드를 사용하면 큐에서 메시지를 받을 수 있습니다. 합니다 Receive 큐의 첫 번째 메시지를 반환 하는 메서드 및 ReceiveByCorrelationId(String) 메서드는 승인, 보고서 또는 큐로 보낸 메시지의 결과로 생성 된 애플리케이션에서 생성 한 응답 메시지를 검색 하는 합니다.

지정된 식별자가 있는 메시지를 큐에서 제거하지 않고 읽으려면 메서드를 PeekById(String) 사용합니다. 메서드는 PeekById(String) 항상 큐에서 첫 번째 메시지를 반환하므로 우선 순위가 높은 메시지가 큐에 도착하지 않는 한 메서드에 대한 후속 호출은 동일한 메시지를 반환합니다. 에 대한 호출 PeekById(String)에서 반환된 메시지와 연결된 트랜잭션 컨텍스트가 없습니다. 는 PeekById(String) 큐에서 메시지를 제거하지 않으므로 트랜잭션이 중단된 경우 롤백할 것이 없습니다.

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

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

추가 정보

적용 대상

ReceiveById(String, TimeSpan)

주어진 식별자를 갖는 메시지를 비트랜잭션 큐로부터 받고, 지정된 식별자가 포함된 메시지를 큐에서 사용할 수 있거나 제한 시간이 만료될 때까지 대기합니다.

public:
 System::Messaging::Message ^ ReceiveById(System::String ^ id, TimeSpan timeout);
public System.Messaging.Message ReceiveById (string id, TimeSpan timeout);
member this.ReceiveById : string * TimeSpan -> System.Messaging.Message
Public Function ReceiveById (id As String, timeout As TimeSpan) As Message

매개 변수

id
String

받을 메시지의 Id입니다.

timeout
TimeSpan

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

반환

전달된 id 매개 변수와 Message 속성이 일치하는 Id를 반환합니다.

예외

id 매개 변수가 null인 경우

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

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

또는

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

예제

다음 코드 예제에서는 ReceiveById(String, TimeSpan)의 사용법을 보여줍니다.


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

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

// Send the message.
queue->Send(msg, "Example Message Label");

// Get the message's Id property value.
String^ id = msg->Id;

// Receive the message from the queue.
msg = queue->ReceiveById(id, TimeSpan::FromSeconds(10.0));

queue->Close();

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

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

// Send the message.
queue.Send(msg, "Example Message Label");

// Get the message's Id property value.
string id = msg.Id;

// Receive the message from the queue.
msg = queue.ReceiveById(id, TimeSpan.FromSeconds(10.0));

설명

이 메서드를 사용하여 알려진 식별자가 있는 메시지를 읽고 큐에서 제거합니다. 매개 변수로 지정된 id 식별자가 있는 메시지가 큐에 있는 경우 이 메서드는 즉시 를 반환합니다. 그렇지 않으면 메서드는 지정된 기간 동안 새 메시지가 도착할 때까지 기다립니다. 제한 시간이 만료되기 전에 새 메시지가 도착하지 않으면 예외가 throw됩니다.

매개 변수는 timeout 이 메서드의 총 실행 시간을 지정하지 않습니다. 대신 새 메시지가 큐에 도착할 때까지 기다리는 시간을 지정합니다. 새 메시지가 도착할 때마다 이 메서드는 Id 새 메시지의 를 검사하여 매개 변수와 id 일치하는지 확인합니다. 그렇지 않은 경우 이 메서드는 시간 제한 기간을 시작하고 다른 새 메시지가 도착할 때까지 기다립니다. 따라서 새 메시지가 제한 시간 내에 계속 도착하는 경우 이 메서드는 새 메시지가 도착하지 않고 제한 시간이 만료될 때까지 또는 매개 변수와 일치하는 id 메시지가 도착할 때까지 무기한 실행을 계속할 수 있습니다Id.

메시지의 속성은 Id 메시지 큐 엔터프라이즈에서 고유하므로 큐에 지정된 id 매개 변수와 일치하는 최대 하나의 메시지가 있습니다.

매개 변수에 지정된 제한 시간 내에 새 메시지가 큐에 계속 도착하는 한 현재 스레드가 차단되는 것이 허용되는 경우 이 오버로드 ReceiveById(String)timeout 사용합니다. 스레드는 지정된 기간 이상 또는 매개 변수 값을 지정 InfiniteTimeouttimeout 한 경우 또는 새 메시지가 매개 변수에 지정된 제한 시간 내에 큐에 계속 도착하는 경우 무기한으로 차단됩니다 timeout .

다른 두 가지 메서드를 사용하면 큐에서 메시지를 받을 수 있습니다. 합니다 Receive 큐의 첫 번째 메시지를 반환 하는 메서드 및 ReceiveByCorrelationId(String) 메서드는 승인, 보고서 또는 큐로 보낸 메시지의 결과로 생성 된 애플리케이션에서 생성 한 응답 메시지를 검색 하는 합니다.

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

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

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

추가 정보

적용 대상

ReceiveById(String, TimeSpan, MessageQueueTransaction)

주어진 식별자를 갖는 메시지를 트랜잭션 큐로부터 받고, 지정된 식별자가 포함된 메시지를 큐에서 사용할 수 있거나 제한 시간이 만료될 때까지 대기합니다.

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

매개 변수

id
String

받을 메시지의 Id입니다.

timeout
TimeSpan

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

반환

전달된 id 매개 변수와 Message 속성이 일치하는 Id를 반환합니다.

예외

id 매개 변수가 null인 경우

또는

transaction 매개 변수가 null인 경우

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

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

또는

비트랜잭션 큐입니다.

또는

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

예제

다음 코드 예제에서는 ReceiveById(String, TimeSpan, MessageQueueTransaction)의 사용법을 보여줍니다.


// 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, "Example Message Label",
    MessageQueueTransactionType::Single);

// Get the message's Id property value.
String^ id = msg->Id;

// Create a message queuing transaction.
MessageQueueTransaction^ transaction = gcnew MessageQueueTransaction();

try
{
    // Begin a transaction.
    transaction->Begin();

    // Receive the message from the queue.
    msg = queue->ReceiveById(id, TimeSpan::FromSeconds(10.0),
        transaction);

    // Commit the transaction.
    transaction->Commit();
}
catch (Exception^ ex)
{
    // Cancel the transaction.
    transaction->Abort();

    // Propagate the exception.
    throw ex;
}
finally
{
    // Dispose of the transaction object.
    delete transaction;
    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, "Example Message Label",
    MessageQueueTransactionType.Single);

// Get the message's Id property value.
string id = msg.Id;

// Create a message queuing transaction.
MessageQueueTransaction transaction = new MessageQueueTransaction();

try
{
    // Begin a transaction.
    transaction.Begin();

    // Receive the message from the queue.
    msg = queue.ReceiveById(id, TimeSpan.FromSeconds(10.0),
        transaction);

    // Commit the transaction.
    transaction.Commit();
}
catch(System.Exception e)
{
    // Cancel the transaction.
    transaction.Abort();

    // Propagate the exception.
    throw e;
}
finally
{
    // Dispose of the transaction object.
    transaction.Dispose();
}

설명

이 메서드를 사용하여 알려진 식별자가 있는 메시지를 읽고 매개 변수로 정의된 transaction 내부 트랜잭션 컨텍스트를 사용하여 큐에서 제거합니다. 매개 변수로 지정된 id 식별자가 있는 메시지가 큐에 있는 경우 이 메서드는 즉시 를 반환합니다. 그렇지 않으면 메서드는 지정된 기간 동안 새 메시지가 도착할 때까지 기다립니다. 제한 시간이 만료되기 전에 새 메시지가 도착하지 않으면 예외가 throw됩니다.

매개 변수는 timeout 이 메서드의 총 실행 시간을 지정하지 않습니다. 대신 새 메시지가 큐에 도착할 때까지 기다리는 시간을 지정합니다. 새 메시지가 도착할 때마다 이 메서드는 Id 새 메시지의 를 검사하여 매개 변수와 id 일치하는지 확인합니다. 그렇지 않은 경우 이 메서드는 시간 제한 기간을 시작하고 다른 새 메시지가 도착할 때까지 기다립니다. 따라서 새 메시지가 제한 시간 내에 계속 도착하는 경우 이 메서드는 새 메시지가 도착하지 않고 제한 시간이 만료될 때까지 또는 매개 변수와 일치하는 id 메시지가 도착할 때까지 무기한 실행을 계속할 수 있습니다Id.

메시지의 속성은 Id 메시지 큐 엔터프라이즈에서 고유하므로 큐에 지정된 id 매개 변수와 일치하는 최대 하나의 메시지가 있습니다.

매개 변수에 지정된 제한 시간 내에 새 메시지가 큐에 계속 도착하는 한 현재 스레드가 차단되는 것이 허용되는 경우 이 오버로드 ReceiveById(String)timeout 사용합니다. 스레드는 지정된 기간 이상 또는 매개 변수 값을 지정한 경우 또는 매개 변수에 지정된 InfiniteTimeouttimeout 시간 제한 기간 내에 새 메시지가 큐에 계속 도착하는 경우 무기한 차단됩니다 timeout .

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

다른 두 가지 메서드를 사용하면 큐에서 메시지를 받을 수 있습니다. 합니다 Receive 큐의 첫 번째 메시지를 반환 하는 메서드 및 ReceiveByCorrelationId(String) 메서드는 승인, 보고서 또는 큐로 보낸 메시지의 결과로 생성 된 애플리케이션에서 생성 한 응답 메시지를 검색 하는 합니다.

지정된 식별자가 있는 메시지를 큐에서 제거하지 않고 읽으려면 메서드를 PeekById(String) 사용합니다. 메서드는 PeekById(String) 항상 큐에서 첫 번째 메시지를 반환하므로 우선 순위가 높은 메시지가 큐에 도착하지 않는 한 메서드에 대한 후속 호출은 동일한 메시지를 반환합니다. 에 대한 호출 PeekById(String)에서 반환된 메시지와 연결된 트랜잭션 컨텍스트가 없습니다. 는 PeekById(String) 큐에서 메시지를 제거하지 않으므로 트랜잭션이 중단된 경우 롤백할 것이 없습니다.

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

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

추가 정보

적용 대상

ReceiveById(String, TimeSpan, MessageQueueTransactionType)

주어진 식별자를 갖는 메시지를 받고, 지정된 식별자가 포함된 메시지를 큐에서 사용할 수 있거나 제한 시간이 만료될 때까지 대기합니다.

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

매개 변수

id
String

받을 메시지의 Id입니다.

timeout
TimeSpan

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

transactionType
MessageQueueTransactionType

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

반환

전달된 id 매개 변수와 Message 속성이 일치하는 Id를 반환합니다.

예외

id 매개 변수가 null인 경우

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

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

또는

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

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

예제

다음 코드 예제에서는 ReceiveById(String, TimeSpan, 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, "Example Message Label",
    MessageQueueTransactionType::Single);

// Get the message's Id property value.
String^ id = msg->Id;

// Receive the message from the queue.
msg = queue->ReceiveById(id, 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, "Example Message Label",
    MessageQueueTransactionType.Single);

// Get the message's Id property value.
string id = msg.Id;

// Receive the message from the queue.
msg = queue.ReceiveById(id, TimeSpan.FromSeconds(10.0),
    MessageQueueTransactionType.Single);

설명

이 메서드를 사용하여 알려진 식별자가 있는 메시지를 읽고 큐에서 제거합니다. 이 메서드는 매개 변수로 지정된 식별자가 있는 메시지가 매개 변수로 id 정의된 transactionType 트랜잭션 컨텍스트를 사용하여 큐에 있는 경우 즉시 반환됩니다. 그렇지 않으면 메서드는 지정된 기간 동안 새 메시지가 도착할 때까지 기다립니다. 제한 시간이 만료되기 전에 새 메시지가 도착하지 않으면 예외가 throw됩니다.

매개 변수는 timeout 이 메서드의 총 실행 시간을 지정하지 않습니다. 대신 새 메시지가 큐에 도착할 때까지 기다리는 시간을 지정합니다. 새 메시지가 도착할 때마다 이 메서드는 Id 새 메시지의 를 검사하여 매개 변수와 id 일치하는지 확인합니다. 그렇지 않은 경우 이 메서드는 시간 제한 기간을 시작하고 다른 새 메시지가 도착할 때까지 기다립니다. 따라서 새 메시지가 제한 시간 내에 계속 도착하는 경우 이 메서드는 새 메시지가 도착하지 않고 제한 시간이 만료될 때까지 또는 매개 변수와 일치하는 id 메시지가 도착할 때까지 무기한 실행을 계속할 수 있습니다Id.

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

메시지의 속성은 Id 메시지 큐 엔터프라이즈에서 고유하므로 큐에 지정된 id 매개 변수와 일치하는 최대 하나의 메시지가 있습니다. 지정된 식별자가 있는 메시지가 이 MessageQueue instance 연결된 메시지 이외의 큐에 있으면 메시지를 찾을 수 없습니다.

매개 변수에 지정된 제한 시간 내에 새 메시지가 큐에 계속 도착하는 한 현재 스레드가 차단되는 것이 허용되는 경우 이 오버로드 ReceiveById(String)timeout 사용합니다. 스레드는 지정된 기간 이상 또는 매개 변수 값을 지정 InfiniteTimeouttimeout 한 경우 또는 새 메시지가 매개 변수에 지정된 제한 시간 내에 큐에 계속 도착하는 경우 무기한으로 차단됩니다 timeout .

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

다른 두 가지 메서드를 사용하면 큐에서 메시지를 받을 수 있습니다. 합니다 Receive 큐의 첫 번째 메시지를 반환 하는 메서드 및 ReceiveByCorrelationId(String) 메서드는 승인, 보고서 또는 큐로 보낸 메시지의 결과로 생성 된 애플리케이션에서 생성 한 응답 메시지를 검색 하는 합니다.

지정된 식별자가 있는 메시지를 큐에서 제거하지 않고 읽으려면 메서드를 PeekById(String) 사용합니다. 메서드는 PeekById(String) 항상 큐에서 첫 번째 메시지를 반환하므로 우선 순위가 높은 메시지가 큐에 도착하지 않는 한 메서드에 대한 후속 호출은 동일한 메시지를 반환합니다. 에 대한 호출 PeekById(String)에서 반환된 메시지와 연결된 트랜잭션 컨텍스트가 없습니다. 는 PeekById(String) 큐에서 메시지를 제거하지 않으므로 트랜잭션이 중단된 경우 롤백할 것이 없습니다.

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

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

추가 정보

적용 대상