Azure函数由具有输入数据存储绑定的队列触发

时间:2017-10-09 12:09:43

标签: c# azure azure-storage azure-functions

我正在尝试为队列触发功能提供输入数据存储绑定。

VTRequest是一个被推送到队列的对象,而VTEntity是一个保存在数据库中的对象。

这个如果是function.json

cp

这是我得到的错误日志:

{
  "bindings": [
    {
      "name": "vtAPIRequest",
      "type": "queueTrigger",
      "direction": "in",
      "queueName": "vtqueue",
      "connection": "vt_STORAGE"
    },
    {
      "type": "table",
      "name": "outVTAPIDataTable",
      "tableName": "data",
      "connection": "vt_STORAGE",
      "direction": "out"
    },
    {
      "type": "table",
      "name": "vtDataRow",
      "tableName": "VTData",
      "partitionKey": "VT",
      "rowKey": "{queueTrigger}.{hash}",
      "take": 1,
      "connection": "vt_STORAGE",
      "direction": "in"
    }
  ],
  "disabled": false
}

using System;


public class VTEntity {

    public string PartitionKey { get; set; }
    public String RowKey { get; set; }
    public string hash { get; set; }
    public string userID { get; set; }    
}



public class VTRequest {

    public string hash { get; set; }
    public string userID { get; set; }    
}


public static void Run(VTRequest vtAPIRequest, VTEntity vtDataRow, 
        TraceWriter log, IAsyncCollector<VTEntity> outVTAPIDataTable) {


    if(null != vtDataRow) {
       .....
    }

}

我确实在相关的db中有这条记录:

enter image description here

我想查询数据库中队列对象传递的哈希值2017-10-09T12:06:07.840 Exception while executing function: Functions.VTAPIQueue. Microsoft.Azure.WebJobs.Host: Exception binding parameter 'vtDataRow'. Microsoft.Azure.WebJobs.Host: '{ "hash": "asdasdasd", "userID": "123456789", "$AzureWebJobsParentId": "1f31be54-ec0d-4f0d-a4aa-45513d038f7e" }.asdasdasd' is not a valid value for a partition key or row key. 2017-10-09T12:06:07.887 Function completed (Failure, Id=29268e32-0545-49c9-9f15-268d90de54cc, Duration=115ms)

有办法吗?

1 个答案:

答案 0 :(得分:2)

你几乎就在那里,只需将rowKey的绑定更改为

"rowKey": "{hash}",