代码之家  ›  专栏  ›  技术社区  ›  Miq

Azure函数运行时v1 EventGrid订阅创建失败

  •  1
  • Miq  · 技术社区  · 7 年前

    我做错了什么或者如何让它工作? 我使用的是Azure Runtime v1(需要使用.NET Framework,而不是core)。

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

    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.
    

    我在上尝试了从GET请求获得的两个系统代码 https://[<myFunctionAppName>].azurewebsites.net/admin/host/systemkeys/eventgridextensionconfig_extension?code=[<master_key>] ,默认密钥,甚至主密钥本身-结果相同。

    当我在门户上创建一个函数时,创建订阅就可以了。

    2 回复  |  直到 7 年前
        1
  •  2
  •   Rahul Ruikar    7 年前

    我在这里复制了这个和一些观察结果

        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://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) 
    
        2
  •  1
  •   gooberwonder    6 年前

    请求Url:

    POST https://{myFuncApp}.azurewebsites.net/admin/extensions/EventGridExtensionConfig?functionName={myEventGridTriggerFnc}&code={_masterKey}
    

    标题:

    aeg-event-type: SubscriptionValidation
    

    正文:

    [{
       "id": "123",
       "subject": "abc",
       "eventType": "xxx",
       "eventTime": "2019-01-31T16:17:37.1080645Z",
       "data": {
          "validationCode": "xxxxxxxxxxxxx",
          "validationUrl": ""
          },
       "dataVersion": "0",
       "metadataVersion": "1",
       "topic": "xxxx"
    }]
    

    {"validationResponse":"xxxxxxxxxxxxx"}
    

    1. 可以从门户yourFunction/Integrate属性复制请求Url 事件网格订阅URL
    2. 如果手动创建请求Url,请使用_ 主人 从门户网站yourFunction/Manage页面输入。
    3. '
    推荐文章