MessageReceiver Class
Receives messages from the message container and acknowledges them.
Microsoft.ServiceBus.Messaging.MessageClientEntity
Microsoft.ServiceBus.Messaging.MessageReceiver
Microsoft.ServiceBus.Messaging.MessageSession
Namespace: Microsoft.ServiceBus.Messaging
Assembly: Microsoft.ServiceBus (in Microsoft.ServiceBus.dll)
The MessageReceiver type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | BatchFlushInterval | Gets the batch flush interval. |
![]() | BatchingEnabled | Gets a value indicating whether the batching is enabled. |
![]() | IsClosed | Gets or sets a value that indicates whether the message client entity is closed. (Inherited from MessageClientEntity.) |
![]() | LastPeekedSequenceNumber | Gets or sets the sequence number of the message last peeked. |
![]() | Mode | Gets the message receive mode. |
![]() | Path | Gets the path of the queue or topic, relative to the MessagingFactory base address. |
![]() | PrefetchCount | Gets or sets the number of messages that the message receiver can simultaneously request. |
![]() | RetryPolicy | (Inherited from MessageClientEntity.) |
![]() | ThisLock | Gents an object used for locking the MessageClientEntity instance. (Inherited from MessageClientEntity.) |
| Name | Description | |
|---|---|---|
![]() | Abandon(Guid) | Discards the message and relinquishes the message lock ownership. |
![]() | Abandon(Guid, IDictionary<String, Object>) | Discards the message and relinquishes the message lock ownership. |
![]() | AbandonAsync(Guid) | Asynchronously discards the message and relinquishes the message lock ownership. |
![]() | AbandonAsync(Guid, IDictionary<String, Object>) | Asynchronously discards the message and relinquishes the message lock ownership. |
![]() | Abort | Aborts the message client entity and puts its status into a closing state. (Inherited from MessageClientEntity.) |
![]() | BeginAbandon(Guid, AsyncCallback, Object) | Begins an asynchronous operation to abandon the message and relinquish its lock. |
![]() | BeginAbandon(Guid, IDictionary<String, Object>, AsyncCallback, Object) | Begins an asynchronous operation to abandon the message and relinquish its lock. |
![]() | BeginClose | Begins an asynchronous operation to close the message client entity. (Inherited from MessageClientEntity.) |
![]() | BeginComplete | Begins an asynchronous operation to complete receipt of a message. |
![]() | BeginCompleteBatch | Begins an asynchronous operation to complete a message batching. |
![]() | BeginDeadLetter(Guid, AsyncCallback, Object) | Begins an asynchronous operation to move a message to the dead letter queue. |
![]() | BeginDeadLetter(Guid, IDictionary<String, Object>, AsyncCallback, Object) | Begins an asynchronous operation to move a message to the dead letter queue. |
![]() | BeginDeadLetter(Guid, String, String, AsyncCallback, Object) | Begins an asynchronous operation to move a message to the dead letter queue. |
![]() | BeginDefer(Guid, AsyncCallback, Object) | Begins an asynchronous operation to suspend receipt of a message. |
![]() | BeginDefer(Guid, IDictionary<String, Object>, AsyncCallback, Object) | Begins an asynchronous operation to suspend receipt of a message. |
![]() | BeginPeek(AsyncCallback, Object) | Begins an operation to peek a message. |
![]() | BeginPeek(Int64, AsyncCallback, Object) | Begins an operation to peek a message. |
![]() | BeginPeekBatch(Int32, AsyncCallback, Object) | Begins an operation to peek a batch of message. |
![]() | BeginPeekBatch(Int64, Int32, AsyncCallback, Object) | Begins an operation to peek a batch of message. |
![]() | BeginReceive(AsyncCallback, Object) | Begins an asynchronous operation to receive a message. |
![]() | BeginReceive(Int64, AsyncCallback, Object) | Begins an asynchronous operation to receive a message. |
![]() | BeginReceive(TimeSpan, AsyncCallback, Object) | Begins an asynchronous operation to receive a message. |
![]() | BeginReceiveBatch(IEnumerable<Int64>, AsyncCallback, Object) | Begins an asynchronous operation to receive a batch of message. |
![]() | BeginReceiveBatch(Int32, AsyncCallback, Object) | Begins an asynchronous operation to receive a batch of message. |
![]() | BeginReceiveBatch(Int32, TimeSpan, AsyncCallback, Object) | Begins an asynchronous operation to receive a batch of message. |
![]() | Close | Closes the message client entity and puts its status into a closed state. (Inherited from MessageClientEntity.) |
![]() | CloseAsync | Asynchronously closes the message client entity and puts its status into a closed state. (Inherited from MessageClientEntity.) |
![]() | Complete | Completes the receive operation on a message. |
![]() | CompleteAsync | Asynchronously completes the receive operation on a message. |
![]() | CompleteBatch | Completes the receive operation on a batch of message. |
![]() | CompleteBatchAsync | Asynchronously completes the receive operation on a batch of message. |
![]() | DeadLetter(Guid) | Moves the undelivered message to the dead letter queue. |
![]() | DeadLetter(Guid, IDictionary<String, Object>) | Moves the undelivered message to the dead letter queue. |
![]() | DeadLetter(Guid, String, String) | Moves the undelivered message to the dead letter queue. |
![]() | DeadLetterAsync(Guid) | Asynchronously moves the undelivered message to the dead letter queue. |
![]() | DeadLetterAsync(Guid, IDictionary<String, Object>) | Asynchronously moves the undelivered message to the dead letter queue. |
![]() | DeadLetterAsync(Guid, String, String) | Asynchronously moves the undelivered message to the dead letter queue. |
![]() | Defer(Guid) | Indicates that the receiver wants to defer the processing for the message. |
![]() | Defer(Guid, IDictionary<String, Object>) | Indicates that the receiver wants to defer the processing for the message. |
![]() | DeferAsync(Guid) | Asynchronously defer the processing of the message. |
![]() | DeferAsync(Guid, IDictionary<String, Object>) | Asynchronously defer the processing of the message. |
![]() | EndAbandon | Ends the asynchronous operation to abandon the message and relinquish its lock. |
![]() | EndClose | Finishes an asynchronous operation to close the message client entity. (Inherited from MessageClientEntity.) |
![]() | EndComplete | Ends the asynchronous operation to complete receipt of a message. |
![]() | EndCompleteBatch | Ends the asynchronous operation to complete receipt of a batch message. |
![]() | EndDeadLetter | Ends an asynchronous operation to move the message to the dead letter queue. |
![]() | EndDefer | Ends an asynchronous operation to defer receipt of a message. |
![]() | EndPeek | Ends an asynchronous operation to peek a message. |
![]() | EndPeekBatch | Ends an asynchronous operation to peek a batch of message. |
![]() | EndReceive | Ends an asynchronous operation to receive a message. |
![]() | EndReceiveBatch | Ends an asynchronous operation to receive a batch of message. |
![]() | Equals | (Inherited from Object.) |
![]() | Fault | Puts the message client entity into a faulted state. (Inherited from MessageClientEntity.) |
![]() | Finalize | (Inherited from Object.) |
![]() | GetHashCode | (Inherited from Object.) |
![]() ![]() | GetLockToken | Gets the lock token bound to the message. |
![]() ![]() | GetLockTokens | Gets the collection of lock tokens from the specified collection of messages. |
![]() | GetType | (Inherited from Object.) |
![]() | MemberwiseClone | (Inherited from Object.) |
![]() | OnAbandon | Executes upon calling the Abandon operation. |
![]() | OnAbort | Executes upon calling the Abort operation. (Inherited from MessageClientEntity.) |
![]() | OnBeginAbandon | |
![]() | OnBeginClose | Executes upon calling the BeginClose operation. (Inherited from MessageClientEntity.) |
![]() | OnBeginComplete | |
![]() | OnBeginDeadLetter | |
![]() | OnBeginDefer | |
![]() | OnBeginOpen | Executes upon calling the operation to begin to open the message client entity. (Inherited from MessageClientEntity.) |
![]() | OnBeginPeek | Executes upon calling the BeginPeek operation. |
![]() | OnBeginRenewMessageLocks | |
![]() | OnBeginTryReceive(TrackingContext, IEnumerable<Int64>, TimeSpan, AsyncCallback, Object) | Executes upon calling the OnTryReceive or BeginTryReceive operation. |
![]() | OnBeginTryReceive(TrackingContext, Int32, TimeSpan, AsyncCallback, Object) | Executes upon calling the OnTryReceive or BeginTryReceive operation. |
![]() | OnBeginTryReceive2 | |
![]() | OnClose | Executes upon calling the Close operation. (Inherited from MessageClientEntity.) |
![]() | OnClosed | Occurs when the message client entity is transitioned into a closing state. (Inherited from MessageClientEntity.) |
![]() | OnComplete | Executes upon calling the Complete operation. |
![]() | OnDeadLetter | Executes upon calling the DeadLetter operation. |
![]() | OnDefer | Executes upon calling the Defer operation. |
![]() | OnEndAbandon | Executes the end abandon action. |
![]() | OnEndClose | Executes upon calling the EndClose operation. (Inherited from MessageClientEntity.) |
![]() | OnEndComplete | Executes the end complete action. |
![]() | OnEndDeadLetter | Executes the end move to dead letter queue action. |
![]() | OnEndDefer | Executes the end defer action. |
![]() | OnEndOpen | Executes upon calling the operation to end to open the message client entity. (Inherited from MessageClientEntity.) |
![]() | OnEndPeek | Executes the EndPeek operation. |
![]() | OnEndRenewMessageLocks | Executes the EndRenew action for message locks. |
![]() | OnEndTryReceive | Executes the end try receive action. |
![]() | OnEndTryReceive2 | |
![]() | OnFaulted | Executes upon calling the Fault operation. (Inherited from MessageClientEntity.) |
![]() | OnOpen | Executes upon calling the operation to open the message client entity. (Inherited from MessageClientEntity.) |
![]() | OnOpened | Executes when the message client entity is opened. (Inherited from MessageClientEntity.) |
![]() | OnPeek | Executes upon calling the Peek operation. |
![]() | OnRenewMessageLocks | Executes the Renew action for lock messages. |
![]() | OnRuntimeDescriptionChanged | (Inherited from MessageClientEntity.) |
![]() | OnTryReceive(TrackingContext, IEnumerable<Int64>, TimeSpan, IEnumerable<BrokeredMessage>) | Executes upon calling the TryReceive operation. |
![]() | OnTryReceive(TrackingContext, Int32, TimeSpan, IEnumerable<BrokeredMessage>) | Executes upon calling the TryReceive operation. |
![]() | Peek() | Reads the next message without changing the state of the receiver or the message source. |
![]() | Peek(Int64) | Reads the next message without changing the state of the receiver or the message source. |
![]() | PeekAsync() | Asynchronously reads the next message without changing the state of the receiver or the message source. |
![]() | PeekAsync(Int64) | Asynchronously reads the next message without changing the state of the receiver or the message source. |
![]() | PeekBatch(Int32) | Reads the next batch of message without changing the state of the receiver or the message source. |
![]() | PeekBatch(Int64, Int32) | Reads the next batch of message without changing the state of the receiver or the message source. |
![]() | PeekBatchAsync(Int32) | Asynchronously reads the next batch of message without changing the state of the receiver or the message source. |
![]() | PeekBatchAsync(Int64, Int32) | Asynchronously reads the next batch of message without changing the state of the receiver or the message source. |
![]() | Receive() | Receives a BrokeredMessage from the current queue or topic. |
![]() | Receive(Int64) | Receives a message from the current queue or topic. |
![]() | Receive(TimeSpan) | Receives a BrokeredMessage from the current queue or topic. |
![]() | ReceiveAsync() | Asynchronously receives a message from the current queue or topic. |
![]() | ReceiveAsync(Int64) | Asynchronously receives a message from the current queue or topic. |
![]() | ReceiveAsync(TimeSpan) | Asynchronously receives a message from the current queue or topic. |
![]() | ReceiveBatch(IEnumerable<Int64>) | Receives a batch of messages. |
![]() | ReceiveBatch(Int32) | Receives a batch of messages. |
![]() | ReceiveBatch(Int32, TimeSpan) | Receives a batch of messages. |
![]() | ReceiveBatchAsync(IEnumerable<Int64>) | Asynchronously receives a batch of messages. |
![]() | ReceiveBatchAsync(Int32) | Asynchronously receives a batch of messages. |
![]() | ReceiveBatchAsync(Int32, TimeSpan) | Asynchronously receives a batch of messages. |
![]() | ThrowIfClosed | Throws an exception if the message client entity is closed. (Inherited from MessageClientEntity.) |
![]() | ThrowIfDisposed | Throws an exception if the message client entity is disposed. (Inherited from MessageClientEntity.) |
![]() | ThrowIfDisposedOrImmutable | Throws an exception if the client is disposed or immutable. (Inherited from MessageClientEntity.) |
![]() | ThrowIfDisposedOrNotOpen | Throws an exception if the client is disposed or not open. (Inherited from MessageClientEntity.) |
![]() | ThrowIfFaulted | Throws an exception if the client is faulted. (Inherited from MessageClientEntity.) |
![]() | ToString | (Inherited from Object.) |
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(); }
