You are developing an audit utility in C# that processes messages in an Azure Queue Storage queue named inventory-audit. The utility must read the content of up to 10 messages to log their metadata, but it must not lock the messages or make them invisible to other processing services. You are using the Azure.Storage.Queues SDK. Complete the code snippet below using explicit typing (do not use var) to retrieve the messages. Which code segments should you use to fill in the blanks?
Answer:QueueClient queueClient = new QueueClient(connectionString, "inventory-audit");
// Inspect up to 10 messages without changing their visibility
【PeekedMessage】[] messages = (await queueClient.【PeekMessagesAsync】(maxMessages: 10)).Value;
// Inspect up to 10 messages without changing their visibility
【PeekedMessage】[] messages = (await queueClient.【PeekMessagesAsync】(maxMessages: 10)).Value;
Answer
Use PeekedMessage for the array type in the first blank, and PeekMessagesAsync (or PeekMessages) for the queue client method in the second blank.
To inspect queue messages without acquiring a lease or modifying their visibility timeout, you must use the PeekMessagesAsync (or PeekMessages) method. This method returns a list of PeekedMessage objects, which represents the state of peeked messages (without pop receipt properties).
Step-by-Step Solution
Key Concept
Reading Azure Queue Storage messages without changing visibility (peeking)