如何使用Azure事件网格触发Azure功能并绑定到Blob存储

时间:2017-12-01 10:54:59

标签: azure azure-functions azure-eventgrid

尝试使用visual studio重新制作c#中的Azure Grid Image Resize示例,但是有问题使得azure函数触发器由事件网格触发并绑定到blob存储。

当前代码:

using Microsoft.Azure.WebJobs.Extensions.EventGrid;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Azure.WebJobs;
using Microsoft.WindowsAzure.Storage.Blob;

namespace FunctionApp
{
    public static class CreateIndex
    {
        [FunctionName("CreateIndex")]
        [StorageAccount("backup_STORAGE")]
        public static void Run(
            [EventGridTrigger()] EventGridEvent myEvent, 
            [Blob("{data.url}")] CloudBlockBlob inputBlob, 
            TraceWriter log)
        {
            log.Info(myEvent.ToString());
            log.Info(inputBlob.ToString());
        }
    }
}

生成的function.json:

{
  "generatedBy": "Microsoft.NET.Sdk.Functions.Generator-1.0.6",
  "configurationSource": "attributes",
  "bindings": [
    {
      "type": "eventGridTrigger",
      "name": "myEvent"
    }
  ],
  "disabled": false,
  "scriptFile": "../bin/FunctionApp.dll",
  "entryPoint": "FunctionApp.CreateIndex.Run"
}

绑定适用于事件网格触发器,但不适用于Blob输入。

预期的function.json:

{
  "bindings": [
    {
      "type": "EventGridTrigger",
      "name": "myEvent",
      "direction": "in"
    },
    {
      "type": "blob",
      "name": "inputBlob",
      "path": "{data.url}",
      "connection": "myblobstorage_STORAGE",
      "direction": "in"
    }
  ],
  "disabled": false
}

1 个答案:

答案 0 :(得分:2)

预编译函数为您生成SELECT `products`.*,`product_category`.`category_id` as catid FROM `products` LEFT JOIN `product_category` ON products.id = product_category.item_id GROUP BY `products`.`id` ,但它们只将触发器绑定放在其中。你的blob绑定不在这个文件中是可以的。

输入Blob绑定仍然有效:运行时将根据您的属性选择它。