绑定到Azure Functions中的自定义队列触发器字段

时间:2017-07-12 14:38:08

标签: azure azure-functions azure-functions-runtime

我一直在努力根据队列触发器中的数据定义表/ blob输出绑定。我意识到我可以通过代码中的命令式绑定来实现这一点,但我认为这也应该可以通过functions.json中的绑定来实现。我以为我已经解决了这个问题,但我现在遇到一个奇怪的运行时错误,我无法通过搜索找到任何信息。

这是我正在使用的functions.json定义:

{
  "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
}

这是我的Run语句:

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

最后,我尝试用于绑定的自定义队列消息:

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

以上所有编译成功,但在运行时我收到以下错误消息。我不确定如何继续 - 其他在线绑定自定义队列消息的例子似乎没有遇到这种类型的错误。欢迎任何建议!

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.
.

发生错误时消息队列的内容是:

{
  "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"
}

1 个答案:

答案 0 :(得分:0)

我无法重述您提到的问题。以下是我的详细步骤,希望它能帮助您解决问题。

1.从Azure门户创建QueueTrigger

enter image description here

2.在run.csx文件中添加以下代码

#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.我使用了你提到的functions.json定义。

4.从Azure门户网站

进行测试

enter image description here

相关问题