Search code examples
azure-storageazure-functionsazure-queuesqueuetrigger

Reading a message in Azure storage queue multiple times


Context: I have an Azure storage queue that is used as the input queue for a Queue Trigger Function. So, whenever a message gets added to the queue, some function X is triggered and starts running. I want to test that the message was successfully put in the queue and consumed. How can I do that from the queue only (assuming I do not have visibility into my function X, and I can not change the settings for the Queue Trigger Function)? To further break down this question:

  • After the Queue Trigger Function dequeues the message, would the message still be available for me to read from it when testing? If yes, how can I access it?
  • Since there is a race condition here, if I dequeue the message when testing before the Queue Trigger Function gets to do it, how would that interfere with the function of the Queue Trigger? Is it possible to dequeue the message when testing, but at the same time, have it available for Queue Trigger to dequeue it and trigger my function X with no interference at all?
  • Bottom line, I have a queue message in Azure storage queue that I want to read twice from two different sources, with no interference between the two operations. Is this possible and supported? If yes, how can I do it?

Thanks!


Solution

  • I don't think the way you're trying to do this will work. You can get part of the way by using Peek Messages to read queue messages without dequeuing them, but if the Function gets to a message before you then you'll never see it in the first place.

    However, you might might be able to get the information you need by using Storage Analytics Logging to track queue activity, or by using Service Bus topics instead of a queue so your messages can have multiple subscribers.