Azure 事件网格/函数/ngrok
Azure Event Grid / Function / ngrok
我正在尝试按照说明进行操作 Local Testing with ngrok
我在 VS 本地使用 C# 示例创建了我的事件 gird 运行 和我的函数 运行。但是,当我尝试使用端点
订阅我的事件时
https://xxxx.ngrok.io/admin/extensions/EventGridExtensionConfig?functionName=EventGridTrigger
我的本地 ngrok 控制台显示:
POST /admin/extensions/EventGridExtensionConfig 404 Not Found
VS中的函数代码:
[FunctionName("EventGridTrigger")]
public static void Run([EventGridTrigger]EventGridEvent eventGridEvent, TraceWriter log)
{
log.Info(eventGridEvent.Data.ToString());
}
根据您的描述,必须使用以下属性:
[FunctionName("EventGridTrigger")]
你可以用 Postman 测试一下:
http://localhost:7071/admin/extensions/EventGridExtensionConfig?functionName=EventGridTrigger
注意,必须添加以下 header:
Aeg-Event-Type:Notification
更新:
以下是我通过 ngrok 和 VS 2017 版本 15.7.5 创建的自定义主题的工作函数:
// This is the default URL for triggering event grid function in the local environment.
// http://localhost:7071/admin/extensions/EventGridExtensionConfig?functionName={functionname}
// Aeg-Event-Type:Notification
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Azure.WebJobs.Extensions.EventGrid;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace FunctionApp10
{
public static class Function2
{
[FunctionName("Function2")]
public static void Run([EventGridTrigger]JObject eventGridEvent, TraceWriter log)
{
log.Info(eventGridEvent.ToString(Formatting.Indented));
}
}
}
和依赖项:
更新2:
VS 从 EventGridTrigger 模板生成的版本 2 函数如下:
// Default URL for triggering event grid function in the local environment.
// http://localhost:7071/runtime/webhooks/EventGridExtensionConfig?functionName={functionname}
// Aeg-Event-Type:Notification
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Azure.EventGrid.Models;
using Microsoft.Azure.WebJobs.Extensions.EventGrid;
using Microsoft.Extensions.Logging;
namespace FunctionApp11
{
public static class Function2
{
[FunctionName("Function2")]
public static void Run([EventGridTrigger]EventGridEvent eventGridEvent, ILogger log)
{
log.LogInformation(eventGridEvent.Data.ToString());
}
}
}
和依赖项:
localhost:7071 邮递员测试注意事项:
负载必须是事件数组
Microsoft 发布的 documentation 显然有错误。 ngrok 示例适用于函数 v1。如果您使用的是函数 v2,那么这是触发该函数所需的 URL:
https://{subdomain}.ngrok.io/runtime/webhooks/EventGridExtensionConfig?functionName={functionName}
查看记录的问题 here
对于函数 2.x,url 是 https://{subdomain}.ngrok.io/runtime/webhooks/eventgrid?functionName={functionName}。
查看docs。
我正在尝试按照说明进行操作 Local Testing with ngrok
我在 VS 本地使用 C# 示例创建了我的事件 gird 运行 和我的函数 运行。但是,当我尝试使用端点
订阅我的事件时https://xxxx.ngrok.io/admin/extensions/EventGridExtensionConfig?functionName=EventGridTrigger
我的本地 ngrok 控制台显示:
POST /admin/extensions/EventGridExtensionConfig 404 Not Found
VS中的函数代码:
[FunctionName("EventGridTrigger")]
public static void Run([EventGridTrigger]EventGridEvent eventGridEvent, TraceWriter log)
{
log.Info(eventGridEvent.Data.ToString());
}
根据您的描述,必须使用以下属性:
[FunctionName("EventGridTrigger")]
你可以用 Postman 测试一下:
http://localhost:7071/admin/extensions/EventGridExtensionConfig?functionName=EventGridTrigger
注意,必须添加以下 header:
Aeg-Event-Type:Notification
更新:
以下是我通过 ngrok 和 VS 2017 版本 15.7.5 创建的自定义主题的工作函数:
// This is the default URL for triggering event grid function in the local environment.
// http://localhost:7071/admin/extensions/EventGridExtensionConfig?functionName={functionname}
// Aeg-Event-Type:Notification
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Azure.WebJobs.Extensions.EventGrid;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace FunctionApp10
{
public static class Function2
{
[FunctionName("Function2")]
public static void Run([EventGridTrigger]JObject eventGridEvent, TraceWriter log)
{
log.Info(eventGridEvent.ToString(Formatting.Indented));
}
}
}
和依赖项:
更新2:
VS 从 EventGridTrigger 模板生成的版本 2 函数如下:
// Default URL for triggering event grid function in the local environment.
// http://localhost:7071/runtime/webhooks/EventGridExtensionConfig?functionName={functionname}
// Aeg-Event-Type:Notification
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Azure.EventGrid.Models;
using Microsoft.Azure.WebJobs.Extensions.EventGrid;
using Microsoft.Extensions.Logging;
namespace FunctionApp11
{
public static class Function2
{
[FunctionName("Function2")]
public static void Run([EventGridTrigger]EventGridEvent eventGridEvent, ILogger log)
{
log.LogInformation(eventGridEvent.Data.ToString());
}
}
}
和依赖项:
localhost:7071 邮递员测试注意事项:
负载必须是事件数组
Microsoft 发布的 documentation 显然有错误。 ngrok 示例适用于函数 v1。如果您使用的是函数 v2,那么这是触发该函数所需的 URL:
https://{subdomain}.ngrok.io/runtime/webhooks/EventGridExtensionConfig?functionName={functionName}
查看记录的问题 here
对于函数 2.x,url 是 https://{subdomain}.ngrok.io/runtime/webhooks/eventgrid?functionName={functionName}。
查看docs。