Scenario:
How to use the Queue trigger to get the message from the queue and add that message details to the entity of Azure Table service within the storage account?
Exception:
Code: .NET 3.1 Azure Functions - Queue Trigger
Order.cs
csharp
namespace AzStorageQTriggerFunction
{
public class Order
{
// This will map to the Category property of the data
public string PartitionKey { get; set; }
// This will map to the Order ID property of the data
public string RowKey { get; set; }
public int Quantity { get; set; }
public decimal UnitPrice { get; set; }
}
}
QueueMessage.cs
csharp
using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Linq;
namespace AzStorageQTriggerFunction
{
public static class QueueMessage
{
[FunctionName("GetMessages")]
[return: Table("Orders", Connection = "storage-connectionstring")]
public static Order Run([QueueTrigger("appqueue", Connection = "storage-connectionstring")] JObject myQueueItem, ILogger log)
{
Order _order = new Order()
{
PartitionKey = myQueueItem["Category"].ToString(),
RowKey = myQueueItem["OrderID"].ToString(),
Quantity = Convert.ToInt32(myQueueItem["Quantity"]),
UnitPrice = Convert.ToDecimal(myQueueItem["UnitPrice"])
};
log.LogInformation("Order written to table");
return _order;
}
}
}
Add Message to the Queue:
JSON
{"Order ID":"01","Category":"Mobiles","Quantity":100,"UnitPrice":9.99}
Function running the queue trigger after passing message to the queue and getting exception while sending it to the Azure Table within the same storage account.
Could any of the community experts help me to resolve this exception and what is the reason of causing this?