ServiceBusReceiver.PurgeMessagesAsync Method

Definition

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

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

Parameters

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.

Remarks

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

This method may invoke multiple service requests to delete all messages. As a result, it may exceed the configured TryTimeout. If you need control over the amount of time the operation takes, it is recommended that you pass a cancellationToken with the desired timeout set for cancellation.

Because multiple service requests may be made, the possibility of partial success exists. In this scenario, the method will stop attempting to delete additional messages and throw the exception that was encountered. It is recommended to evaluate this exception and determine which messages may not have been deleted.

Applies to