Azure Functions Blob 触发器动态绑定

Azure Functions Blob Trigger Dynamic Binding

我需要一个 Azure Functions blob 触发器来触发应用程序设置在运行时提供的存储桶。我读到可以这样做:

[FunctionName("Process")]
public static async Task Process([BlobTrigger("%BucketName%/{name}", Connection = "AzureWebJobsStorage")] Stream avroBlobStream, string name, TraceWriter log)
{
}

如果我在 appsettings.json 的 Values 字段中只有 BucketName,这在本地有效。

{
  "IsEncrypted": false,
  "Values": {
    "BucketName": "capture-bucket",
  }
}

如果它不在值字段中,这是错误:

[6/24/2019 5:52:15 PM] Function 'SomeClass.Process' failed indexing and will be disabled.
[6/24/2019 5:52:15 PM] No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. config.UseServiceBus(), config.UseTimers(), etc.).

我在 Azure App 函数中设置了 BucketName,但它给了我同样的错误。你能建议应该调用什么设置或者我在真正的 Azure 环境中做错了什么吗?应该是Values:BucketName?但是我从来没有在微软网站上看到过以Values:作为前缀的例子。

对于你的错误,我测试了一种情况是Microsoft.Azure.WebJobs.Extensions.Storage包没有安装。安装后,它将起作用。你可以试试。

关于动态绑定,官方教程中有描述:Binding expressions - app settings。当您在本地测试时,应用程序设置值来自 local.settings.json 文件。我不知道你为什么要使用 appsettings.json。格式就是你粘贴的格式。

而在 Azure 上,由于 local.settings.json 中的设置不会与 VS 一起部署,您必须转到 Azure 功能配置,并设置绑定名称。

我已经测试过了,这样就可以了,它可以处理我的 blob 文件。

希望这对您有所帮助,如果我误解了您的要求,请告诉我。