MessageReceiver Class
Receives messages from the message container and acknowledges them. . 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 without knowing whether it is a topic or a queue.
System.Object
Microsoft.ServiceBus.Messaging.MessageClientEntity
Microsoft.ServiceBus.Messaging.MessageReceiver
Microsoft.ServiceBus.Messaging.MessageSession
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.) |
|
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. |
| Name | Description | |
|---|---|---|
|
Abandon | 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 | 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. |
|
BeginDeadLetter(Guid, 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 | Begins an asynchronous operation to suspend receipt of a 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. |
|
Close | Closes the message client entity and puts its status into a closed state. (Inherited from MessageClientEntity.) |
|
Complete | Completes the receive operation on a message. |
|
DeadLetter(Guid) | Moves the undelivered message to the dead letter queue. |
|
DeadLetter(Guid, String, String) | Moves the undelivered message to the dead letter queue. |
|
Defer | Indicates that the receiver wants to defer the processing for 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. |
|
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. |
|
EndReceive | Ends an asynchronous operation to receive a 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 | Executes upon calling the OnAbandon or BeginAbandon operation. |
|
OnBeginClose | Executes upon calling the BeginClose operation. (Inherited from MessageClientEntity.) |
|
OnBeginComplete | Executes upon calling the OnComplete or BeginComplete operation. |
|
OnBeginDeadLetter | Executes upon calling the OnDeadLetter or BeginDeadLetter operation. |
|
OnBeginDefer | Executes upon calling the OnDefer or BeginDefer operation. |
|
OnBeginOpen | Executes upon calling the operation to begin to open the message client entity. (Inherited from MessageClientEntity.) |
|
OnBeginTryReceive(TrackingContext, IEnumerable(Of 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. |
|
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.) |
|
OnEndTryReceive | Executes the end try receive action. |
|
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.) |
|
OnTryReceive(TrackingContext, IEnumerable(Of Int64), TimeSpan, IEnumerable(Of BrokeredMessage)) | Executes upon calling the TryReceive operation. |
|
OnTryReceive(TrackingContext, Int32, TimeSpan, IEnumerable(Of BrokeredMessage)) | Executes upon calling the TryReceive operation. |
|
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. |
|
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.) |
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: 0, seconds: 5))) != null) { Console.WriteLine( string.Format( "Message received: Id = {0}, Body = {1}", message.MessageId, message.GetBody<string>())); message.Complete(); }
