0

I've been struggling to define table/blob output bindings based on data in a queue trigger. I realize I could accomplish this with imperative binding in code, but I think this should also be possible via the bindings in functions.json. I thought I'd solved this, but am now getting a strange runtime error which I cannot find any information on via searching.

Here's the functions.json definition I am using:

{
  "bindings": [
    {
      "name": "myQueueItem",
      "type": "queueTrigger",
      "direction": "in",
      "queueName": "w2pdfqueue",
      "connection": "xxxxxxxx"
    },
    {
      "type": "table",
      "name": "FW2Table",
      "tableName": "FW2",
      "take": 1,
      "connection": "xxxxxxxxx",
      "direction": "in",
      "partitionKey": "{PartitionKey}",
      "rowKey": "{RowKey}"
    },
    {
      "type": "blob",
      "name": "outputBlob",
      "path": "{ClientID}/{ResourceID}",
      "connection": "xxxxxxxxxx",
      "direction": "inout"
    }
  ],
  "disabled": false
}

And here is the Run statement I have:

public static void Run(W2QueueItem myQueueItem, TraceWriter log, W2Row FW2Table, CloudBlockBlob outputBlob)

Finally, the custom queue message I am trying to use for binding:

public class W2QueueItem 
{
    public string PartitionKey { get; set; }
    public string RowKey { get; set; }
    public string ClientID { get; set; }
    public string ResourceID { get; set; }
}

All of the above compiles successfully, however at runtime I am getting the following error message. I'm not sure how to proceed -- other examples online of binding to custom queue messages do not seem to encounter this type of error. Any suggestions would be welcome!

ost: Binding parameters to complex objects (such as 'W2QueueItem') uses Json.NET serialization. 
1. Bind the parameter type as 'string' instead of 'W2QueueItem' to get the raw values and avoid JSON deserialization, or
2. Change the queue payload to be valid json. The JSON parser failed: Unexpected character encountered while parsing value: s. Path '', line 0, position 0.
.

The contents of the message queue when the error occurs are:

{
  "PartitionKey": "d6a2e537-a0a0-4949-a6fd-2e56723cdaf0",
  "RowKey": "1|053e3136-048d-417b-94c0-6339d3b9c835",
  "ClientID": "ef1de151-9855-54d7-4598-6ee416dc5a51",
  "ResourceID": "a33efdd2-45ae-47ee-bc56-55b431468962",
  "$AzureWebJobsParentId": "e1337646-5f0f-44e4-86fe-e6a46589a739"
}
  • Out of curiosity are you able to make the change to take in the raw string and then post what the string looks like here? It would help to be able to say why deserialization might be failing – Jesse Carter Jul 12 '17 at 14:47
  • Here's the content of the queue message for the test data I am running when the error occurs: { "PartitionKey": "d6a2e537-a0a0-4949-a6fd-2e56723cdaf0", "RowKey": "1|053e3136-048d-417b-94c0-6339d3b9c835", "ClientID": "ef1de151-9855-54d7-4598-6ee416dc5a51", "ResourceID": "a33efdd2-45ae-47ee-bc56-55b431468962", "$AzureWebJobsParentId": "e1337646-5f0f-44e4-86fe-e6a46589a739" } – user1943819 Jul 12 '17 at 14:50
  • Do you get the same problem when testing from `Test` tab in the portal? I tried your class and message, seems to go fine. – Mikhail Shilkov Jul 12 '17 at 15:16
  • Another guess, what happens if you use a json string message payload, i.e. `"{ \"PartitionKey\": ...}"`? – Matt Mason Jul 12 '17 at 18:11
  • I am running this code in the test tab of the portal - so that is where I am seeing the issue. From an earlier suggestion, I have tried outputting what is getting bound to myQueueItem and have what looks a bit strange. Here's the code: log.Info($"PDFMergeStore Fired For: {myQueueItem}"); And here's the result: 2017-07-13T13:06:51.883 PDFMergeStore Fired For: Submission#0+W2QueueItem – user1943819 Jul 13 '17 at 13:12

1 Answers1

0

I cannot repro the issue that you mentioned. The following is my detail steps, hope it will help you work it out.

1.Create a QueueTrigger from Azure portal

enter image description here

2.Add the following code in the run.csx file

#r "Microsoft.WindowsAzure.Storage"
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using Microsoft.WindowsAzure.Storage.Table;
using System;
public static void Run(W2QueueItem myQueueItem, TraceWriter log, W2Row FW2Table,CloudBlockBlob outputBlob)
{  
     log.Info($"C# Queue trigger function processed: {myQueueItem.ClientID}");
}
public class W2QueueItem 
{
    public string PartitionKey { get; set; }
    public string RowKey { get; set; }
    public string ClientID { get; set; }
    public string ResourceID { get; set; }
}

public class W2Row: TableEntity
{
   public W2Row() { }
}

3.I used the functions.json definition as you mentioned.

4.Test it from Azure portal

enter image description here

Tom Sun - MSFT
  • 24,161
  • 3
  • 30
  • 47