Azure Event Grid / Function / ngrok

别等时光非礼了梦想. 提交于 2019-12-24 11:03:07

问题


I'm trying to follow the instructions Local Testing with ngrok

I have my event gird running and my function running in VS locally using the C# example. However, when I try to subscribe to my event using the endpoint

https://xxxx.ngrok.io/admin/extensions/EventGridExtensionConfig?functionName=EventGridTrigger

My local ngrok console shows:

POST /admin/extensions/EventGridExtensionConfig 404 Not Found

Function code in VS:

  [FunctionName("EventGridTrigger")]
    public static void Run([EventGridTrigger]EventGridEvent eventGridEvent, TraceWriter log)
    {
        log.Info(eventGridEvent.Data.ToString());
    }

回答1:


Apparently there is an error in the documentation published by Microsoft. The ngrok example is for functions v1. If you are using functions v2 then this is the URL required to trigger the function:

https://{subdomain}.ngrok.io/runtime/webhooks/EventGridExtensionConfig?functionName={functionName}

See the issue logged here




回答2:


based on your description, the following attribute must be used:

[FunctionName("EventGridTrigger")]

you can test it with the Postman:

http://localhost:7071/admin/extensions/EventGridExtensionConfig?functionName=EventGridTrigger 

note, that the following header must be added:

Aeg-Event-Type:Notification

Update:

the following is my working function via ngrok and custom topic created by VS 2017 Version 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));
        }
    }
}

and the dependencies:

Update2:

the function for version 2 generated by VS from the EventGridTrigger template is the following:

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

and the dependencies:

Note for localhost:7071 postman test:

the payload must be as an array of the events




回答3:


For function 2.x the url is https://{subdomain}.ngrok.io/runtime/webhooks/eventgrid?functionName={functionName}.

See the docs.



来源:https://stackoverflow.com/questions/51675648/azure-event-grid-function-ngrok

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!