MessageReceiver Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
The MessageReceiver can be used to receive messages from Queues and Subscriptions and acknowledge them.
public class MessageReceiver : Microsoft.Azure.ServiceBus.ClientEntity, Microsoft.Azure.ServiceBus.Core.IMessageReceiver
type MessageReceiver = class
inherit ClientEntity
interface IMessageReceiver
interface IReceiverClient
interface IClientEntity
Public Class MessageReceiver
Inherits ClientEntity
Implements IMessageReceiver
- Inheritance
- Implements
Examples
Create a new MessageReceiver to receive a message from a Subscription
IMessageReceiver messageReceiver = new MessageReceiver(
namespaceConnectionString,
EntityNameHelper.FormatSubscriptionPath(topicName, subscriptionName),
ReceiveMode.PeekLock);
Receive a message from the Subscription.
var message = await messageReceiver.ReceiveAsync();
await messageReceiver.CompleteAsync(message.SystemProperties.LockToken);
Remarks
The MessageReceiver provides advanced functionality that is not found in the QueueClient or SubscriptionClient. For instance, ReceiveAsync(), which allows you to receive messages on demand, but also requires you to manually renew locks using RenewLockAsync(Message). It uses AMQP protocol to communicate with service.
Constructors
MessageReceiver(ServiceBusConnection, String, ReceiveMode, RetryPolicy, Int32) |
Creates a new AMQP MessageReceiver on a given ServiceBusConnection |
MessageReceiver(ServiceBusConnectionStringBuilder, ReceiveMode, RetryPolicy, Int32) |
Creates a new MessageReceiver from a ServiceBusConnectionStringBuilder. |
MessageReceiver(String, String, ITokenProvider, TransportType, ReceiveMode, RetryPolicy, Int32) |
Creates a new MessageReceiver from a specified endpoint, entity path, and token provider. |
MessageReceiver(String, String, ReceiveMode, RetryPolicy, Int32) |
Creates a new MessageReceiver from a specified connection string and entity path. |
Properties
ClientId |
Gets the ID to identify this client. This can be used to correlate logs and exceptions. (Inherited from ClientEntity) |
IsClosedOrClosing |
Returns true if the client is closed or closing. (Inherited from ClientEntity) |
LastPeekedSequenceNumber |
Gets the sequence number of the last peeked message. |
OperationTimeout |
Duration after which individual operations will timeout. |
OwnsConnection |
Returns true if connection is owned and false if connection is shared. (Inherited from ClientEntity) |
Path |
The path of the entity for this receiver. For Queues this will be the name, but for Subscriptions this will be the path. |
PrefetchCount |
Prefetch speeds up the message flow by aiming to have a message readily available for local retrieval when and before the application asks for one using Receive. Setting a non-zero value prefetches PrefetchCount number of messages. Setting the value to zero turns prefetch off. Defaults to 0. |
ReceiveMode |
Gets the ReceiveMode of the current receiver. |
RegisteredPlugins |
Gets a list of currently registered plugins. |
RetryPolicy |
Gets the RetryPolicy defined on the client. (Inherited from ClientEntity) |
ServiceBusConnection |
Connection object to the service bus namespace. |
Methods
AbandonAsync(String, IDictionary<String,Object>) |
Abandons a Message using a lock token. This will make the message available again for processing. |
CloseAsync() |
Closes the Client. Closes the connections opened by it. (Inherited from ClientEntity) |
CompleteAsync(IEnumerable<String>) |
Completes a series of Message using a list of lock tokens. This will delete the message from the service. |
CompleteAsync(String) |
Completes a Message using its lock token. This will delete the message from the service. |
DeadLetterAsync(String, IDictionary<String,Object>) |
Moves a message to the deadletter sub-queue. |
DeadLetterAsync(String, String, String) |
Moves a message to the deadletter sub-queue. |
DeferAsync(String, IDictionary<String,Object>) |
Indicates that the receiver wants to defer the processing for the message. |
OnAbandonAsync(String, IDictionary<String,Object>) | |
OnClosingAsync() | |
OnCompleteAsync(IEnumerable<String>) | |
OnDeadLetterAsync(String, IDictionary<String,Object>, String, String) | |
OnDeferAsync(String, IDictionary<String,Object>) | |
OnMessageHandler(MessageHandlerOptions, Func<Message,CancellationToken,Task>) | |
OnPeekAsync(Int64, Int32) | |
OnReceiveAsync(Int32, TimeSpan) | |
OnReceiveDeferredMessageAsync(Int64[]) | |
OnRenewLockAsync(String) | |
PeekAsync() |
Fetches the next active message without changing the state of the receiver or the message source. |
PeekAsync(Int32) |
Fetches the next batch of active messages without changing the state of the receiver or the message source. |
PeekBySequenceNumberAsync(Int64, Int32) |
Peeks a batch of messages. |
PeekBySequenceNumberAsync(Int64) |
Asynchronously reads the next message without changing the state of the receiver or the message source. |
ReceiveAsync() |
Receive a message from the entity defined by Path using ReceiveMode mode. |
ReceiveAsync(Int32, TimeSpan) |
Receives a maximum of |
ReceiveAsync(Int32) |
Receives a maximum of |
ReceiveAsync(TimeSpan) |
Receive a message from the entity defined by Path using ReceiveMode mode. |
ReceiveDeferredMessageAsync(IEnumerable<Int64>) |
Receives a IList<T> of deferred messages identified by |
ReceiveDeferredMessageAsync(Int64) |
Receives a specific deferred message identified by |
RegisterMessageHandler(Func<Message,CancellationToken,Task>, Func<ExceptionReceivedEventArgs,Task>) |
Receive messages continuously from the entity. Registers a message handler and begins a new thread to receive messages. This handler(Func<T1,T2,TResult>) is awaited on every time a new message is received by the receiver. |
RegisterMessageHandler(Func<Message,CancellationToken,Task>, MessageHandlerOptions) |
Receive messages continuously from the entity. Registers a message handler and begins a new thread to receive messages. This handler(Func<T1,T2,TResult>) is awaited on every time a new message is received by the receiver. |
RegisterPlugin(ServiceBusPlugin) |
Registers a ServiceBusPlugin to be used with this receiver. |
RenewLockAsync(Message) |
Renews the lock on the message specified by the lock token. The lock will be renewed based on the setting specified on the queue. |
RenewLockAsync(String) |
Renews the lock on the message. The lock will be renewed based on the setting specified on the queue. New lock token expiry date and time in UTC format. |
ThrowIfClosed() |
Throw an OperationCanceledException if the object is Closing. (Inherited from ClientEntity) |
UnregisterMessageHandlerAsync(TimeSpan) |
Unregister message handler from the receiver if there is an active message handler registered. This operation waits for the completion of inflight receive and message handling operations to finish and unregisters future receives on the message handler which previously registered. |
UnregisterPlugin(String) |
Unregisters a ServiceBusPlugin. |
Applies to
Azure SDK for .NET