ResetQuota 政策

本页面适用于 ApigeeApigee Hybrid

查看 Apigee Edge 文档。

政策图标

是什么

用于动态修改目标配额政策允许的剩余请求数。您通常可利用此政策来减少目标配额政策的当前配额计数,而不是等待配额重置。

例如,目标配额政策将开发者限制为每周 1000 个请求。在一周的第二天,开发者已达到此限制。使用“重置配额”政策从配额计数器中减去 500 个,以允许在本周剩余时间内使用其他 500 个请求。在一周结束时,配额政策会重置,开发者将恢复到一周 1000 个请求。

此政策是一项可扩展政策,使用此政策可能会影响费用或使用情况,具体取决于您的 Apigee 许可。如需了解政策类型和使用情况影响,请参阅政策类型

如需详细了解配额政策,请参阅配额政策。另请参阅这篇社区帖子,了解如何使用“重置配额”政策。

示例

以下政策代码示例说明了如何重置配额计数器:

重置默认计数器

<ResetQuota name="resetQuota">
   <Quota name="MyQuotaPolicy">
      <Identifier name="_default">
         <Allow>100</Allow>
      </Identifier>
   </Quota>
</ResetQuota>

重置配额政策使用 <Quota> 标记的 name 特性来指定目标配额政策。在上面的示例中,MyQuotaPolicy 政策是目标。

所有重置配额政策都需要使用 <Identifier> 标记来指定要更新的配额政策中的计数器。默认情况下,配额政策只有一个计数器,除非配额政策也包括 <Identifier> 标记。在此示例中,目标配额政策不使用 <Identifier> 标记,因此您可指定 name 特性作为 _default

<Allow> 元素指定用于减少目标政策的当前配额计数的值。在此示例中,配额计数减少了 100,以允许目标配额政策增加 100 个请求。当目标配额政策重置时,此更改会被丢弃。

目标配额政策的定义如下所示:

<Quota name="MyQuotaPolicy">
  <Interval>5</Interval>
  <TimeUnit>hour</TimeUnit>
  <Allow count="100"/>
</Quota>

使用引用

<ResetQuota name="resetQuota">
   <Quota ref="request.header.quotapolicy">
      <Identifier name="_default">
         <Allow ref="request.header.allowquota" />
      </Identifier>
   </Quota>
</ResetQuota>

在此示例中,您将以请求标头的形式传递目标配额政策的名称及其配额计数更改。然后,您可以在重置配额政策中引用包含这些值的流变量。

指定标识符

<ResetQuota name="resetQuota">
   <Quota name="QuotaPolicy">
      <Identifier ref="request.header.clientId">
         <Allow>100</Allow>
      </Identifier>
   </Quota>
</ResetQuota>

如果目标配额政策指定 <Identifier> 标记,则您可以为重置配额政策的 <Identifier> 标记指定相同的值,以更新特定配额计数。注意以下目标配额政策中的 <Identifier> 标记如何与为重置配额政策指定的值匹配:

<Quota name="QuotaPolicy">
  <Identifier ref="request.header.clientId"/> 
  <Interval>5</Interval>
  <TimeUnit>hour</TimeUnit>
  <Allow count="100"/>
</Quota>

元素参考

元素参考描述了重置配额政策的元素和特性。

<ResetQuota async="false" continueOnError="false" enabled="true" name="Reset-Quota-1">
   <DisplayName>Reset Quota 1</DisplayName>
   <Quota name="quotaName" ref="request.header.quotapolicy">
      <Identifier name="identifierName" ref="request.header.identifier">
         <Class ref="request.header.classIdentifier" />
         <Allow>100</Allow>
      </Identifier>
   </Quota>
</ResetQuota>

<ResetQuota> 特性

<ResetQuota async="false" continueOnError="false" enabled="true" name="Reset-Quota-1"> 

The following table describes attributes that are common to all policy parent elements:

Attribute Description Default Presence
name

The internal name of the policy. The value of the name attribute can contain letters, numbers, spaces, hyphens, underscores, and periods. This value cannot exceed 255 characters.

Optionally, use the <DisplayName> element to label the policy in the management UI proxy editor with a different, natural-language name.

