我做错了什么或者如何让它发挥作用? 我正在使用 Azure Runtime v1(需要使用 .NET Framework,而不是 core)。
Visual Studio中的函数代码如下:
// This is the default URL for triggering event grid function in the local environment.
// http://localhost:7071/admin/extensions/EventGridExtensionConfig?functionName={functionname}
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Azure.WebJobs.Extensions.EventGrid;
namespace FunctionApp1
{
public static class Function1
{
[FunctionName("Function1")]
public static void Run([EventGridTrigger]Microsoft.Azure.EventGrid.Models.EventGridEvent eventGridEvent, TraceWriter log)
{
log.Info(eventGridEvent.Data.ToString());
}
}
}
当我尝试添加该功能的订阅时,无论是通过门户还是 cli,我都会收到以下错误:
PS Azure:\> az eventgrid event-subscription create -g [<myGroupName>] --topic-name data-generated --name Func1Subs --endpoint "https://[<myFunctionAppName>].azurewebsites.net/admin/extensions/EventGridExtensionConfig?functionName=Function1&code=[<code>]"
Argument 'resource_group_name' has been deprecated and will be removed in version '2.1.0'. Use '--source-resource-id' instead.
Argument 'topic_name' has been deprecated and will be removed in version '2.1.0'. Use '--source-resource-id' instead.
The attempt to validate the provided endpoint https://[<myFunctionAppName>].azurewebsites.net/admin/extensions/EventGridExtensionConfig failed. For more details, visit https://aka.ms/esvalidation.
我尝试了从https://[<myFunctionAppName>].azurewebsites.net/admin/host/systemkeys/eventgridextensionconfig_extension?code=[<master_key>]
上的GET请求获得的两个系统代码、默认 key 甚至主 key 本身 - 相同的结果。
使用门户上的按钮“添加事件网格订阅”时 - 我也在通知框中收到此错误。
当我在门户上创建功能时 - 创建订阅工作正常。
此外,当我将 .netcore 函数部署到 2.x 运行时时 - 并使用门户按钮创建订阅 - 这也可以正常工作。但就像我说的 - 我想使用运行时 1.x 来部署 .NETFramework 功能。
最佳答案
我在这里复制了这个和一些观察结果
如果我使用默认函数签名,它工作正常
namespace FunctionApp7
{
public static class Function1
{
[FunctionName("Function1")]
public static void Run([EventGridTrigger]JObject eventGridEvent, TraceWriter log)
{
log.Info(eventGridEvent.ToString(Formatting.Indented));
}
}
}
但是当我使用您提到的签名时,我在创建事件订阅时遇到错误。我还需要添加 nuget 包以便进行以下编译 Microsoft.Azure.EventGrid 3.0.0
namespace FunctionApp10
{
public static class Function1
{
[FunctionName("Function1")]
public static void Run([EventGridTrigger]Microsoft.Azure.EventGrid.Models.EventGridEvent eventGridEvent, TraceWriter log)
{
log.Info(eventGridEvent.Data.ToString());
}
}
}
看看下面的链接
https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-event-grid
以下签名不适用于V1函数
public static void Run([EventGridTrigger]Microsoft.Azure.EventGrid.Models.EventGridEvent eventGridEvent, TraceWriter log)
关于c# - Azure Functions Runtime v1 EventGrid 订阅创建失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54462432/