当功能应用程序禁用功能应用时,Azure API管理不会发送重试

发布于 2025-02-07 06:21:48 字数 1937 浏览 2 评论 0 原文

如果第一个遇到错误,我已经配置了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>

I've configured an API Management policy to retry to a second region if the first encounters an error.

However, when I disable the primary function app, based in Sydney, there are no retries recorded in Application insights - only the original failing request. There are no function calls recorded in the Melbourne function app.

I've tried a bunch of different configurations. Both region function apps are running fine.

I've got the copied the code below, is there something that I'm missing or not understanding?

Thanks in advance

API Policy

<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 Error Response

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白芷 2025-02-14 06:21:48

由于在保存上有错误:

context.gariables.getValueordEfault&lt; int&gt;('retrycounter',0),0) =&gt;( 我必须将单引号替换为双引号。 context.variables.getValueordEfault&lt; int&gt;(“ retrycounter”,0)

用于测试我创建了两个模拟服务:

返回状态代码200:
httpps://rfqapiservicey27itmeb4cf7q.azure-azure-api.azure-api.azure-api.azure-api.azure-api.azure-api.azure-api.azure-api.azure-api.azure-api.azure-apo.azure-apo.azure-pechure/2 >

返回状态代码403:
https:// https://rfqapiservicey27itmeb4cf7q.azure-azure-azure-echure-echure-echure-apoi teast/403 >

重试 后端部分将永远不会返回到 inbound 部分。因此,选择条件仅在一开始就受到打击。

因此,选择条件必须移至后端部分。

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

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

backend 请求请求403资源:

此请求失败,重试策略在 Backend e节:

当将返回 200 并留下后端部分:

I had to replace the single quotes to double quotes because of an error on save:

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

For testing I created two mocked services:

Returns status code 200:
https://rfqapiservicey27itmeb4cf7q.azure-api.net/echo/200/test

Returns status code 403:
https://rfqapiservicey27itmeb4cf7q.azure-api.net/echo/403/test

The retry section in the backend section will never return to the inbound section. So the choose condition was only hit at the very beginning.

Therefore, the choose condition has to be moved to the backend section.

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

enter image description here

My sample operation executes as expected:

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

enter image description here

The first hit in the backend requests the 403 resource:
enter image description here

This request is failing, and the retry policy sets the 200 in the backend section:
enter image description here

This second request is successful when will return 200 and leave the backend section:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文