Ian Knowles
Ian Knowles

Reputation: 63

Azure Storage Queue - message Id

Is there a way of getting the message id (guid string) when you add a message to an Azure message queue?

            var storageAccount = CloudStorageAccount.Parse(Storage.ConnectionString);
            var queueClient = storageAccount.CreateCloudQueueClient();
            var messageQueue = queueClient.GetQueueReference(Storage.Queue.Property);

            await messageQueue.AddMessageAsync(message: new CloudQueueMessage(message)
                , timeToLive: TimeSpan.MaxValue
                , initialVisibilityDelay: null
                , options: null
                , operationContext: null);

            // How do I get message Id

I need to be able to create a log of whats in the queue and at the time of adding an item to the queue and the message id seams to be Azure internally created with no way of passing as an option.

Upvotes: 2

Views: 1103

Answers (1)

Peter Bons
Peter Bons

Reputation: 29840

Sure, no problem. Just read the Id property of the message after sending it:

            var storageAccount = CloudStorageAccount.Parse(Storage.ConnectionString);
            var queueClient = storageAccount.CreateCloudQueueClient();
            var messageQueue = queueClient.GetQueueReference(Storage.Queue.Property);

            var queueMessage = new CloudQueueMessage(message);

            await messageQueue.AddMessageAsync(message: queueMessage 
                , timeToLive: TimeSpan.MaxValue
                , initialVisibilityDelay: null
                , options: null
                , operationContext: null);

            // How do I get message Id
            Console.WriteLine(queueMessage.Id);

Upvotes: 3

Related Questions