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

时间:2019-01-31 14:10:23

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

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

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

当我在门户网站上创建功能时-创建订阅可以正常工作。
同样,当我将.netcore函数部署到2.x运行时-并使用Portal按钮创建订阅时-这也很好。但是就像我说的-我想使用运行时1.x部署.NETFramework函数。

2 个答案:

答案 0 :(得分:2)

我在这里转载了这个和一些观察

如果我使用默认功能签名,则可以正常工作

RTs

但是当我使用您提到的签名时,在创建事件订阅时出现错误。我还需要添加nuget包以供后续编译 Microsoft.Azure.EventGrid 3.0.0

    namespace FunctionApp7
{
    public static class Function1
    {
        [FunctionName("Function1")]
        public static void Run([EventGridTrigger]JObject eventGridEvent, TraceWriter log)
        {
            log.Info(eventGridEvent.ToString(Formatting.Indented));
        }
    }
}

看看下面的链接

https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-event-grid

以下签名不适用于V1功能

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

答案 1 :(得分:1)

您可以使用邮递员为Azure Event Grid订户验证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": "xxxxxxxx",
      "validationUrl": "",
      },
   "dataVersion": "0",
   "metadataVersion": "1",
   "topic": "xxxx"
}]

成功的响应将返回:

{"validationResponse":"xxxxxxxx"}

注意:

  1. 可以从门户网站的yourFunction / Integrate属性 Event Grid Subscription URL
  2. 复制请求网址。
  3. 对于手动创建请求网址的情况,请使用门户网站“功能/管理”页面上的_ master 键。
  4. 要测试功能主体,请使用标题'aeg-event-type:Notification '
相关问题