繁体   English   中英

禁用功能应用时 Azure API 管理不发送重试

[英]Azure API management not sending retry when function app disabled

如果第一个区域遇到错误,我已配置 API 管理策略以重试到第二个区域。

但是,当我禁用位于悉尼的主要功能应用程序时,应用程序洞察中没有记录重试 - 只有原始失败请求。 墨尔本函数应用程序中没有记录函数调用。

我尝试了很多不同的配置。 两个区域功能应用程序都运行良好。

我已经复制了下面的代码,有什么我遗漏或不理解的地方吗?

提前致谢

API 政策

<policies>
  <inbound>
    <base />
    <choose>
      <when condition="@(context.Variables.GetValueOrDefault<int>('RetryCounter', 0) == 0)">
        <set-backend-service base-url="{{syndey-function-app}}" />
      </when>
      <otherwise>
        <set-backend-service base-url="{{melbourne-function-app}}" />
      </otherwise>
    </choose>
  </inbound>
  <backend>
    <retry count="1" interval="0" first-fast-retry="true" condition="@(
        context.Response.StatusCode > 400
      )">
      <set-variable name="RetryCounter" value="@(context.Variables.GetValueOrDefault<int>('RetryCounter', 0) + 1)" />
      <forward-request buffer-request-body="true" timeout="15"/>
    </retry>
  </backend>
  <outbound>
    <base />
  </outbound>
  <on-error>
    <base />
  </on-error>
</policies>

403 错误响应

<h1 id="unavailable">Error 403 - This web app is stopped.</h1>
<p id="tryAgain">
The web app you have attempted to reach is currently stopped and does not 
accept any requests. Please try to reload the page or visit it again soon.
</p>

<p id="toAdmin">
If you are the web app administrator, please find the common 403 error 
scenarios and resolution <a href="https://go.microsoft.com/fwlink/?linkid=2095007" 
target="_blank">here</a>. For further troubleshooting tools and recommendations, 
please visit <a href="https://portal.azure.com/">Azure Portal</a>.
</p>

由于保存时出错,我不得不将单引号替换为双引号:

context.Variables.GetValueOrDefault<int>('RetryCounter', 0) => context.Variables.GetValueOrDefault<int>("RetryCounter", 0)

为了测试,我创建了两个模拟服务:

返回状态码 200:
https://rfqapiservicey27itmeb4cf7q.azure-api.net/echo/200/test

返回状态码 403:
https://rfqapiservicey27itmeb4cf7q.azure-api.net/echo/403/test

backend部分的retry部分永远不会返回inbound部分。 所以choose条件只是在一开始就被击中。

因此,必须将choose条件移至backend部分。

<policies>
    <inbound>
        <base />
        <set-backend-service base-url="https://rfqapiservicey27itmeb4cf7q.azure-api.net/echo/403" />
        <!--
            <set-backend-service base-url="{{syndey-function-app}}" />
         -->
    </inbound>
    <backend>
        <retry count="1" interval="0" first-fast-retry="true" condition="@(
        context.Response.StatusCode > 400
      )">
            <set-variable name="RetryCounter" value="@(context.Variables.GetValueOrDefault<int>("RetryCounter", 0) + 1)" />
            <choose>
                <when condition="@(context.Variables.GetValueOrDefault<int>("RetryCounter", 0) > 1)">
                    <set-backend-service base-url="https://rfqapiservicey27itmeb4cf7q.azure-api.net/echo/200" />
                    <!--
                        <set-backend-service base-url="{{melbourne-function-app}}" />
                    -->
                </when>
            </choose>
            <forward-request buffer-request-body="true" timeout="15" />
        </retry>
    </backend>
    <outbound>
        <base />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>

在此处输入图像描述

我的示例操作按预期执行:

https://rfqapiservicey27itmeb4cf7q.azure-api.net/sample/test

在此处输入图像描述

backend第一次命中请求 403 资源: 在此处输入图像描述

此请求失败, retry策略在backend部分设置200 在此处输入图像描述

第二个请求成功时将返回200并离开backend部分:

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM