Azure Functions Runtime v1 EventGrid 订阅创建失败
Azure Functions Runtime v1 EventGrid Subscription create fails
我做错了什么或如何让它发挥作用?
我正在使用 Azure Runtime v1(需要使用 .NET Framework,而不是核心)。
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 请求获得的系统代码、默认密钥甚至主密钥本身 - 结果相同。
当使用门户上的按钮时 "Add Event Grid subscription" - 我也在通知框中收到此错误。
当我在门户网站上创建功能时 - 创建订阅工作正常。
此外,当我将 .netcore 函数部署到 2.x 运行时 - 并使用门户按钮创建订阅时 - 这也能正常工作。但正如我所说 - 我想使用运行时 1.x 来部署 .NETFramework 函数。
您可以使用 Postman 验证 Azure 事件网格订阅者的 EventGridTrigger 函数,请参阅以下内容:
请求Url:
POST https://{myFuncApp}.azurewebsites.net/admin/extensions/EventGridExtensionConfig?functionName={myEventGridTriggerFnc}&code={_masterKey}
Header:
aeg-event-type: SubscriptionValidation
Body:
[{
"id": "123",
"subject": "abc",
"eventType": "xxx",
"eventTime": "2019-01-31T16:17:37.1080645Z",
"data": {
"validationCode": "xxxxxxxxxxxxx",
"validationUrl": ""
},
"dataVersion": "0",
"metadataVersion": "1",
"topic": "xxxx"
}]
成功响应会return:
{"validationResponse":"xxxxxxxxxxxxx"}
备注:
- 可以从门户yourFunction/Integrate、属性复制请求Url 事件网格订阅URL
- 在手动创建请求 Url 的情况下,使用门户 yourFunction/Manage 页面中的 _master 键。
- 要测试函数 body,请使用 header 'aeg-event-type: Notification'
我在这里转载了这个和一些观察结果
如果我使用默认函数签名,它工作正常
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.EventGrid3.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());
}
}
}
看看下面的link
https://docs.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)
我做错了什么或如何让它发挥作用? 我正在使用 Azure Runtime v1(需要使用 .NET Framework,而不是核心)。
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 请求获得的系统代码、默认密钥甚至主密钥本身 - 结果相同。
当使用门户上的按钮时 "Add Event Grid subscription" - 我也在通知框中收到此错误。
当我在门户网站上创建功能时 - 创建订阅工作正常。
此外,当我将 .netcore 函数部署到 2.x 运行时 - 并使用门户按钮创建订阅时 - 这也能正常工作。但正如我所说 - 我想使用运行时 1.x 来部署 .NETFramework 函数。
您可以使用 Postman 验证 Azure 事件网格订阅者的 EventGridTrigger 函数,请参阅以下内容:
请求Url:
POST https://{myFuncApp}.azurewebsites.net/admin/extensions/EventGridExtensionConfig?functionName={myEventGridTriggerFnc}&code={_masterKey}
Header:
aeg-event-type: SubscriptionValidation
Body:
[{
"id": "123",
"subject": "abc",
"eventType": "xxx",
"eventTime": "2019-01-31T16:17:37.1080645Z",
"data": {
"validationCode": "xxxxxxxxxxxxx",
"validationUrl": ""
},
"dataVersion": "0",
"metadataVersion": "1",
"topic": "xxxx"
}]
成功响应会return:
{"validationResponse":"xxxxxxxxxxxxx"}
备注:
- 可以从门户yourFunction/Integrate、属性复制请求Url 事件网格订阅URL
- 在手动创建请求 Url 的情况下,使用门户 yourFunction/Manage 页面中的 _master 键。
- 要测试函数 body,请使用 header 'aeg-event-type: Notification'
我在这里转载了这个和一些观察结果
如果我使用默认函数签名,它工作正常
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.EventGrid3.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());
}
}
}
看看下面的link
https://docs.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)