1

An Azure function has a Queue trigger, and the data coming from the Queue is serialized Json...i.e., the web app serializes object of type DataType1 and writes it to the Queue. The Azure function has to be able to resolve the namespace for DataType1 so it can deserialize it for use in the function.

What is the best practice for doing this? Some sort of helper library that both projects reference, with IDataType1? Is there any other way?

Mike
  • 1,010
  • 1
  • 14
  • 33
  • Use Json.Net to serialize/deserialize and just push json as string as message queue. – Thomas Jun 08 '19 at 09:05
  • I appreciate your input, but essentially that is what I'm trying to avoid. I want the Queue trigger message to be strongly typed so that I don't have to deserialize, that is done automatically and my message will already be in DataType1 format. My question is what is the best practice for both the web app and the function referencing that type. – Mike Jun 08 '19 at 13:04
  • You can have a shared libray if you are in control of both applications or define the class in both projects. – Thomas Jun 09 '19 at 01:08

1 Answers1

2

In your queue triggered function, you can have it pass you an already strongly typed object:

[QueueTrigger("%Queue%", Connection = "StorageConnectionString")] MyQueueItem myQueueItem, int dequeueCount

In C# and C# script, access the message data by using a method parameter such as string paramName. In C# script, paramName is the value specified in the name property of function.json. You can bind to any of the following types:

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

https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-queue#trigger---usage

Chris
  • 3,113
  • 5
  • 24
  • 46