Compartir a través de


ServiceBusReceiver.DeleteMessagesAsync Method

Definition

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.

public virtual System.Threading.Tasks.Task<int> DeleteMessagesAsync (int messageCount, DateTimeOffset? beforeEnqueueTime = default, System.Threading.CancellationToken cancellationToken = default);
abstract member DeleteMessagesAsync : int * Nullable<DateTimeOffset> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<int>
override this.DeleteMessagesAsync : int * Nullable<DateTimeOffset> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<int>
Public Overridable Function DeleteMessagesAsync (messageCount As Integer, Optional beforeEnqueueTime As Nullable(Of DateTimeOffset) = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of Integer)

Parameters

messageCount
Int32

The desired number of messages to delete. This value is limited by the service and governed Service Bus quotas. The service may delete fewer messages than this limit.

beforeEnqueueTime
Nullable<DateTimeOffset>

An optional DateTimeOffset, in UTC, representing the cutoff time for deletion. Only messages that were enqueued before this time will be deleted. If not specified, UtcNow will be assumed.

cancellationToken
CancellationToken

An optional CancellationToken instance to signal the request to cancel the operation.

Returns

The number of messages that were deleted.

Exceptions

Occurs when the messageCount is less than 1 or exceeds the maximum allowed, as determined by the Service Bus service. For more information on service limits, see https://learn.microsoft.com/azure/service-bus-messaging/service-bus-quotas#messaging-quotas.

Remarks

If the lock for a message is held by a receiver, it will be respected and the message will not be deleted.

Applies to