Редагувати

Поділитися через


MessageQueue.ReceiveById Method

Definition

Receives the message that matches the given identifier, removing it from the queue.

Overloads

ReceiveById(String)

Receives the message that matches the given identifier from a non-transactional queue and immediately raises an exception if no message with the specified identifier currently exists in the queue.

ReceiveById(String, MessageQueueTransaction)

Receives the message that matches the given identifier (from a transactional queue) and immediately raises an exception if no message with the specified identifier currently exists in the queue.

ReceiveById(String, MessageQueueTransactionType)

Receives the message that matches the given identifier and immediately raises an exception if no message with the specified identifier currently exists in the queue.

ReceiveById(String, TimeSpan)

Receives the message that matches the given identifier (from a non-transactional queue) and waits until either a message with the specified identifier is available in the queue or the time-out expires.

ReceiveById(String, TimeSpan, MessageQueueTransaction)

Receives the message that matches the given identifier (from a transactional queue) and waits until either a message with the specified identifier is available in the queue or the time-out expires.

ReceiveById(String, TimeSpan, MessageQueueTransactionType)

Receives the message that matches the given identifier and waits until either a message with the specified identifier is available in the queue or the time-out expires.

ReceiveById(String)

Receives the message that matches the given identifier from a non-transactional queue and immediately raises an exception if no message with the specified identifier currently exists in the queue.

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

Parameters

id
String

The Id of the message to receive.

Returns

The Message whose Id property matches the id parameter passed in.

Exceptions

The id parameter is null.

The message with the specified id could not be found.

An error occurred when accessing a Message Queuing method.

Examples

The following code example demonstrates the use of 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);

Remarks

Use this method to read a message with a known identifier and remove it from the queue. This method throws an exception immediately if the message is not in the queue.

The Id property of a message is unique across the Message Queuing enterprise, so there will be at most one message in the queue that matches the given id parameter.

Two other methods allow you to receive messages from a queue. The Receive method returns the first message in the queue, and the ReceiveByCorrelationId(String) method is used to retrieve an acknowledgment, report, or application-generated response message that was created as a result of a message sent to the queue.

To read a message with a specified identifier without removing it from the queue, use the PeekById(String) method. The PeekById(String) method always returns the first message in the queue, so subsequent calls to the method return the same message unless a higher priority message arrives in the queue.

The following table shows whether this method is available in various Workgroup modes.

Workgroup mode Available
Local computer Yes
Local computer and direct format name Yes
Remote computer No
Remote computer and direct format name Yes

See also

Applies to

ReceiveById(String, MessageQueueTransaction)

Receives the message that matches the given identifier (from a transactional queue) and immediately raises an exception if no message with the specified identifier currently exists in the queue.

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

Parameters

id
String

The Id of the message to receive.

Returns

The Message whose Id property matches the id parameter passed in.

Exceptions

The id parameter is null.

-or-

The transaction parameter is null.

The message with the specified id could not be found.

The queue is non-transactional.

-or-

An error occurred when accessing a Message Queuing method.

Examples

The following code example demonstrates the use of 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();
}

Remarks

Use this method to read a message with a known identifier and remove it from the queue, using the internal transaction context defined by the transaction parameter. This method throws an exception immediately if the message is not in the queue

The Id property of a message is unique across the Message Queuing enterprise, so there will be at most one message in the queue that matches the given id parameter.

Because this method is called on a transactional queue, the message that is received would be returned to the queue if the transaction is aborted. The message is not permanently removed from the queue until the transaction is committed.

Two other methods allow you to receive messages from a queue. The Receive method returns the first message in the queue, and the ReceiveByCorrelationId(String) method is used to retrieve an acknowledgment, report, or application-generated response message that was created as a result of a message sent to the queue.

