在 azure 函数中绑定字符串输出队列时出错
Error binding string output queue in azure function
我正在使用 Azure 函数,试图让输出队列工作,但我一直 运行 遇到输出绑定错误。我想知道这是否与我装饰参数的方式有关?我已经看到如何使用单个队列作为 return 值来完成它,但我需要有多个输出队列。
函数定义:
using Microsoft.Azure.WebJobs; using Microsoft.Azure.WebJobs.Host; using Newtonsoft.Json; using Newtonsoft.Json.Linq;
namespace FunctionApp1 {
public static class TestItemAddQueueTrigger
{
[StorageAccount("AzureWebJobsStorage")]
[FunctionName("TestItemAddQueueTrigger")]
public static void Run([QueueTrigger("testitem-add")] string itemAdd,
TraceWriter log,
[Queue("testitem-added", Connection = "AzureWebJobsStorage")] out string itemAddedQueue)
{
dynamic message = JObject.Parse(itemAdd);
log.Info($"Received message\n{JsonConvert.SerializeObject(message, Formatting.Indented)}");
var itemAddedQueueMessage = new
{
};
itemAddedQueue = JsonConvert.SerializeObject(itemAddedQueueMessage);
log.Info($"Sent message to queue \"itemAddedQueue\"\n{JsonConvert.SerializeObject(itemAddedQueueMessage, Formatting.Indented)}");
}
} }
错误信息:
A ScriptHost error has occurred
[10/18/2017 4:31:27 PM] Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.TestItemAddQueueTrigger'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'itemAddedQueue' to type String&. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. config.UseServiceBus(), config.UseTimers(), etc.).
Nuget 引用:
Microsoft.NET.Sdk.Functions (1.0.6) Microsoft.Azure.WebJobs
(2.1.0-beta4) Microsoft.Azure.WebJobs.Extensions (2.1.0-beta4)
Microsoft.Azure.WebJobs.Extensions.Http (1.0.0-beta4) Newtonsoft.Json
(9.0.1) System.ValueTuple (4.3.0)
项目文件:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net47</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.6" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
解决方案文件:
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27004.2002
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FunctionApp1", "FunctionApp1\FunctionApp1.csproj", "{10F86A7D-5E03-41A9-8BBB-103C8E06E059}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{10F86A7D-5E03-41A9-8BBB-103C8E06E059}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{10F86A7D-5E03-41A9-8BBB-103C8E06E059}.Debug|Any CPU.Build.0 = Debug|Any CPU
{10F86A7D-5E03-41A9-8BBB-103C8E06E059}.Release|Any CPU.ActiveCfg = Release|Any CPU
{10F86A7D-5E03-41A9-8BBB-103C8E06E059}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B0A27606-232E-4B58-9586-12AB68E9CAC0}
EndGlobalSection
EndGlobal
I've seen how it can be done with using a single queue as a return value, but I have a need to have multiple output queues.
我使用了和你一样的功能包,并在我这边制作了一个测试demo。效果很好。
所以我建议你可以尝试创建一个新的功能项目并再次使用下面的代码测试。
这段代码有多个输出队列。它会自动将队列发送到 "output" 和 "output2"。
public static class Function1
{
[StorageAccount("AzureWebJobsStorage")]
[FunctionName("Function1")]
public static void Run([QueueTrigger("queue")]string myQueueItem,[Queue("output")] out string test2, [Queue("output2", Connection = "AzureWebJobsStorage")] out string itemAddedQueue, TraceWriter log)
{
log.Info($"C# Queue trigger function processed: {myQueueItem}");
dynamic message = JObject.Parse(myQueueItem);
log.Info($"Received message\n{JsonConvert.SerializeObject(message, Formatting.Indented)}");
var itemAddedQueueMessage = new test
{
name = "test"
};
itemAddedQueue = JsonConvert.SerializeObject(itemAddedQueueMessage);
test2 = JsonConvert.SerializeObject(itemAddedQueueMessage);
log.Info($"Sent message to queue \"itemAddedQueue\"\n{JsonConvert.SerializeObject(itemAddedQueueMessage, Formatting.Indented)}");
}
public class test
{
public string name { get; set; }
}
}
结果如下:
我能够通过从 npm 重新安装 azure 核心工具 1.x 来解决这个问题:npm install -g azure-functions-core-tools
这迫使 visual studio 重新安装 Azure Cli 工具,我的最佳猜测是某处存在版本冲突。
不幸的是,我不知道导致我的问题的根本原因或版本组合。
我正在使用 Azure 函数,试图让输出队列工作,但我一直 运行 遇到输出绑定错误。我想知道这是否与我装饰参数的方式有关?我已经看到如何使用单个队列作为 return 值来完成它,但我需要有多个输出队列。
函数定义:
using Microsoft.Azure.WebJobs; using Microsoft.Azure.WebJobs.Host; using Newtonsoft.Json; using Newtonsoft.Json.Linq;
namespace FunctionApp1 {
public static class TestItemAddQueueTrigger
{
[StorageAccount("AzureWebJobsStorage")]
[FunctionName("TestItemAddQueueTrigger")]
public static void Run([QueueTrigger("testitem-add")] string itemAdd,
TraceWriter log,
[Queue("testitem-added", Connection = "AzureWebJobsStorage")] out string itemAddedQueue)
{
dynamic message = JObject.Parse(itemAdd);
log.Info($"Received message\n{JsonConvert.SerializeObject(message, Formatting.Indented)}");
var itemAddedQueueMessage = new
{
};
itemAddedQueue = JsonConvert.SerializeObject(itemAddedQueueMessage);
log.Info($"Sent message to queue \"itemAddedQueue\"\n{JsonConvert.SerializeObject(itemAddedQueueMessage, Formatting.Indented)}");
}
} }
错误信息:
A ScriptHost error has occurred
[10/18/2017 4:31:27 PM] Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.TestItemAddQueueTrigger'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'itemAddedQueue' to type String&. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. config.UseServiceBus(), config.UseTimers(), etc.).
Nuget 引用:
Microsoft.NET.Sdk.Functions (1.0.6) Microsoft.Azure.WebJobs (2.1.0-beta4) Microsoft.Azure.WebJobs.Extensions (2.1.0-beta4)
Microsoft.Azure.WebJobs.Extensions.Http (1.0.0-beta4) Newtonsoft.Json (9.0.1) System.ValueTuple (4.3.0)
项目文件:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net47</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.6" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
解决方案文件:
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27004.2002
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FunctionApp1", "FunctionApp1\FunctionApp1.csproj", "{10F86A7D-5E03-41A9-8BBB-103C8E06E059}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{10F86A7D-5E03-41A9-8BBB-103C8E06E059}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{10F86A7D-5E03-41A9-8BBB-103C8E06E059}.Debug|Any CPU.Build.0 = Debug|Any CPU
{10F86A7D-5E03-41A9-8BBB-103C8E06E059}.Release|Any CPU.ActiveCfg = Release|Any CPU
{10F86A7D-5E03-41A9-8BBB-103C8E06E059}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B0A27606-232E-4B58-9586-12AB68E9CAC0}
EndGlobalSection
EndGlobal
I've seen how it can be done with using a single queue as a return value, but I have a need to have multiple output queues.
我使用了和你一样的功能包,并在我这边制作了一个测试demo。效果很好。
所以我建议你可以尝试创建一个新的功能项目并再次使用下面的代码测试。
这段代码有多个输出队列。它会自动将队列发送到 "output" 和 "output2"。
public static class Function1
{
[StorageAccount("AzureWebJobsStorage")]
[FunctionName("Function1")]
public static void Run([QueueTrigger("queue")]string myQueueItem,[Queue("output")] out string test2, [Queue("output2", Connection = "AzureWebJobsStorage")] out string itemAddedQueue, TraceWriter log)
{
log.Info($"C# Queue trigger function processed: {myQueueItem}");
dynamic message = JObject.Parse(myQueueItem);
log.Info($"Received message\n{JsonConvert.SerializeObject(message, Formatting.Indented)}");
var itemAddedQueueMessage = new test
{
name = "test"
};
itemAddedQueue = JsonConvert.SerializeObject(itemAddedQueueMessage);
test2 = JsonConvert.SerializeObject(itemAddedQueueMessage);
log.Info($"Sent message to queue \"itemAddedQueue\"\n{JsonConvert.SerializeObject(itemAddedQueueMessage, Formatting.Indented)}");
}
public class test
{
public string name { get; set; }
}
}
结果如下:
我能够通过从 npm 重新安装 azure 核心工具 1.x 来解决这个问题:npm install -g azure-functions-core-tools
这迫使 visual studio 重新安装 Azure Cli 工具,我的最佳猜测是某处存在版本冲突。
不幸的是,我不知道导致我的问题的根本原因或版本组合。