MessageQueue.PeekById 메서드

정의

지정된 메시지 식별자가 포함된 메시지의 복사본을 반환하지만 큐에서 해당 메시지를 제거하지는 않습니다.

오버로드

PeekById(String)

메시지 식별자가 id 매개 변수와 일치하는 메시지를 피킹합니다.

PeekById(String, TimeSpan)

메시지 식별자가 id 매개 변수와 일치하는 메시지를 피킹합니다. 큐에 메시지가 표시되거나 제한 시간이 만료될 때까지 대기합니다.

PeekById(String)

메시지 식별자가 id 매개 변수와 일치하는 메시지를 피킹합니다.

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

매개 변수

id
String

피킹할 메시지의 Id입니다.

반환

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

예외

id 매개 변수가 null인 경우

지정된 id의 메시지가 없습니다.

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

예제

다음 코드 예제에서는 PeekById(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));

// Peek at the message.
msg = queue->PeekById(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));

// Peek at the message.
msg = queue.PeekById(id);

설명

큐에서 제거하지 않고 알려진 메시지 식별자가 있는 메시지를 읽는 데 사용합니다 PeekById(String) . 메시지의 식별자는 메시지 큐 엔터프라이즈에서 고유하므로 큐에 지정된 id 매개 변수와 일치하는 최대 하나의 메시지가 있습니다. 이 오버로드는 큐에 현재 메시지가 포함되지 않은 경우 예외를 throw합니다.

큐에서 메시지를 피킹할 수 있는 두 가지 추가 메서드인 PeekPeekByCorrelationId(String)를 사용할 수 있습니다. Peek 메서드는 큐에서 첫 번째 메시지를 반환 합니다. PeekByCorrelationId(String) 승인, 보고서, 또는 큐로 보낸 메시지의 결과로 생성 된 애플리케이션에서 생성 한 응답 메시지를 반환 합니다.

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

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

추가 정보

적용 대상

PeekById(String, TimeSpan)

메시지 식별자가 id 매개 변수와 일치하는 메시지를 피킹합니다. 큐에 메시지가 표시되거나 제한 시간이 만료될 때까지 대기합니다.

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

매개 변수

id
String

피킹할 메시지의 Id입니다.

timeout
TimeSpan

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

반환

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

예외

id 매개 변수가 null인 경우

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

지정된 id가 들어 있는 메시지가 큐에 없고 timeout 매개 변수가 지정한 기간이 만료되기 전에 메시지가 도착하지 않았습니다.

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

예제

다음 코드 예제에서는 PeekById(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;

// Peek at the message.
msg = queue->PeekById(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;

// Peek at the message.
msg = queue.PeekById(id, TimeSpan.FromSeconds(10.0));

설명

큐에서 제거하지 않고 알려진 메시지 식별자가 있는 메시지를 읽는 데 사용합니다 PeekById(String) . 메시지의 식별자는 메시지 큐 엔터프라이즈에서 고유하므로 큐에 지정된 id 매개 변수와 일치하는 최대 하나의 메시지가 있습니다. 이 오버로드는 큐에 현재 메시지가 포함되지 않고 시간 초과가 발생하기 전에 새 메시지가 도착하지 않는 경우 예외를 throw합니다.

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

큐에서 메시지를 피킹할 수 있는 두 가지 추가 메서드인 PeekPeekByCorrelationId(String)를 사용할 수 있습니다. Peek 메서드는 큐에서 첫 번째 메시지를 반환 합니다. PeekByCorrelationId(String) 승인, 보고서, 또는 큐로 보낸 메시지의 결과로 생성 된 애플리케이션에서 생성 한 응답 메시지를 반환 합니다.

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

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

추가 정보

적용 대상