S. McChesney
S. McChesney

Reputation: 151

Azure Storage Queues and Message Shape

I have looked around and searched, and I cannot find anything addressing this, so if my Google Fu has failed me, please just point me in the right direction.

We are using Azure Storage Queues to trigger execution of Azure Functions (V2). (I don't believe that this usage is relevant, but I'm including it just in case.) Over the course of developing the Function, the "shape" of the input data changed (I'm using C# POCO objects and serializing them to JSON to create the queue message content.)

What I discovered was that after pushing the code changes out to Azure, the Storage Queue was continuing to send the JSON message to the Function in the old object JSON format - even though the JSON provided to the Storage Queue was in the new format.

The fix was simple enough - delete the queue and let the code re-create it. However, there's a lot of confusion here:

  1. Azure Storage Queues take messages as string values, so why is a "schema" being attached at all? I realize the message is ultimately provided in a CloudQueueMessage object, so there is probably some sort of JSON goodness happening behind the scenes. But...
  2. If there is one (and there sure appears to be one), why would the Storage Queue accept and successfully process a message that does not match that format? If anything, I would have expected the message to end up in the poison queue, rather than some attempt to "translate" the incoming message into the schema.
  3. Is there a way to deal with this "in code" (other than writing a bunch of my own code to "check the schema")?
  4. What would have happened had I provided a simple string value? (This is really more curiosity for me than anything else...)

Any answers anyone can provide/point me to would be greatly appreciated.

Upvotes: 0

Views: 1288

Answers (1)

Jerry Liu
Jerry Liu

Reputation: 17790

You probably mistake message content with CloudQueueMessage object.

What we usually handle in code is message content/text/body containing the information we want to process. In your case, i.e. C# POCO and the serialized Json payload.

When we create a queue message in Azure Storage Queue, several properties are populated by Azure. CloudQueueMessage object is composed of message content and these properties. They are used to control how queue messages behave when we process its content, check the doc for their usage.

    public static long MaxMessageSize { get; }
    public static TimeSpan MaxVisibilityTimeout { get; }
    public static int MaxNumberOfMessagesToPeek { get; }
    public string Id { get; }
    public string PopReceipt { get; }
    public DateTimeOffset? InsertionTime { get; }
    public DateTimeOffset? ExpirationTime { get; }
    public DateTimeOffset? NextVisibleTime { get; }
    public int DequeueCount { get; }

As for the message content itself, it can be a string or byte array. When Azure Function receives the message, we have several options how queue message are populated, the first three take message content only.

  • Object - The Functions runtime deserializes a JSON payload into an instance of an arbitrary class defined in your code.
  • string
  • byte[]
  • CloudQueueMessage

Upvotes: 0

Related Questions