如何将Azure Functions返回值绑定到输出?

时间:2016-11-03 18:42:11

标签: azure azure-functions

使用Azure Functions时,是否可以将输出绑定到我的函数的返回值?

1 个答案:

答案 0 :(得分:2)

是的,如果您将绑定名称设置为$return,那么您的函数返回的任何内容都将被发送到您的输出绑定。这样可以避免为函数指定out <T> boundParam参数。

实施例

装订

使用手动触发器

{
  "bindings": [
    {
      "type": "blob",
      "name": "$return",
      "path": "testoutput/{rand-guid}.txt",
      "connection": "AzureWebJobsDashboard",
      "direction": "out"
    },
    {
      "type": "manualTrigger",
      "name": "input",
      "direction": "in"
    }
  ],
  "disabled": false
}

代码(同步)

using System;

public static string Run(string input, TraceWriter log)
{
    log.Info($"C# manually triggered function called with input: {input}");
    await Task.Delay(1);

    return input;
}

代码(异步)

using System;

public static async Task<string> Run(string input, TraceWriter log)
{
    log.Info($"C# manually triggered function called with input: {input}");
    await Task.Delay(1);

    return input;
}