【问题标题】:Accessing EventGridEvent.EventType in Azure function binding在 Azure 函数绑定中访问 EventGridEvent.EventType
【发布时间】:2021-05-07 23:46:13
【问题描述】:

我有一个由 EventGridEvent 触发的 Azure 函数。我正在尝试将所有事件存储在 Azure 表中,并为每个表指定事件的名称。

这就是我在不绑定的情况下解决它的方法:

[FunctionName("MyFunction")]
public static async Task MyFunction([EventGridTrigger] EventGridEvent eventGridEvent)
{
    var table = CloudStorageAccount.Parse(Environment.GetEnvironmentVariable("AzureWebJobsStorage")).CreateCloudTableClient().GetTableReference(eventGridEvent.EventType);
    await table.CreateIfNotExistsAsync();
    // etc...
}    

但我想通过绑定来完成它。

这是我尝试过的:

 [FunctionName("MyFunction")]
 public static async Task MyFunction(
     [EventGridTrigger] EventGridEvent eventGridEvent,
     [Table("{EventType}")] CloudTable table)
    {
    }

我收到此错误:

Microsoft.Azure.WebJobs.Host:索引方法“MyFunction”出错。 Microsoft.Azure.WebJobs.Host:无法解析绑定参数“EventType”。绑定表达式必须映射到触发器提供的值或触发器绑定到的值的属性,或者必须是系统绑定表达式(例如 sys.randguid、sys.utcnow 等。 )。

确定EventType 是触发器绑定到的EventGridEvent 的属性吗?

我应该如何在绑定中访问EventGridEvent.EventType

【问题讨论】:

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


【解决方案1】:

不幸的是,对于事件网格触发器/绑定,不支持这种属性绑定表达式(例如 {EventType})。这就是为什么您在 Event Grid trigger doc 中看不到这一点,而不是在支持此类绑定的地方(例如 Service Bus

【讨论】:

    猜你喜欢
    • 2017-07-15
    • 2018-03-30
    • 1970-01-01
    • 1970-01-01
    • 2023-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-04
    相关资源
    最近更新 更多