To read a message with a specified identifier without removing it from the queue, use the PeekById(String) method. The PeekById(String) method always returns the first message in the queue, so subsequent calls to the method return the same message unless a higher priority message arrives in the queue. There is no transaction context associated with a message returned by a call to PeekById(String). Because PeekById(String) does not remove any messages in the queue, there would be nothing to roll back if the transaction were aborted.

The following table shows whether this method is available in various Workgroup modes.

Workgroup mode Available
Local computer Yes
Local computer and direct format name Yes
Remote computer No
Remote computer and direct format name Yes

See also

Applies to

ReceiveById(String, MessageQueueTransactionType)

Receives the message that matches the given identifier and immediately raises an exception if no message with the specified identifier currently exists in the queue.

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

Parameters

id
String

The Id of the message to receive.

transactionType
MessageQueueTransactionType

One of the MessageQueueTransactionType values, describing the type of transaction context to associate with the message.

Returns

The Message whose Id property matches the id parameter passed in.

Exceptions

The id parameter is null.

The message with the specified id could not be found.

The transactionType parameter is not one of the MessageQueueTransactionType members.

An error occurred when accessing a Message Queuing method.

Examples

The following code example demonstrates the use of 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);

Remarks

Use this method to read a message with a known identifier and remove it from the queue. This method throws an exception immediately if the message is not in the queue. Otherwise, the message is removed from the queue and returned to the application using a transaction context defined by the transactionType parameter.

Specify Automatic for the transactionType parameter if there is already an external transaction context attached to the thread that you want to use to receive the message. Specify Single if you want to receive the message as a single internal transaction. You can specify None if you want to receive a message from a transactional queue outside of a transaction context.

The Id property of a message is unique across the Message Queuing enterprise, so there will be at most one message in the queue that matches the given id parameter. If the message with the specified identifier is in a queue other than the one associated with this MessageQueue instance, the message will not be found.

If this method is called to receive a message from a transactional queue, the message that is received would be returned to the queue if the transaction is aborted. The message is not permanently removed from the queue until the transaction is committed.

Two other methods allow you to receive messages from a queue. The Receive method returns the first message in the queue, and the ReceiveByCorrelationId(String) method is used to retrieve an acknowledgment, report, or application-generated response message that was created as a result of a message sent to the queue.

To read a message with a specified identifier without removing it from the queue, use the PeekById(String) method. The PeekById(String) method always returns the first message in the queue, so subsequent calls to the method return the same message unless a higher priority message arrives in the queue. There is no transaction context associated with a message returned by a call to PeekById(String). Because PeekById(String) does not remove any messages in the queue, there would be nothing to roll back if the transaction were aborted.

The following table shows whether this method is available in various Workgroup modes.

Workgroup mode Available
Local computer Yes
Local computer and direct format name Yes
Remote computer No
Remote computer and direct format name Yes

See also

Applies to

ReceiveById(String, TimeSpan)

Receives the message that matches the given identifier (from a non-transactional queue) and waits until either a message with the specified identifier is available in the queue or the time-out expires.

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

Parameters

id
String

The Id of the message to receive.

timeout
TimeSpan

A TimeSpan that indicates the time to wait until a new message is available for inspection.

Returns

The Message whose Id property matches the id parameter passed in.

Exceptions

The id parameter is null.

The value specified for the timeout parameter is not valid, possibly timeout is less than Zero or greater than InfiniteTimeout.

A message with the specified id did not arrive in the queue before the time-out expired.

-or-

An error occurred when accessing a Message Queuing method.

Examples

The following code example demonstrates the use of 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));

Remarks

Use this method to read a message with a known identifier and remove it from the queue. This method returns immediately if the message with the identifier specified by the id parameter is in the queue. Otherwise, the method waits the given period of time for a new message to arrive. If a new message does not arrive before the time-out expires, an exception is thrown.

The timeout parameter does not specify the total running time for this method. Rather, it specifies the time to wait for a new message to arrive in the queue. Each time a new message arrives, this method examines the Id of the new message to see if it matches the id parameter. If not, this method starts the time-out period over and waits for another new message to arrive. Therefore, if new messages continue to arrive within the time-out period, it is possible for this method to continue running indefinitely, either until the time-out period expires without any new messages arriving, or until a message arrives whose Id matches the id parameter.

