IMessageReceiver Interface

Definition

The MessageReceiver can be used to receive messages from Queues and Subscriptions and acknowledge them.

public interface IMessageReceiver : Microsoft.Azure.ServiceBus.Core.IReceiverClient
type IMessageReceiver = interface
    interface IReceiverClient
    interface IClientEntity
Public Interface IMessageReceiver
Implements IReceiverClient
Derived
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).

Properties

LastPeekedSequenceNumber

Gets the sequence number of the last peeked message.

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.

(Inherited from IReceiverClient)
ReceiveMode

Gets the ReceiveMode of the current receiver.

(Inherited from IReceiverClient)

Methods

AbandonAsync(String, IDictionary<String,Object>)

Abandons a Message using a lock token. This will make the message available again for processing.

(Inherited from IReceiverClient)
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 queue.

(Inherited from IReceiverClient)
DeadLetterAsync(String, IDictionary<String,Object>)

Moves a message to the deadletter sub-queue.

(Inherited from IReceiverClient)
DeadLetterAsync(String, String, String)

Moves a message to the deadletter sub-queue.

(Inherited from IReceiverClient)
DeferAsync(String, IDictionary<String,Object>)

Indicates that the receiver wants to defer the processing for the message.

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)

Asynchronously reads the next message without changing the state of the receiver or the message source.

PeekBySequenceNumberAsync(Int64, Int32)

Peeks a batch of messages.

ReceiveAsync()

Receive a message from the entity defined by Microsoft.Azure.ServiceBus.Core.IReceiverClient.Path using ReceiveMode mode.

ReceiveAsync(Int32)

Receives a maximum of maxMessageCount messages from the entity defined by Microsoft.Azure.ServiceBus.Core.IReceiverClient.Path using ReceiveMode mode.

ReceiveAsync(Int32, TimeSpan)

Receives a maximum of maxMessageCount messages from the entity defined by Microsoft.Azure.ServiceBus.Core.IReceiverClient.Path using ReceiveMode mode.

ReceiveAsync(TimeSpan)

Receive a message from the entity defined by Microsoft.Azure.ServiceBus.Core.IReceiverClient.Path using ReceiveMode mode.

ReceiveDeferredMessageAsync(IEnumerable<Int64>)

Receives a System.Collections.Generic.IList`1 of deferred messages identified by sequenceNumbers.

ReceiveDeferredMessageAsync(Int64)

Receives a specific deferred message identified by sequenceNumber.

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(System.Func`3) is awaited on every time a new message is received by the receiver.

(Inherited from IReceiverClient)
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(System.Func`3) is awaited on every time a new message is received by the receiver.

(Inherited from IReceiverClient)
RenewLockAsync(Message)

Renews the lock on the message. 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.

Applies to

See also