在APIM中,目前我们有产品订阅键级节流。但是,很明显,如果同一产品中有多个API,那么一个API可能会消耗比预期更多的配额,并阻止其他API能够使用该应用程序。因此,根据MS文档(https://learn.microsoft.com/en-us/azure/api-management/api-management-sample-flexible-throttling),我们可以使用组合策略。
现在的问题是,我们是否可以这样做,
API-1 300 calls per 60 seconds where product subscription key =123
API-2 200 calls per 60 seconds where product subscription key =123
API-3 200 calls per 60 seconds where product subscription key =123如果是的话,对产品订阅键的调用总数可以是多少?如果这有意义的话。
我采取了下面的方法,把政策结合起来。但它不喜欢。
<rate-limit-by-key calls="50" renewal-period="60" counter-key="@("somevalue" + context.Request.Headers.GetValueOrDefault("Ocp-Apim-Subscription-Key"))" />
<rate-limit calls="10" renewal-period="30">
<api name="AddressSearch API dev" calls="5" renewal-period="30" />
<operation name="Search_GetAddressSuggestions" calls="3" renewal-period="30" />
</rate-limit>发布于 2018-12-19 00:37:49
因此,为了使速率限制API水平,我已经提出了以下,以满足我的要求。
<choose>
<when condition="@(context.Operation.Id.Equals("End point name1"))">
<rate-limit-by-key calls="40" renewal-period="30" counter-key="@(context.Api.Name + context.Operation.Name + context.Request.Headers.GetValueOrDefault("Ocp-Apim-Subscription-Key"))" />
</when>
<when condition="@(context.Operation.Id.Equals("End point name2"))">
<rate-limit-by-key calls="20" renewal-period="30" counter-key="@(context.Api.Name + context.Operation.Name + context.Request.Headers.GetValueOrDefault("Ocp-Apim-Subscription-Key"))" />
</when>
<otherwise>
<rate-limit-by-key calls="15" renewal-period="30" counter-key="@(context.Api.Name + context.Operation.Name + context.Request.Headers.GetValueOrDefault("Ocp-Apim-Subscription-Key"))" />
</otherwise>
</choose>希望这能有所帮助。
发布于 2018-12-11 19:26:03
重要的是要明白,逐键利率和利率限制的计数器是独立的.
当按键的速率限制允许请求通过时,它增加了它的计数器。当速率限制允许请求通过时,它增加了计数器的.在您的配置中,当按键速度限制节流请求时,速率限制将不会被执行,也不会计算请求。
这意味着,在大多数情况下,下限获胜。您的配置将允许一次订阅,每分钟打50个电话,但这不太可能有任何区别,因为二流限制政策将节流后,10个调用相同的产品,因此第一个将没有任何机会做任何事情。
如果像样例一样需要限制,可以按照以下方式使用配置:
<rate-limit calls="0" renewal-period="0">
<api name="API-1" calls="100" renewal-period="60" />
<api name="API-2" calls="200" renewal-period="60" />
<api name="API-3" calls="300" renewal-period="60" />
</rate-limit>发布于 2018-12-10 17:47:54
为了确认-您正在根据订阅键在API级别上设置三个节流策略:
API-1: 300 calls per 60 seconds API-2: 200 calls per 60 seconds API-3: 200 calls per 60 seconds
在这种情况下,如果这些是您唯一的API,那么每60秒每个订阅键的最大请求数是: 300 + 200 + 200 = 700。
如果您有更多的API,则除非为它们指定策略,否则不会限制它们。
https://stackoverflow.com/questions/53690281
复制相似问题