如何从另一个 Azure 函数触发 HTTP Azure 函数

huangapple go评论59阅读模式
英文:

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:

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:

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)应该像下面这样开始执行:
如何从另一个 Azure 函数触发 HTTP Azure 函数

然后,当我运行函数 2 时,这是函数 1 的日志:

如何从另一个 Azure 函数触发 HTTP Azure 函数

更多信息,请参考 此链接

对于在 VS CODE 中的 Python:

在 Visual Studio 中,默认情况下,不同项目在不同端口上运行,而在 VS Code 中,使用相同的端口,您将收到以下错误:

如何从另一个 Azure 函数触发 HTTP Azure 函数

部署到 Azure 门户:

如何从另一个 Azure 函数触发 HTTP Azure 函数

然后获取如下的 URL:

如何从另一个 Azure 函数触发 HTTP Azure 函数

为此,您需要首先将您的函数部署到 Azure,然后获取 URL 并使其像下面这样工作:

u = 'https://rith34.azurewebsites.net/api/HttpTrigger1?code=jd5WmzFuRxdyTg=='
requests.post(u)

如何从另一个 Azure 函数触发 HTTP Azure 函数

requirements.txt:

如何从另一个 Azure 函数触发 HTTP Azure 函数

在门户中的输出:

检查已部署函数的监视部分:

如何从另一个 Azure 函数触发 HTTP Azure 函数

进一步参考类似的 示例

英文:

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

如何从另一个 Azure 函数触发 HTTP Azure 函数

Output of both functions:

Function which is called from Another function(Function 1 should start executing like below:
如何从另一个 Azure 函数触发 HTTP Azure 函数

Then when I run function 2 and this is function1 logs:

如何从另一个 Azure 函数触发 HTTP Azure 函数

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:

如何从另一个 Azure 函数触发 HTTP Azure 函数

Deploy to Portal:
如何从另一个 Azure 函数触发 HTTP Azure 函数

Then get the URL like below:

如何从另一个 Azure 函数触发 HTTP Azure 函数

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)

如何从另一个 Azure 函数触发 HTTP Azure 函数

requirements.txt:

如何从另一个 Azure 函数触发 HTTP Azure 函数

Output in Portal:

Check the deployed function monitor section:

如何从另一个 Azure 函数触发 HTTP Azure 函数

For further refer similar example.

huangapple
  • 本文由 发表于 2023年6月8日 01:43:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/76425849.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定