gpt4 book ai didi

Azure Durable Function(外部函数)

转载 作者:行者123 更新时间:2023-12-03 05:03:47 25 4
gpt4 key购买 nike

我使用Azure功能开发了几个微服务,每个服务都有独立的用例和不同的编程语言。

Micro Services

现在我有一个用例可以按以下顺序使用所有服务,因此我又开发了一个 Azure 函数来按给定顺序使用所有服务。下面的代码运行良好。

Aggregate Service

public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)]HttpRequestMessage req, TraceWriter log)
{
string returnValue = string.Empty;
dynamic data = await req.Content.ReadAsStringAsync();
if (data == null)
{
return req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a value in the request body");
}
else
{
string body = data.ToString();
var transformResult = await HttpRestHelper.CreateRequestAsync(AppConfiguration.TransformServiceEndPoint, body, HttpMethod.POST);

var validationResult = await HttpRestHelper.CreateRequestAsync(AppConfiguration.ValidationServiceEndPoint, transformResult.Result.ToString(), HttpMethod.POST);

if (validationResult.Result != null && Convert.ToBoolean(validationResult.Result))
{
var encryptionResult = await HttpRestHelper.CreateRequestAsync(AppConfiguration.EncryptionServiceEndPoint, transformResult.Result.ToString(), HttpMethod.POST);

var storageResult = await HttpRestHelper.CreateRequestAsync(AppConfiguration.StorageServiceEndPoint, encryptionResult.Result.ToString(), HttpMethod.POST);
returnValue = storageResult.Result.ToString();
}
else
{
returnValue = "Validation Failed";
}

return req.CreateResponse(HttpStatusCode.OK, returnValue, "text/plain");
}
}

问题

如果每个微服务需要 1 分钟才能执行,我必须在我的 super 服务中等待大约 4 分钟,并收取 4 分钟以上的费用。 (我们不需要支付等待时间:) https://www.youtube.com/watch?v=lVwWlZ-4Nfs )

我想在这里使用 Azure Durable 函数,但没有获得任何调用外部 url 的方法。

请帮助我或提出更好的解决方案。

提前致谢

最佳答案

持久编排功能不适用于任意 HTTP 端点。相反,您需要创建单独的函数作为事件触发的。

编排将在幕后使用消息队列而不是 HTTP。 HTTP 本质上是请求-响应,因此您必须保持连接并为此付费。

基于队列的编排器还可以为您提供一些额外的弹性来应对间歇性故障。

关于Azure Durable Function(外部函数),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49839300/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com