Azure 事件网格/函数/ngrok

标签 azure azure-functions azure-eventgrid

我正在尝试按照说明进行操作 Local Testing with ngrok

我使用 C# 示例在本地 VS 中运行事件网格和函数。但是,当我尝试使用端点订阅我的事件时

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));
        }
    }
}

和依赖项:

enter image description here

更新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());
        }
    }
}

和依赖项:

enter image description here

localhost:7071 postman 测试注意事项:

有效负载必须是事件数组

关于Azure 事件网格/函数/ngrok,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51675648/

相关文章:

azure - 使用 python 将文件从 blob 容器复制到另一个容器

azure - 无法在 Azure 中选择 "Create Event Subscription"中的资源

azure - ReadEventsAsync EventHub 不会停止

azure - 我需要 docker 在 linux ubuntu 上运行 azure data studio 吗?

azure - WP Silverlight 后台任务与 Azure 的通信

azure - azure 函数 AzureWebJobsStorage 和 AzureWebJobsSecretStorageType 设置有何用途

azure - Azure Functions 是否通过 HTTPS 运行?

azure - 如何在Azure Function中使用LinQ lambda表达式并将其与Azure SQL连接

azure - 具有对象 ID 的客户端无权在范围内执行操作 'Microsoft.DataFactory/datafactories/datapipelines/read'

azure - 事件网格不会使用逻辑应用触发