0
votes

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.

1
If my explanation did some help, could you accept it to close your question? Any confusion, just ask. - Jerry Liu
I am not talking about the CloudQueueMessage itself. When I debug my Function and hover over the string parameter that receives the message-queue data, the JSON string I receive is not the shape of the new POCO object - it is the shape of the old POCO object. It's like, internally, the Functions runtime is taking the JSON I pass to the CloudQueueMessage constructor and parsing it into an object - but the object it expects is the shape of the object when the queue was created. So it tried to create that kind of object and then put the JSON I provide into it, which does not work. - S. McChesney
Sorry for my poor comprehension, could you display the structure of old and new POCO object? IMO once we create a CloudQueueMessage with some string content, the content can only be modified by ourselves. The string parameter in Function method signature is supposed to get exactly the string content with no changes. - Jerry Liu

1 Answers

0
votes

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