简体   繁体   中英

How to call http triggered azure function from timer triggered azure function

There is a timer function, which in the middle of its work should call the http triggered (post request) function. How to do it? Will Durable function - chaining pattern help? How to pass parameters (in requestBody) to the called function? ps I apologize if I expressed myself illiterately in this matter.

Investigated the implementation of the chaining pattern. In the examples there was only a function of type Activity Trigger.

How to do it? - You will submit a WebRequest from the timer triggered function to the http triggered function.

Will Durable function - chaining pattern help? - Probably not, nothing you have mentioned so far in your problem statement leads me to believe that changing your pattern will address any of your concerns.

How to pass parameters (in requestBody) to the called function? - The documentation for webrequest provides some examples

As @Oxymoron suggested, you have to use Web Request Object to Post the Http Trigger URL/Function and you can use one of the durable functions patterns to call the http trigger function from the timer trigger. and I followed @Thiago Custodio SO-Thread as below:

    namespace FunctionApp45
    {
        public class Function1
        {
            [FunctionName("Function1")]
            public async Task RunAsync([TimerTrigger("*/30 * * * * *")]TimerInfo myTimer, ILogger log)
            {
                log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
    
                var url = "https://www.google.co.in/";
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                request.AutomaticDecompression = DecompressionMethods.GZip;
    
                using (HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync())
                using (Stream stream = response.GetResponseStream())
                using (StreamReader reader = new StreamReader(stream))
                {
                    var htmlrawdata = reader.ReadToEnd();
                    log.LogInformation(htmlrawdata);
                }
            }
        }
    }

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM