如何将我的 Azure Functions return 值绑定到输出?
How can I bind my Azure Functions return value to a output?
使用 Azure Functions 时,是否可以将我的输出绑定到函数的 return 值?
是的,如果您将绑定名称设置为 $return
那么无论您的函数 returns 将被发送到您的输出绑定。这将避免您必须为函数指定 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;
}
使用 Azure Functions 时,是否可以将我的输出绑定到函数的 return 值?
是的,如果您将绑定名称设置为 $return
那么无论您的函数 returns 将被发送到您的输出绑定。这将避免您必须为函数指定 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;
}