Kum*_*ple 5 azure azure-functions serverless-architecture serverless
我是耐用函数(编排函数)的新手,并且根据Microsoft文档查看了示例应用程序。因此,我对此毫不怀疑。
例:
public static async Task<HttpResponseMessage> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, methods: "post",
Route = "orchestrators/{functionName}")] HttpRequestMessage req,
[OrchestrationClient] DurableOrchestrationClient starter,
string functionName,
TraceWriter log)
{
// Function input comes from the request content.
dynamic eventData = await req.Content.ReadAsAsync<object>();
string instanceId = await starter.StartNewAsync(functionName, eventData);
log.Info($"Started orchestration with ID = '{instanceId}'.");
return starter.CreateCheckStatusResponse(req, instanceId);
}
Run Code Online (Sandbox Code Playgroud)
要调用它,我使用邮递员发出了HTTP POST请求,因此请求已成功处理,但是当我在控制台中配置了不同的动词(如HTTP GET)时,它在控制台中响应为NotFound”,以及浏览器对HTTP请求的请求中均响应了“ NotFound”错误在控制台中。为什么会这样?
我可以使用in计时器触发azure函数调用任何Orchestration函数吗?
如果不是为什么?
更新:
有关问题的一些其他详细信息
[FunctionName("TimerTrigger")]
public static async Task Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer, TraceWriter log)
{//this runs for every 5minutes
using (HttpClient client = new HttpClient())
{
var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("", "")
});
//making request to above function by http trigger
var result = await client.PostAsync("http://localhost:7071/orchestrators/E1_HelloSequence", content);
}
log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
return;
}
Run Code Online (Sandbox Code Playgroud)
我可以通过计时器触发对HTTP触发器的请求触发原因的原因是为什么我的持久函数运行时间较长,所以如果在计时器触发器本身中调用编排函数,那么可能会有计时器触发超时的可能性,因此我为什么要尝试这种方法。可以通过上述代码调用?
当我配置不同的动词(如 HTTP GET)时,它在控制台中以 NotFound” 错误响应,以及使用来自浏览器的 http 请求向它发出的请求在控制台中以“NotFound”错误响应。为什么会发生这种情况?
因为您指定了仅在 POST 上触发的函数:
[HttpTrigger(AuthorizationLevel.Anonymous, methods: "post",
Route = "orchestrators/{functionName}")] HttpRequestMessage req,
Run Code Online (Sandbox Code Playgroud)
要启用 GET,请添加get到methods参数。
我可以使用计时器触发器天蓝色函数调用任何编排函数吗?
您可以使用OrchestrationClient类似于 HTTP 函数的输入绑定来定义计时器触发的函数。样本声明:
public static async Task Run(
[TimerTrigger("0 */1 * * * *")] TimerInfo info,
[OrchestrationClient] DurableOrchestrationClient starter)
Run Code Online (Sandbox Code Playgroud)
这是一般的Azure Functions行为。GET不起作用的原因是因为示例中的函数仅配置为可与POST一起使用。请参见[HttpTrigger]函数签名中的属性:
[HttpTrigger(AuthorizationLevel.Anonymous, methods: "post",
Route = "orchestrators/{functionName}")]
Run Code Online (Sandbox Code Playgroud)
如果要支持GET,请相应地更改methods参数:
[HttpTrigger(AuthorizationLevel.Anonymous, methods: "get",
Route = "orchestrators/{functionName}")]
Run Code Online (Sandbox Code Playgroud)
请注意,Visual Studio似乎有一个缓存错误,其中在本地调试时未正确保存对路由信息的更改。我打开了一个GitHub问题以在此处跟踪该问题:https : //github.com/Azure/Azure-Functions/issues/552
有关HTTP触发器的详细信息,请参阅以下文档:https : //docs.microsoft.com/zh-cn/azure/azure-functions/functions-bindings-http-webhook
如果要使用计时器触发器来触发持久功能,则只需更改触发器类型。例如:
[FunctionName("ScheduledStart")]
public static async Task RunScheduled(
[TimerTrigger("0 0 * * * *")] TimerInfo timerInfo,
[OrchestrationClient] DurableOrchestrationClient starter,
TraceWriter log)
{
string functionName = "E1_HelloSequence";
string instanceId = await starter.StartNewAsync(functionName, null);
log.Info($"Started orchestration with ID = '{instanceId}'.");
}
Run Code Online (Sandbox Code Playgroud)
有关计时器触发器的详细信息,请参阅以下文档:https : //docs.microsoft.com/zh-cn/azure/azure-functions/functions-bindings-timer
| 归档时间: |
|
| 查看次数: |
3075 次 |
| 最近记录: |