问题描述
我有一个由 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
?
解决方法
不幸的是,对于事件网格触发器/绑定,不支持这种属性绑定表达式(例如 {EventType}
)。这就是为什么您在 Event Grid trigger doc 中看不到这一点,而不是在支持此类绑定的地方(例如 Service Bus)