N/A Required
continueOnError

Set to false to return an error when a policy fails. This is expected behavior for most policies.

Set to true to have flow execution continue even after a policy fails. See also:

false Optional
enabled

Set to true to enforce the policy.

Set to false to turn off the policy. The policy will not be enforced even if it remains attached to a flow.

true Optional
async

This attribute is deprecated.

false Deprecated

<DisplayName> element

Use in addition to the name attribute to label the policy in the management UI proxy editor with a different, natural-language name.

<DisplayName>Policy Display Name</DisplayName>
Default

N/A

If you omit this element, the value of the policy's name attribute is used.

Presence Optional
Type String

<Quota> 元素

标识应更新计数器的目标配额政策。

<Quota name="quotaName"  ref="request.header.quotapolicy">
   <Identifier name="identifierName" ref="request.header.identifier">
      <Allow>100</Allow>
   </Identifier>
</Quota>
默认: 不适用
状态: 需要
类型: 不适用

属性

属性 说明 默认值 状态
name

指定目标配额政策的名称。

不适用 可选
ref 包含目标配额政策名称的流变量。如果同时指定了 refname,则 ref 优先。如果 ref 在运行时没有解析,则使用 name 不适用 可选

<Quota>/<Identifier> 元素

目标配额政策指定 <Identifier> 标记时用于唯一标识计数器的变量。

<Quota name="quotaName">
   <Identifier name="identifierName" ref="request.header.identifier">
      <Allow>100</Allow>
   </Identifier>
</Quota>
默认: 不适用
状态: 需要
类型: 字符串

属性

属性 说明 默认值 状态
name

在目标配额政策中指定计数标识符的名称。对于不使用 <Identifier> 标记的配额政策,请指定 _default

不适用 可选
ref

包含目标配额政策中的计数标识符名称的流变量。如果同时指定了 refname,则 ref 优先。如果 ref 在运行时没有解析,则使用 name

不适用 可选

<Quota>/<Identifier>/<Allow> 元素

指定减少配额计数器的数量。您必须指定 <Allow>,否则政策不会修改配额。

<Identifier name="identifierName" ref="request.header.identifier">
   <Allow ref="request.header.allowquota">100</Allow>
</Identifier>
默认: 不适用
状态: 需要
类型: 整数

属性

属性 说明 默认值 状态
ref

包含目标配额政策中的配额计数更改的流变量。

不适用 可选

<Quota>/<Identifier>/<Class> 元素

指定更新配额计数器的类。如需详细了解如何将类与配额政策搭配使用,请参阅配额政策

<Identifier name="_default">
   <Class ref="request.header.classIdentifier">
     <Allow>200</Allow>
   </Class>
</Identifier>
默认: 不适用
状态: 可选
类型: 不适用

属性

属性 说明 默认值 状态
ref

引用包含要更新的配额类的流变量。

不适用 可选

错误参考信息

本部分介绍当此政策触发错误时返回的故障代码和错误消息,以及由 Apigee 设置的故障变量。在开发故障规则以处理故障时,请务必了解此信息。如需了解详情,请参阅您需要了解的有关政策错误的信息处理故障

运行时错误

政策执行时可能会发生这些错误。

故障代码 HTTP 状态 原因 修复
policies.resetquota.InvalidRLPolicy 500 ResetQuota 政策的 <Quota> 元素中指定的 Quota 政策未在 API 代理中定义,因此在流中不可用。<Quota> 元素是必填的,并且识别 Quota 政策(该政策的计数器应通过 ResetQuota 政策来更新)。
policies.resetquota.FailedToResolveAllowCountRef 不适用 对政策的 <Allow> 元素中包含允许计数的变量的引用无法解析为值。此元素是必需的,并指定减少配额计数器的数量。
policies.resetquota.FailedToResolveRLPolicy 500 无法解析 <Quota> 元素中的 ref 属性引用的变量。

部署错误

在您部署包含此政策的代理时,可能会发生这些错误。

错误名称 原因 修复
InvalidCount 如果在 ResetQuota 政策的 <Allow> 元素中指定的计数值不是整数,则 API 代理的部署将会失败。

架构

相关主题

配额政策