【发布时间】:2017-07-12 14:38:08
【问题描述】:
我一直在努力根据队列触发器中的数据定义表/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
}
这是我的运行语句:
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"
}
【问题讨论】:
-
出于好奇,您能否进行更改以获取原始字符串,然后在此处发布字符串的样子?能够说明为什么反序列化可能会失败会有所帮助
-
出现错误时我正在运行的测试数据的队列消息的内容如下: { "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", "$AzureWebJobsParId:" e1337646-5f0f-44e4-86fe-e6a46589a739" }
-
从门户中的
Test选项卡进行测试时是否遇到同样的问题?我试过你的课程和留言,似乎还不错。 -
另一种猜测,如果你使用 json 字符串消息负载会发生什么,即
"{ \"PartitionKey\": ...}"? -
我在门户的测试选项卡中运行此代码 - 所以这就是我看到问题的地方。根据较早的建议,我尝试输出绑定到 myQueueItem 的内容,并且看起来有些奇怪。这是代码: log.Info($"PDFMergeStore Fired For: {myQueueItem}");结果如下:2017-07-13T13:06:51.883 PDFMergeStore 为:Submission#0+W2QueueItem
标签: azure azure-functions azure-functions-runtime