问题描述
如何使用策略来平衡对一对后端服务的呼叫负载? (在这种情况下,是在不同区域的一对Logic App)
How can you use policy to load balance calls to a pair of backend services? (in this case a pair of Logic Apps in different regions)
我已阅读 API管理策略并可以在控制流,但我不知道如何(a)测试后端服务是否可用,然后(b)如果主服务不可用,则将调用更改为备份服务
I've read through the API Management policies and can see something around the control flow but I can't work out how to (a) test the back-end service is available, and then (b) change the call to the backup service if the primary is unavailable
<backend>
<forward-request/>
</backend>
推荐答案
实现此目标的另一种方法可能是您可以使用重试策略,并带有设置后端服务或发送请求
One more way to achieve this could be that you can use the retry policy with set backend service or send-request
类似
<backend>
<retry condition="@(context.Response.StatusCode == 400 || context.Response.StatusCode >= 500)" count="10" interval="10" max-interval="100" delta="10" first-fast-retry="false">
<choose>
<when condition="@(context.Response != null && (context.Response.StatusCode == 400 || context.Response.StatusCode >= 500)">
<set-backend-service base-url="http://echoapibackup.cloudapp.net/api" />
</when>
<otherwise>
<set-backend-service base-url="http://echoapi.cloudapp.net/api" />
</otherwise>
</choose>
<forward-request />
</retry>
</backend>
如果您的主后端返回错误,则会继续在您的备份后端上重试.
This will in case your primary backend returns an error, will keep retrying on your backup backend.
这篇关于您如何使用Azure API管理策略来负载均衡对后端服务的调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!