我使用Azure函数开发了两个微服务,每个服务都有独立的用例和不同的编程语言。
现在我有了一个按以下顺序使用所有服务的用例,所以我又开发了一个Azure函数以按给定顺序使用所有服务。下面的代码运行良好。
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分钟,我必须在超级服务中等待约4分钟,并支付4分钟以上的费用。(我们不需要支付等待时间:)
https://www.youtube.com/watch?v=lVwWlZ-4Nfs
)
我想在这里使用Azure持久功能,但没有任何方法来调用外部url。
请帮助我或提出更好的解决方案。
提前感谢