2017-10-17 109 views
1

我是Durable函数(Orchestration函数)的新手,并且按照Microsoft文档可以看到示例应用程序。所以我几乎没有怀疑。如何通过定时器触发调用Durable功能?

例如:

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); 
     } 

调用它我使用邮递员所以请求成功处理的HTTP POST请求,但我被配置成当不同的动词像HTTP GET将其用在控制台NOTFOUND”错误回答以及请求作出它与浏览器的HTTP请求报以“NOTFOUND”错误控制台。为什么会发生?

我可以在定时器触发蔚蓝的功能调用任何业务流程与功能?

如果不是,为什么?

UPDATE:

有关问题一些额外的细节

[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; 
      } 

我可以请求HTTP触发由计时器triggred为什么,因为我的耐用功能具有长期运行的进程,所以如果在计时器调用业务流程功能触发自己,所以可能会有计时器触发超时的可能性,以便我试图按照这种方法。是否可以通过上面的代码调用?

回答

1

这是一般的Azure函数行为。 GET不起作用的原因是因为示例中的函数只能配置为使用POST。见函数签名的[HttpTrigger]属性:

[HttpTrigger(AuthorizationLevel.Anonymous, methods: "post", 
     Route = "orchestrators/{functionName}")] 

如果你想支持GET,然后更改相应的methods参数:

[HttpTrigger(AuthorizationLevel.Anonymous, methods: "get", 
     Route = "orchestrators/{functionName}")] 

注意,Visual Studio中似乎有一个缓存的臭虫更改在本地进行调试时,路由信息未正确保存。我开了一个GitHub的问题跟踪,在这里:https://github.com/Azure/Azure-Functions/issues/552

有关HTTP触发器的更多信息,请参阅本文档:https://docs.microsoft.com/en-us/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}'."); 
} 

有关计时器更多信息触发,请参阅本文档:https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-timer

+0

谢谢...我的问题通过上述方案解决 –

2

当我配置了不同的动词,如HTTP GET它与NOTFOUND”控制台错误以及为其所作出的HTTP请求从浏览器请求的回应‘在控制台NOTFOUND’错误。为什么会发生?

回应

因为你指定你的函数要在POST只触发:

[HttpTrigger(AuthorizationLevel.Anonymous, methods: "post", 
Route = "orchestrators/{functionName}")] HttpRequestMessage req, 

要启用GET,加getmethods参数

我可以调用任何具有定时器触发天蓝色功能的Orchestration功能吗?

您可以用OrchestrationClient输入绑定定义类似于您的HTTP函数的定时器触发函数。示例声明:

public static async Task Run(
    [TimerTrigger("0 */1 * * * *")] TimerInfo info, 
    [OrchestrationClient] DurableOrchestrationClient starter)