我需要能够进入队列项本身(而不是字符串),以便可以从函数中进行操作。
在run.csx代码中运行漏洞,我可以访问CloudQueueMessage
#r "Microsoft.WindowsAzure.Storage"
using Microsoft.WindowsAzure.Storage.Queue;
using System;
public static void Run(CloudQueueMessage myQueueItem, ILogger log)
{
log.LogInformation($"Queue ID: {myQueueItem.Id}");
log.LogInformation($"Queue Insertion Time: {myQueueItem.InsertionTime}");
log.LogInformation($"Queue Expiration Time: {myQueueItem.ExpirationTime}");
log.LogInformation($"Queue Payload: {myQueueItem.AsString}");
}
在我的本地开发中,此代码引发错误。 我使用所有最新的Nuget。
VS2017 15.8.8
Azure功能和Web作业工具:15.10.2046.0
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using Microsoft.WindowsAzure.Storage.Queue;
namespace AzurePumps.MyForce
{
public static class PersonQueueProcessor
{
[FunctionName("PersonQueueProcessor")]
public static void Run([QueueTrigger("sfcontact-update-error", Connection = "storage-queue-connection")]CloudQueueMessage myQueueItem, ILogger log)
{
log.LogInformation($"Queue ID: {myQueueItem.Id}");
log.LogInformation($"Queue Insertion Time: {myQueueItem.InsertionTime}");
log.LogInformation($"Queue Expiration Time: {myQueueItem.ExpirationTime}");
log.LogInformation($"Queue Payload: {myQueueItem.AsString}");
}
}
}
日志:
Azure Functions Core Tools (2.1.748 Commit hash: 5db20665cf0c11bedaffc96d81c9baef7456acb3)
Function Runtime Version: 2.0.12134.0
Skipping 'SF_SecurityToken' from local settings as it's already defined in current environment variables.
[10/26/2018 8:07:51 PM] Building host: startup suppressed:False, configuration suppressed: False
[10/26/2018 8:07:52 PM] Reading host configuration file 'D:\Projects\Force\bin\Debug\netstandard2.0\host.json'
[10/26/2018 8:07:52 PM] Host configuration file read:
[10/26/2018 8:07:52 PM] {
[10/26/2018 8:07:52 PM] "version": "2.0"
[10/26/2018 8:07:52 PM] }
[10/26/2018 8:07:53 PM] Initializing Host.
[10/26/2018 8:07:53 PM] Host initialization: ConsecutiveErrors=0, StartupCount=1
[10/26/2018 8:07:53 PM] Starting JobHost
[10/26/2018 8:07:53 PM] Starting Host (HostId=vddk35x1fmsnlt-1608145051, InstanceId=e9842cc2-f4a1-46c2-80d0-3e0aad9ae83b, Version=2.0.12134.0, ProcessId=16720, AppDomainId=1, Debug=False, FunctionsExtensionVersion=)
[10/26/2018 8:07:53 PM] Loading functions metadata
[10/26/2018 8:07:53 PM] 2 functions loaded
[10/26/2018 8:07:54 PM] Generating 2 job function(s)
[10/26/2018 8:07:55 PM] Found the following functions:
[10/26/2018 8:07:55 PM] AzurePumps.MyForce.PersonProcessor.Run
[10/26/2018 8:07:55 PM] AzurePumps.MyForce.PersonQueueProcessor.Run
[10/26/2018 8:07:55 PM]
[10/26/2018 8:07:55 PM] Host initialized (1859ms)
[10/26/2018 8:08:00 PM] Host started (6876ms)
[10/26/2018 8:08:00 PM] Job host started
Hosting environment: Production
Content root path: D:\Projects\Force\bin\Debug\netstandard2.0
Now listening on: http://0.0.0.0:7071
Application started. Press Ctrl+C to shut down.
Listening on http://0.0.0.0:7071/
Hit CTRL-C to exit...
[10/26/2018 8:08:06 PM] Host lock lease acquired by instance ID '0000000000000000000000006DB263D8'.
[10/26/2018 8:08:22 PM] Executing 'PersonQueueProcessor' (Reason='New queue message detected on 'sfcontact-update-error'.', Id=1e37d3a4-a992-41c8-b6ca-595787e5224e)
[10/26/2018 8:08:23 PM] Executed 'PersonQueueProcessor' (Failed, Id=1e37d3a4-a992-41c8-b6ca-595787e5224e)
**[10/26/2018 8:08:23 PM] System.Private.CoreLib: Exception while executing function: PersonQueueProcessor. Microsoft.Azure.WebJobs.Host: Exception binding parameter 'myQueueItem'. Microsoft.Azure.WebJobs.Extensions.Storage: Binding parameters to complex objects (such as 'CloudQueueMessage') uses Json.NET serialization.
1. Bind the parameter type as 'string' instead of 'CloudQueueMessage' 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: i. Path '', line 0, position 0.**
答案 0 :(得分:1)
确保不参考/安装WindowsAzure.Storage
最新版本9.3.2,与Function SDK集成时似乎存在错误。请参阅跟踪的issue。
现在,当我们创建v2 Function Project时,模板中的依赖项,例如Microsoft.NET.SDK.Functions
默认引用WindowsAzure.Storage
9.3.1。此版本运行良好(如您在Azure门户中所见),无需单独安装该软件包。
此外,建议您将Microsoft.Azure.WebJobs.Extensions.Storage
更新为3.0.1,以避免引发一些首次机会异常。