The Id property of a message is unique across the Message Queuing enterprise, so there will be at most one message in the queue that matches the given id parameter.

Use this overload of ReceiveById(String) when it is acceptable for the current thread to be blocked as long as new messages continue to arrive in the queue within the time-out period specified by the timeout parameter. The thread will be blocked for at least the given period of time, or indefinitely if you specified the value InfiniteTimeout for the timeout parameter, or if new messages continue to arrive in the queue within the time-out period specified by the timeout parameter.

Two other methods allow you to receive messages from a queue. The Receive method returns the first message in the queue, and the ReceiveByCorrelationId(String) method is used to retrieve an acknowledgment, report, or application-generated response message that was created as a result of a message sent to the queue.

To read a message with a specified identifier without removing it from the queue, use the PeekById(String) method. The PeekById(String) method always returns the first message in the queue, so subsequent calls to the method return the same message unless a higher priority message arrives in the queue.

The following table shows whether this method is available in various Workgroup modes.

Workgroup mode Available
Local computer Yes
Local computer and direct format name Yes
Remote computer No
Remote computer and direct format name Yes

See also

Applies to

ReceiveById(String, TimeSpan, MessageQueueTransaction)

Receives the message that matches the given identifier (from a transactional queue) and waits until either a message with the specified identifier is available in the queue or the time-out expires.

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

Parameters

id
String

The Id of the message to receive.

timeout
TimeSpan

A TimeSpan that indicates the time to wait until a new message is available for inspection.

Returns

The Message whose Id property matches the id parameter passed in.

Exceptions

The id parameter is null.

-or-

The transaction parameter is null.

The value specified for the timeout parameter is not valid, possibly timeout is less than Zero or greater than InfiniteTimeout.

A message with the specified id did not arrive in the queue before the time-out expired.

-or-

The queue is non-transactional.

-or-

An error occurred when accessing a Message Queuing method.

Examples

The following code example demonstrates the use of 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();
}

Remarks

Use this method to read a message with a known identifier and remove it from the queue, using the internal transaction context defined by the transaction parameter. This method returns immediately if the message with the identifier specified by the id parameter is in the queue. Otherwise, the method waits the given period of time for a new message to arrive. If a new message does not arrive before the time-out expires, an exception is thrown.

The timeout parameter does not specify the total running time for this method. Rather, it specifies the time to wait for a new message to arrive in the queue. Each time a new message arrives, this method examines the Id of the new message to see if it matches the id parameter. If not, this method starts the time-out period over and waits for another new message to arrive. Therefore, if new messages continue to arrive within the time-out period, it is possible for this method to continue running indefinitely, either until the time-out period expires without any new messages arriving, or until a message arrives whose Id matches the id parameter.

The Id property of a message is unique across the Message Queuing enterprise, so there will be at most one message in the queue that matches the given id parameter.

Use this overload of ReceiveById(String) when it is acceptable for the current thread to be blocked as long as new messages continue to arrive in the queue within the time-out period specified by the timeout parameter. The thread will be blocked for at least the given period of time, or indefinitely if you specified the value InfiniteTimeout for the timeout parameter, or if new messages continue to arrive in the queue within the timeout period specified by the timeout parameter.

Because this method is called on a transactional queue, the message that is received would be returned to the queue if the transaction is aborted. The message is not permanently removed from the queue until the transaction is committed.

Two other methods allow you to receive messages from a queue. The Receive method returns the first message in the queue, and the ReceiveByCorrelationId(String) method is used to retrieve an acknowledgment, report, or application-generated response message that was created as a result of a message sent to the queue.

