Export (0) Print
Expand All

MessageReceiver Class

Receives messages from the message container and acknowledges them.

Namespace:  Microsoft.ServiceBus.Messaging
Assembly:  Microsoft.ServiceBus (in Microsoft.ServiceBus.dll)

public abstract class MessageReceiver : MessageClientEntity

The MessageReceiver type exposes the following members.

  NameDescription
Public propertyBatchFlushIntervalGets the batch flush interval.
Protected propertyBatchingEnabledGets a value indicating whether the batching is enabled.
Public propertyIsClosedGets or sets a value that indicates whether the message client entity is closed. (Inherited from MessageClientEntity.)
Public propertyLastPeekedSequenceNumberGets or sets the sequence number of the message last peeked.
Public propertyModeGets the message receive mode.
Public propertyPathGets the path of the queue or topic, relative to the MessagingFactory base address.
Public propertyPrefetchCountGets or sets the number of messages that the message receiver can simultaneously request.
Public propertyRetryPolicyGets or sets a retry policy associated with this instance that determines whether if the request should be retried. (Inherited from MessageClientEntity.)
Protected propertyThisLockGents an object used for locking the MessageClientEntity instance. (Inherited from MessageClientEntity.)
Top

  NameDescription
Public methodAbandon(Guid)Discards the message and relinquishes the message lock ownership.
Public methodAbandon(Guid, IDictionary<String, Object>)Discards the message and relinquishes the message lock ownership.
Public methodAbandonAsync(Guid)Asynchronously discards the message and relinquishes the message lock ownership.
Public methodAbandonAsync(Guid, IDictionary<String, Object>)Asynchronously discards the message and relinquishes the message lock ownership.
Public methodAbortAborts the message client entity and puts its status into a closing state. (Inherited from MessageClientEntity.)
Public methodBeginAbandon(Guid, AsyncCallback, Object)Begins an asynchronous operation to abandon the message and relinquish its lock.
Public methodBeginAbandon(Guid, IDictionary<String, Object>, AsyncCallback, Object)Begins an asynchronous operation to abandon the message and relinquish its lock.
Public methodBeginCloseBegins an asynchronous operation to close the message client entity. (Inherited from MessageClientEntity.)
Public methodBeginCompleteBegins an asynchronous operation to complete receipt of a message.
Public methodBeginCompleteBatchBegins an asynchronous operation to complete a message batching.
Public methodBeginDeadLetter(Guid, AsyncCallback, Object)Begins an asynchronous operation to move a message to the dead letter queue.
Public methodBeginDeadLetter(Guid, IDictionary<String, Object>, AsyncCallback, Object)Begins an asynchronous operation to move a message to the dead letter queue.
Public methodBeginDeadLetter(Guid, String, String, AsyncCallback, Object)Begins an asynchronous operation to move a message to the dead letter queue.
Public methodBeginDefer(Guid, AsyncCallback, Object)Begins an asynchronous operation to suspend receipt of a message.
Public methodBeginDefer(Guid, IDictionary<String, Object>, AsyncCallback, Object)Begins an asynchronous operation to suspend receipt of a message.
Public methodBeginPeek(AsyncCallback, Object)Begins an operation to peek a message.
Public methodBeginPeek(Int64, AsyncCallback, Object)Begins an operation to peek a message.
Public methodBeginPeekBatch(Int32, AsyncCallback, Object)Begins an operation to peek a batch of message.
Public methodBeginPeekBatch(Int64, Int32, AsyncCallback, Object)Begins an operation to peek a batch of message.
Public methodBeginReceive(AsyncCallback, Object)Begins an asynchronous operation to receive a message.
Public methodBeginReceive(Int64, AsyncCallback, Object)Begins an asynchronous operation to receive a message.
Public methodBeginReceive(TimeSpan, AsyncCallback, Object)Begins an asynchronous operation to receive a message.
Public methodBeginReceiveBatch(IEnumerable<Int64>, AsyncCallback, Object)Begins an asynchronous operation to receive a batch of message.
Public methodBeginReceiveBatch(Int32, AsyncCallback, Object)Begins an asynchronous operation to receive a batch of message.
Public methodBeginReceiveBatch(Int32, TimeSpan, AsyncCallback, Object)Begins an asynchronous operation to receive a batch of message.
Public methodCloseCloses the message client entity and puts its status into a closed state. (Inherited from MessageClientEntity.)
Public methodCloseAsyncAsynchronously closes the message client entity and puts its status into a closed state. (Inherited from MessageClientEntity.)
Public methodCompleteCompletes the receive operation on a message.
Public methodCompleteAsyncAsynchronously completes the receive operation on a message.
Public methodCompleteBatchCompletes the receive operation on a batch of message.
Public methodCompleteBatchAsyncAsynchronously completes the receive operation on a batch of message.
Public methodDeadLetter(Guid)Moves the undelivered message to the dead letter queue.
Public methodDeadLetter(Guid, IDictionary<String, Object>)Moves the undelivered message to the dead letter queue.
Public methodDeadLetter(Guid, String, String)Moves the undelivered message to the dead letter queue.
Public methodDeadLetterAsync(Guid)Asynchronously moves the undelivered message to the dead letter queue.
Public methodDeadLetterAsync(Guid, IDictionary<String, Object>)Asynchronously moves the undelivered message to the dead letter queue.
Public methodDeadLetterAsync(Guid, String, String)Asynchronously moves the undelivered message to the dead letter queue.
Public methodDefer(Guid)Indicates that the receiver wants to defer the processing for the message.
Public methodDefer(Guid, IDictionary<String, Object>)Indicates that the receiver wants to defer the processing for the message.
Public methodDeferAsync(Guid)Asynchronously defer the processing of the message.
Public methodDeferAsync(Guid, IDictionary<String, Object>)Asynchronously defer the processing of the message.
Public methodEndAbandonEnds the asynchronous operation to abandon the message and relinquish its lock.
Public methodEndCloseFinishes an asynchronous operation to close the message client entity. (Inherited from MessageClientEntity.)
Public methodEndCompleteEnds the asynchronous operation to complete receipt of a message.
Public methodEndCompleteBatchEnds the asynchronous operation to complete receipt of a batch message.
Public methodEndDeadLetterEnds an asynchronous operation to move the message to the dead letter queue.
Public methodEndDeferEnds an asynchronous operation to defer receipt of a message.
Public methodEndPeekEnds an asynchronous operation to peek a message.
Public methodEndPeekBatchEnds an asynchronous operation to peek a batch of message.
Public methodEndReceiveEnds an asynchronous operation to receive a message.
Public methodEndReceiveBatchEnds an asynchronous operation to receive a batch of message.
Public methodEquals (Inherited from Object.)
Protected methodFaultPuts the message client entity into a faulted state. (Inherited from MessageClientEntity.)
Protected methodFinalize (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Protected methodStatic memberGetLockTokenGets the lock token bound to the message.
Protected methodStatic memberGetLockTokensGets the collection of lock tokens from the specified collection of messages.
Public methodGetType (Inherited from Object.)
Protected methodMemberwiseClone (Inherited from Object.)
Protected methodOnAbandonExecutes upon calling the Abandon operation.
Protected methodOnAbortExecutes upon calling the Abort operation. (Inherited from MessageClientEntity.)
Protected methodOnBeginAbandonExecutes upon calling the OnAbandon or BeginAbandon operation.
Protected methodOnBeginCloseExecutes upon calling the BeginClose operation. (Inherited from MessageClientEntity.)
Protected methodOnBeginCompleteExecutes upon calling the OnComplete or BeginComplete operation.
Protected methodOnBeginDeadLetterExecutes upon calling the OnDeadLetter or BeginDeadLetter operation.
Protected methodOnBeginDeferExecutes upon calling the OnDefer or BeginDefer operation.
Protected methodOnBeginOpenExecutes upon calling the operation to begin to open the message client entity. (Inherited from MessageClientEntity.)
Protected methodOnBeginPeekExecutes upon calling the BeginPeek operation.
Protected methodOnBeginRenewMessageLocksExecutes upon calling the OnBegin operation for lock messages.
Protected methodOnBeginTryReceive(TrackingContext, IEnumerable<Int64>, TimeSpan, AsyncCallback, Object)Executes upon calling the OnTryReceive or BeginTryReceive operation.
Protected methodOnBeginTryReceive(TrackingContext, Int32, TimeSpan, AsyncCallback, Object)Executes upon calling the OnTryReceive or BeginTryReceive operation.
Protected methodOnBeginTryReceive2Executes upon calling the OnTryReceive or BeginTryReceive operation.
Protected methodOnCloseExecutes upon calling the Close operation. (Inherited from MessageClientEntity.)
Protected methodOnClosedOccurs when the message client entity is transitioned into a closing state. (Inherited from MessageClientEntity.)
Protected methodOnCompleteExecutes upon calling the Complete operation.
Protected methodOnDeadLetterExecutes upon calling the DeadLetter operation.
Protected methodOnDeferExecutes upon calling the Defer operation.
Protected methodOnEndAbandonExecutes the end abandon action.
Protected methodOnEndCloseExecutes upon calling the EndClose operation. (Inherited from MessageClientEntity.)
Protected methodOnEndCompleteExecutes the end complete action.
Protected methodOnEndDeadLetterExecutes the end move to dead letter queue action.
Protected methodOnEndDeferExecutes the end defer action.
Protected methodOnEndOpenExecutes upon calling the operation to end to open the message client entity. (Inherited from MessageClientEntity.)
Protected methodOnEndPeekExecutes the EndPeek operation.
Protected methodOnEndRenewMessageLocksExecutes the EndRenew action for message locks.
Protected methodOnEndTryReceiveExecutes the end try receive action.
Protected methodOnEndTryReceive2Executes the end try receive action.
Protected methodOnFaultedExecutes upon calling the Fault operation. (Inherited from MessageClientEntity.)
Public methodOnMessageProcesses a message in an event-driven message pump.
Public methodOnMessageAsyncAsynchronously processes a message in an event-driven message pump.
Protected methodOnOpenExecutes upon calling the operation to open the message client entity. (Inherited from MessageClientEntity.)
Protected methodOnOpenedExecutes when the message client entity is opened. (Inherited from MessageClientEntity.)
Protected methodOnPeekExecutes upon calling the Peek operation.
Protected methodOnRenewMessageLocksExecutes the Renew action for lock messages.
Protected methodOnTryReceive(TrackingContext, IEnumerable<Int64>, TimeSpan, IEnumerable<BrokeredMessage>)Executes upon calling the TryReceive operation.
Protected methodOnTryReceive(TrackingContext, Int32, TimeSpan, IEnumerable<BrokeredMessage>)Executes upon calling the TryReceive operation.
Public methodPeek()Reads the next message without changing the state of the receiver or the message source.
Public methodPeek(Int64)Reads the next message without changing the state of the receiver or the message source.
Public methodPeekAsync()Asynchronously reads the next message without changing the state of the receiver or the message source.
Public methodPeekAsync(Int64)Asynchronously reads the next message without changing the state of the receiver or the message source.
Public methodPeekBatch(Int32)Reads the next batch of message without changing the state of the receiver or the message source.
Public methodPeekBatch(Int64, Int32)Reads the next batch of message without changing the state of the receiver or the message source.
Public methodPeekBatchAsync(Int32)Asynchronously reads the next batch of message without changing the state of the receiver or the message source.
Public methodPeekBatchAsync(Int64, Int32)Asynchronously reads the next batch of message without changing the state of the receiver or the message source.
Public methodReceive()Receives a BrokeredMessage from the current queue or topic.
Public methodReceive(Int64)Receives a message from the current queue or topic.
Public methodReceive(TimeSpan)Receives a BrokeredMessage from the current queue or topic.
Public methodReceiveAsync()Asynchronously receives a message from the current queue or topic.
Public methodReceiveAsync(Int64)Asynchronously receives a message from the current queue or topic.
Public methodReceiveAsync(TimeSpan)Asynchronously receives a message from the current queue or topic.
Public methodReceiveBatch(IEnumerable<Int64>)Receives a batch of messages.
Public methodReceiveBatch(Int32)Receives a batch of messages.
Public methodReceiveBatch(Int32, TimeSpan)Receives a batch of messages.
Public methodReceiveBatchAsync(IEnumerable<Int64>)Asynchronously receives a batch of messages.
Public methodReceiveBatchAsync(Int32)Asynchronously receives a batch of messages.
Public methodReceiveBatchAsync(Int32, TimeSpan)Asynchronously receives a batch of messages.
Protected methodThrowIfClosedThrows an exception if the message client entity is closed. (Inherited from MessageClientEntity.)
Protected methodThrowIfDisposedThrows an exception if the message client entity is disposed. (Inherited from MessageClientEntity.)
Protected methodThrowIfDisposedOrImmutableThrows an exception if the client is disposed or immutable. (Inherited from MessageClientEntity.)
Protected methodThrowIfDisposedOrNotOpenThrows an exception if the client is disposed or not open. (Inherited from MessageClientEntity.)
Protected methodThrowIfFaultedThrows an exception if the client is faulted. (Inherited from MessageClientEntity.)
Public methodToString (Inherited from Object.)
Top

Although you can use the QueueClient class to send and receive messages without creating a MessageReceiver object, you can also use MessageSender and MessageReceiver to create a sender and receiver on an entity. However, note that you can only use a MessageReceiver to receive messages from a queue or subscription; you cannot receive messages or listen for messages from a topic. Similarly, you can only use a MessageSender to send messages to a queue or topic; you cannot send messages to a subscription. Note that the default message receive mode is PeekLock, which ensures reliable message receiving.

When you create a MessageReceiver for subscriptions, the entityPath parameter is of the form topicPath/subscriptions/subscriptionName.

The following example receives a message from the queue created in the MessageSender example:

Uri serviceUri = ServiceBusEnvironment.CreateServiceUri("sb", ServiceNamespace, string.Empty); 

MessagingFactory factory = MessagingFactory.Create(serviceUri, credentials); 

MessageReceiver myMessageReceiver = factory.CreateMessageReceiver(queueName);

BrokeredMessage message;
while ((message = myMessageReceiver.Receive(new TimeSpan(hours: 0, minutes: 1, seconds: 5))) != null)
{
    Console.WriteLine(
    string.Format(
    "Message received: Id = {0}, Body = {1}", message.MessageId, message.GetBody<string>()));
    message.Complete();
}

Any public static (Shared in Visual Basic) members of this type are thread safe. Instance members are also guaranteed to be thread safe.

Community Additions

ADD
Show:
© 2014 Microsoft