Question

Difficulty: MediumImplement Azure Queue Storage Solutions

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;

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

1
Determine the message retrieval requirement.
The utility needs to read messages without locking them or making them invisible to other consumers.
This requirement indicates that a peek operation must be used instead of a standard receive operation.
2
Select the correct SDK method.
The Azure.Storage.Queues SDK provides the PeekMessagesAsync method (or synchronous PeekMessages) to read messages without modifying their visibility timeout.
ReceiveMessagesAsync would retrieve the messages and set a visibility timeout, locking them from other consumers.
3
Select the correct return type.
The PeekMessagesAsync method returns a collection of PeekedMessage objects rather than QueueMessage objects.
PeekedMessage represents messages that have been peeked and do not contain lease-specific properties like a PopReceipt.

Key Concept

Reading Azure Queue Storage messages without changing visibility (peeking)
Rate this question