英文:
How to trigger a http azure function from another azure function
问题
I have written a HTTP trigger azure function that executes a series of operations (like add files to blob storage, list them, delete them or do some more time requiring tasks through orchestrator), according to Azure Durable Function.
I want to retrieve the status of such time requiring tasks through an additional azure function that, based on the job id of the orchestrator, returns "Pending", "Completed", or "Failed". In order to do that, I need to make a request inside the main HTTP trigger function to ask for such status.
I've tried:
- azure functions http.HttpRequest(url) and HttpRequest(url)
- requests.get(url)
Neither of them apparently works locally, since Visual Studio Code in debug mode completely freezes. Can it be due to authorization issues or is it not possible to trigger another azure function locally? Will it work once I deploy the code?
I've read the suggested articles in stackoverflow and the relative azure functions documentation, but none of them is providing a complete answer.
英文:
I have written a HTTP trigger azure function that executes a series of operations (like add files to blob storage, list them, delete them or do some more time requiring tasks through orchestrator), according to Azure Durable Function.
I want to retrieve the status of such time requiring tasks through an additional azure function that, based on the job id of the orchestrator, returns "Pending", "Completed" or "Failed". In order to do that, I need to make a request inside the main HTTP trigger function to ask for such status.
I've tried:
- azure functions http.HttpRequest(url) and HttpRequest(url)
- requests.get(url)
Neither of them apparently works locally, since Visual Studio Code in debug mode completely freezes. Can it be due to authorization issues or is it not possible to trigger another azure function locally? Will it work once I deploy the code?
I've read the suggested articles in stackoverflow and the relative azure functions documentation, but none of them is providing a complete answer.
答案1
得分: 1
I will translate the code-related content for you:
>如何从另一个 Azure 函数触发 HTTP Azure 函数
在 C# 中,您可以使用 httpClient
进行调用,如下所示:
var r = await httpClient.GetAsync("http://localhost:7114/api/Function1");
var c = await r.Content.ReadAsStringAsync();
var response = req.CreateResponse(HttpStatusCode.OK);
两个函数的输出:
从另一个函数调用的函数(Function 1)应该像下面这样开始执行:
然后,当我运行函数 2 时,这是函数 1 的日志:
更多信息,请参考 此链接。
对于在 VS CODE 中的 Python:
在 Visual Studio 中,默认情况下,不同项目在不同端口上运行,而在 VS Code 中,使用相同的端口,您将收到以下错误:
部署到 Azure 门户:
然后获取如下的 URL:
为此,您需要首先将您的函数部署到 Azure,然后获取 URL
并使其像下面这样工作:
u = 'https://rith34.azurewebsites.net/api/HttpTrigger1?code=jd5WmzFuRxdyTg=='
requests.post(u)
requirements.txt:
在门户中的输出:
检查已部署函数的监视部分:
进一步参考类似的 示例。
英文:
>How to trigger a http azure function from another azure function
In C# you can call using httpClient
as below:
var r = await httpClient.GetAsync("http://localhost:7114/api/Function1");
var c = await r.Content.ReadAsStringAsync();
var response = req.CreateResponse(HttpStatusCode.OK);
Output of both functions:
Function which is called from Another function(Function 1 should start executing like below:
Then when I run function 2 and this is function1 logs:
For further you can refer this.
For python in VS CODE:
In Visual Studio defaultly, different Projects run on different ports where as In VS code same port is used and you will get this error:
Deploy to Portal:
Then get the URL like below:
For that you need to deploy your function first to azure and then get the URL
and make it working like below:
u='https://rith34.azurewebsites.net/api/HttpTrigger1?code=jd5WmzFuRxdyTg=='
requests.post(u)
requirements.txt:
Output in Portal:
Check the deployed function monitor section:
For further refer similar example.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论