To read a message with a specified identifier without removing it from the queue, use the PeekById(String) method. The PeekById(String) method always returns the first message in the queue, so subsequent calls to the method return the same message, unless a higher priority message arrives in the queue. There is no transaction context associated with a message returned by a call to PeekById(String). Because PeekById(String) does not remove any messages in the queue, there would be nothing to roll back if the transaction were aborted.

The following table shows whether this method is available in various Workgroup modes.

Workgroup mode Available
Local computer Yes
Local computer and direct format name Yes
Remote computer No
Remote computer and direct format name Yes

See also

Applies to

ReceiveById(String, TimeSpan, MessageQueueTransactionType)

Receives the message that matches the given identifier and waits until either a message with the specified identifier is available in the queue or the time-out expires.

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

Parameters

id
String

The Id of the message to receive.

timeout
TimeSpan

A TimeSpan that indicates the time to wait until a new message is available for inspection.

transactionType
MessageQueueTransactionType

One of the MessageQueueTransactionType values, describing the type of transaction context to associate with the message.

Returns

The Message whose Id property matches the id parameter passed in.

Exceptions

The id parameter is null.

The value specified for the timeout parameter is not valid, possibly timeout is less than Zero or greater than InfiniteTimeout.

A message with the specified id did not arrive in the queue before the time-out expired.

-or-

An error occurred when accessing a Message Queuing method.

The transactionType parameter is not one of the MessageQueueTransactionType members.

Examples

The following code example demonstrates the use of 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);

Remarks

Use this method to read a message with a known identifier and remove it from the queue. This method returns immediately if the message with the identifier specified by the id parameter is in the queue, using a transaction context defined by the transactionType parameter. Otherwise, the method waits the given period of time for a new message to arrive. If a new message does not arrive before the time-out expires, an exception is thrown.

The timeout parameter does not specify the total running time for this method. Rather, it specifies the time to wait for a new message to arrive in the queue. Each time a new message arrives, this method examines the Id of the new message to see if it matches the id parameter. If not, this method starts the time-out period over and waits for another new message to arrive. Therefore, if new messages continue to arrive within the time-out period, it is possible for this method to continue running indefinitely, either until the time-out period expires without any new messages arriving, or until a message arrives whose Id matches the id parameter.

Specify Automatic for the transactionType parameter if there is already an external transaction context attached to the thread that you want to use to receive the message. Specify Single if you want to receive the message as a single internal transaction. You can specify None if you want to receive a message from a transactional queue outside of a transaction context.

The Id property of a message is unique across the Message Queuing enterprise, so there will be at most one message in the queue that matches the given id parameter. If the message with the specified identifier is in a queue other than the one associated with this MessageQueue instance, the message will not be found.

Use this overload of ReceiveById(String) when it is acceptable for the current thread to be blocked as long as new messages continue to arrive in the queue within the time-out period specified by the timeout parameter. The thread will be blocked for at least the given period of time, or indefinitely if you specified the value InfiniteTimeout for the timeout parameter, or if new messages continue to arrive in the queue within the time-out period specified by the timeout parameter.

If this method is called to receive a message from a transactional queue, the message that is received would be returned to the queue if the transaction is aborted. The message is not permanently removed from the queue until the transaction is committed.

Two other methods allow you to receive messages from a queue. The Receive method returns the first message in the queue, and the ReceiveByCorrelationId(String) method is used to retrieve an acknowledgment, report, or application-generated response message that was created as a result of a message sent to the queue.

To read a message with a specified identifier without removing it from the queue, use the PeekById(String) method. The PeekById(String) method always returns the first message in the queue, so subsequent calls to the method return the same message unless a higher priority message arrives in the queue. There is no transaction context associated with a message returned by a call to PeekById(String). Because PeekById(String) does not remove any messages in the queue, there would be nothing to roll back if the transaction were aborted.

The following table shows whether this method is available in various Workgroup modes.

Workgroup mode Available
Local computer Yes
Local computer and direct format name Yes
Remote computer No
Remote computer and direct format name Yes

See also

Applies to