Compartilhar via


ServiceBusReceiver Class

Definition

The ServiceBusReceiver is responsible for receiving ServiceBusReceivedMessage and settling messages from Queues and Subscriptions. It is constructed by calling CreateReceiver(String, ServiceBusReceiverOptions).

public class ServiceBusReceiver : IAsyncDisposable
type ServiceBusReceiver = class
    interface IAsyncDisposable
Public Class ServiceBusReceiver
Implements IAsyncDisposable
Inheritance
ServiceBusReceiver
Derived
Implements

Remarks

The ServiceBusReceiver is safe to cache and use for the lifetime of an application or until the ServiceBusClient that it was created by is disposed. Caching the receiver is recommended when the application is consuming messages regularly or semi-regularly. The receiver is responsible for ensuring efficient network, CPU, and memory use. Calling DisposeAsync() on the associated ServiceBusClient as the application is shutting down will ensure that network resources and other unmanaged objects used by the receiver are properly cleaned up.

Constructors

ServiceBusReceiver()

Initializes a new instance of the ServiceBusReceiver class for mocking.

ServiceBusReceiver(ServiceBusClient, String, ServiceBusReceiverOptions)

Initializes a new instance of the ServiceBusReceiver class for use with derived types.

ServiceBusReceiver(ServiceBusClient, String, String, ServiceBusReceiverOptions)

Initializes a new instance of the ServiceBusReceiver class for use with derived types.

Properties

EntityPath

The path of the Service Bus entity that the receiver is connected to, specific to the Service Bus namespace that contains it.

FullyQualifiedNamespace

The fully qualified Service Bus namespace that the receiver is associated with. This is likely to be similar to {yournamespace}.servicebus.windows.net.

Identifier

A name used to identify the receiver client. If null or empty, a random unique value will be will be used.

IsClosed

Indicates whether or not this ServiceBusReceiver has been closed.

PrefetchCount

The number of messages that will be eagerly requested from Queues or Subscriptions and queued locally without regard to whether a processing is currently active, intended to help maximize throughput by allowing the receiver to receive from a local cache rather than waiting on a service request

ReceiveMode

The ReceiveMode used to specify how messages are received.

Methods

AbandonMessageAsync(ServiceBusReceivedMessage, IDictionary<String,Object>, CancellationToken)

Abandons a ServiceBusReceivedMessage.This will make the message available again for immediate processing as the lock on the message held by the receiver will be released.

CloseAsync(CancellationToken)

Performs the task needed to clean up resources used by the ServiceBusReceiver.

CompleteMessageAsync(ServiceBusReceivedMessage, CancellationToken)

Completes a ServiceBusReceivedMessage. This will delete the message from the service.

DeadLetterMessageAsync(ServiceBusReceivedMessage, IDictionary<String,Object>, CancellationToken)

Moves a message to the dead-letter subqueue.

DeadLetterMessageAsync(ServiceBusReceivedMessage, IDictionary<String,Object>, String, String, CancellationToken)

Moves a message to the dead-letter subqueue.

DeadLetterMessageAsync(ServiceBusReceivedMessage, String, String, CancellationToken)

Moves a message to the dead-letter subqueue.

DeferMessageAsync(ServiceBusReceivedMessage, IDictionary<String,Object>, CancellationToken)

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

DeleteMessagesAsync(Int32, Nullable<DateTimeOffset>, CancellationToken)

Deletes up to messageCount messages from the entity. The actual number of deleted messages may be less if there are fewer eligible messages in the entity.

DisposeAsync()

Performs the task needed to clean up resources used by the ServiceBusReceiver. This is equivalent to calling CloseAsync(CancellationToken).

PeekMessageAsync(Nullable<Int64>, CancellationToken)

Fetches the next active ServiceBusReceivedMessage without changing the state of the receiver or the message source.

PeekMessagesAsync(Int32, Nullable<Int64>, CancellationToken)

Fetches a list of active messages without changing the state of the receiver or the message source.

PurgeMessagesAsync(Nullable<DateTimeOffset>, CancellationToken)

Attempts to purge all messages from an entity. Locked messages are not eligible for removal and will remain in the entity.

ReceiveDeferredMessageAsync(Int64, CancellationToken)

Receives a deferred message identified by sequenceNumber.

ReceiveDeferredMessagesAsync(IEnumerable<Int64>, CancellationToken)

Receives a list of deferred messages identified by sequenceNumbers.

ReceiveMessageAsync(Nullable<TimeSpan>, CancellationToken)

Receives a ServiceBusReceivedMessage from the entity using ReceiveMode mode. ReceiveMode defaults to PeekLock mode.

ReceiveMessagesAsync(CancellationToken)

Receives messages as an asynchronous enumerable from the entity using ReceiveMode mode. ReceiveMode defaults to PeekLock mode. Messages will be received from the entity as the IAsyncEnumerable is iterated. If no messages are available, this method will continue polling until messages are available, i.e. it will never return null.

ReceiveMessagesAsync(Int32, Nullable<TimeSpan>, CancellationToken)

Receives a list of ServiceBusReceivedMessage from the entity using ReceiveMode mode. ReceiveMode defaults to PeekLock mode. This method doesn't guarantee to return exact maxMessages messages, even if there are maxMessages messages available in the queue or topic.

RenewMessageLockAsync(ServiceBusReceivedMessage, CancellationToken)

Renews the lock on the message. The lock will be renewed based on the setting specified on the queue.

Applies to