Azure 的速率限制策略,用于限制特定订阅无法按预期工作

问题描述 投票:0回答:1
azure azure-api-management rate-limiting
1个回答
0
投票

我使用了相同的策略来免除正在使用的订阅密钥

rate-limit
策略。

出于测试目的,我接听了 10 个电话。

<policies>
    <inbound>
        <base />
        <choose>
            <when condition="@(context.Subscription.Name=="test")" />
            <when condition="@(context.Subscription.Name=="demo")" />
            <otherwise>
                <rate-limit calls="10" renewal-period="300" remaining-calls-variable-name="remainingCallsPerSubscription" />
            </otherwise>
        </choose>
    </inbound>
    <backend>
        <base />
    </backend>
    <outbound>
        <base />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>

测试时,您需要传递订阅密钥名称为Ocp-Apim-Subscription-Key,该值将是您的订阅密钥的值,否则它将获取

context.Subscription.Name
的值作为
Built-in all-access subscription
默认情况下。

enter image description here enter image description here

context.Subscription.Name
的值为 false 时,我得到如下所示的预期响应。

enter image description here

enter image description here enter image description here

为了获得预期的响应,请确保您没有在全局或 API 级别定义任何其他策略。

© www.soinside.com 2019 - 2024. All rights reserved.