【问题标题】:Azure Functions Runtime v1 EventGrid Subscription create failsAzure Functions Runtime v1 EventGrid 订阅创建失败
【发布时间】:2019-06-25 00:33:31
【问题描述】:

我做错了什么或如何使它起作用? 我正在使用 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://[&lt;myFunctionAppName&gt;].azurewebsites.net/admin/host/systemkeys/eventgridextensionconfig_extension?code=[&lt;master_key&gt;] 上的 GET 请求获得的系统代码、默认密钥甚至主密钥本身——结果相同。

当使用门户上的按钮“添加事件网格订阅”时 - 我也在通知框中收到此错误。

当我在门户上创建功能时 - 创建订阅工作正常。
此外,当我将 .netcore 函数部署到 2.x 运行时 - 并使用门户按钮创建订阅时 - 这也可以正常工作。但就像我说的 - 我想使用 runtime 1.x 来部署一个 .NETFramework 函数。

【问题讨论】:

    标签: c# .net azure azure-functions azure-eventgrid


    【解决方案1】:

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

    如果我使用默认函数签名,它可以正常工作

        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) 
    

    【讨论】:

    • 使用nuget包的需要写在你分享的doc链接里。我尝试了它,因为它以前不能与 JObject 一起使用,但当时我可能使用了无效的密钥。根据文档,它应该双向工作,因为验证逻辑应该由运行时处理,而不是由函数处理。不过,如果你说它对你有用,我会再试一次,也许用新的函数应用程序和 eventgrid 主题。
    • 呃,切换回 JObject 工作正常...该页面上的注释非常混乱 - 它暗示您可以使用 EventGridEvent,而实际上您不能。感谢您重新检查。
    【解决方案2】:

    您可以使用 Postman 为 Azure 事件网格订阅者验证 EventGridTrigger 函数,请参阅以下内容:

    请求网址:

    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 页面中的 _master 键。
    3. 要测试函数体,请使用标头 'aeg-event-type: Notification'

    【讨论】:

    • 我不想手动验证函数。正如文档所说,我应该只将 function.json 输入作为事件触发器,它应该自动进行验证。
    • 此测试可用于验证订阅处理程序端点的 EventGridTrigger 函数的 url 地址。如果测试通过,则此 url 地址对订阅 webhook 端点有效。
    • 谢谢,我试试看。
    • Postman 正在返回 404“找不到函数:'Function1'。当我将输入参数改回 JObject 时,我收到了验证码。感谢您的帮助。
    猜你喜欢
    • 2021-01-09
    • 1970-01-01
    • 1970-01-01
    • 2018-10-26
    • 2021-12-10
    • 1970-01-01
    • 2021-12-01
    • 1970-01-01
    • 2019-07-07
    相关资源
    最近更新 更多