简体   繁体   中英

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.

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM