Azure 事件网格输出绑定不起作用

问题描述 投票:0回答:2

我已经尝试了本文档提供的所有变体,以创建一个接受事件网格事件并输出和事件网格事件的天蓝色函数:

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

using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using System.Threading.Tasks;
using Microsoft.Azure.EventGrid.Models;
using Microsoft.Azure.WebJobs.Extensions.EventGrid;

namespace Azure.Extensions.WebJobs.Sample
{
    public static class CloudEventBindingFunction
    {
        [FunctionName("TestFunctionName")]
        public static async Task RunAsync(
            [EventGridTrigger] EventGridEvent eventGridEvent, [EventGrid(TopicEndpointUri = "TopicEndpointUri", TopicKeySetting = "TopicKeySetting")] IAsyncCollector<EventGridEvent> eventCollector, ILogger log)
        {
            var e = new EventGridEvent("message-id", "subject-name", "event-data", "event-type", DateTime.UtcNow, "1.0");
            await eventCollector.AddAsync(e);
        }
    }
}

无论我使用什么版本,我都会在天蓝色中收到错误消息:

Microsoft.Azure.EventGrid.Models.EventGridEvent is not a valid event type.

我也尝试过使用此函数的 [return: ...] 变体,并且遇到了同样的问题。

我的host.json

Azure Functions runtime is 2.0

Function runtime version is ~4

Azure 功能托管在应用服务计划(高级)上

该函数已用

func new dotnet

初始化

为了排除某些情况,这是我的 csproj 文件:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <Nullable>enable</Nullable>
    <WarningsAsErrors>nullable</WarningsAsErrors>
    <LangVersion>latest</LangVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Azure.Messaging.EventGrid" Version="4.10.0" />
    <PackageReference Include="Microsoft.Azure.EventGrid" Version="3.2.1" />
    <PackageReference Include="Azure.Storage.Blobs" Version="12.11.0" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions" Version="4.0.1" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.EventGrid" Version="3.2.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.0" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>
c# azure azure-functions azure-eventgrid
2个回答
0
投票
  • 事件订阅的到期时间指定订阅何时终止。将来,该值应该是有效的日期时间值。 确保事件订阅到期时间是将来的时间并且采用正确的日期时间格式。
  • 检查您现有的资源使用情况并消除不再需要的资源。如果您无法删除任何资源,请启动新的 Azure 订阅并向其中添加事件网格资源。
  • 此外,请参阅此 Azure 事件网格订阅验证故障排除文档。了解更多信息。

0
投票

我在将 Microsoft.Azure.WebJobs.Extensions.EventGrid 从版本 2 更新到版本 3 时遇到了同样的问题。此处的文档显示提供给 EventGrid 输出绑定的类型在 Microsoft.Azure 的扩展版本 2 和版本 3 之间发生了变化.EventGrid.Models.EventGridEvent 到 Azure.Messaging.EventGrid,因此如果要更新该包,还需要更新数据类型。

© www.soinside.com 2019 - 2024. All rights reserved.