[storage] Add support for deleting multiple queue messages in one request #102

Closed
prabirshrestha opened this Issue Jul 13, 2012 · 1 comment

Projects

None yet

4 participants

@prabirshrestha
Microsoft Azure member

I'm trying to implement an efficient algorithm for polling queue which can be found at https://gist.github.com/3093080

I can get a batch of messages using the follow code.

var messages = await Task.Factory.FromAsync>(queue.BeginGetMessages, queue.EndGetMessages, settings.DequeueMessageBatchSize, settings.MessageVisibilityTimeout, null, TaskCreationOptions.AttachedToParent);

Once I process this batch message, I would also like to delete all the messages in a batch.

Currently there is now way besides looping through all the messages. This causes multiple transactions rather then one and also requires use to increase the visibility timeout for the message depending on our batch message size just for deleting the messages.

private async static Task DeleteMessages(CloudQueuePollSettings settings, CloudQueue queue, IEnumerable messages)
{
    foreach (var message in messages)
    {
        int retryCount = settings.RetryCount;

        do
        {
            Exception exception = null;
            try
            {
                await Task.Factory.FromAsync(queue.BeginDeleteMessage, queue.EndDeleteMessage, message, null);
                break;
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            --retryCount;

            if (exception != null)
                await settings.OnError(queue, exception, message, retryCount == 0);

        } while (retryCount >= 0);
    }
}

I would recommend for a BeginDeleteMessages and EndDeleteMessages methods that would allow us to pass an IEnumerable.

But first the queue service api needs to support deleting batch of messages.

#102

@bradygaster bradygaster was assigned Dec 9, 2013
@stankovski
Microsoft Azure member

Please recreate in https://github.com/Azure/azure-storage-net/ if still relevant.

@stankovski stankovski closed this Oct 2, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment