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>

在本範例中,您會將目標配額政策的名稱和配額數量的變更,以要求中的標頭形式傳遞。接著,您可以在「重設配額」政策中參照含有這些值的流程變數。

指定 ID

<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>
預設值: 不適用
外觀狀態: 必填
類型: 不適用

屬性

屬性 說明 預設 存在必要性
名稱

指定目標配額政策的名稱。

不適用 選用
ref 包含目標配額政策名稱的流程變數。如果同時指定 refname,則 ref 的優先順序較高。如果 ref 在執行階段無法解析,系統就會使用 name 不適用 選用

<Quota>/<Identifier> 元素

如果目標配額政策指定 <Identifier> 標記,則此變數會用於識別計數器。

<Quota name="quotaName">
   <Identifier name="identifierName" ref="request.header.identifier">
      <Allow>100</Allow>
   </Identifier>
</Quota>
預設值: 不適用
外觀狀態: 必填
類型: 字串

屬性

屬性 說明 預設 存在必要性
名稱

指定目標配額政策中的計數 ID 名稱。如果配額政策未使用 <Identifier> 標記,請指定 _default

不適用 選用
ref

流程變數,包含目標配額政策中的計數 ID 名稱。如果同時指定 refnameref 的優先順序較高。如果 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 傳回的錯誤代碼和錯誤訊息,以及 Apigee 設定的錯誤變數。如果您要開發錯誤處理規則,就必須瞭解這項資訊。如需更多資訊,請參閱「關於政策錯誤的相關資訊」和「處理錯誤」。

執行階段錯誤

政策執行時可能會發生這些錯誤。

錯誤代碼 HTTP 狀態 原因 修正
policies.resetquota.InvalidRLPolicy 500 ResetQuota 政策的 <Quota> 元素中指定的 Quota 政策並未在 API Proxy 中定義,因此在流程中無法使用。<Quota> 元素為必要元素,可識別目標 Quota 政策,其計數器應透過 ResetQuota 政策更新。
policies.resetquota.FailedToResolveAllowCountRef 不適用 政策 <Allow> 元素中含有允許計數的變數參照無法解析為值。此元素為必要元素,可指定減少配額計數器的金額。
policies.resetquota.FailedToResolveRLPolicy 500 無法解析 <Quota> 元素中 ref 屬性參照的變數。

部署錯誤

部署含有這項政策的 Proxy 時,可能會發生這些錯誤。

錯誤名稱 原因 修正
InvalidCount 如果 ResetQuota 政策的 <Allow> 元素中指定的計數值不是整數,則 API 代理程式會部署失敗。

結構定義

相關主題

配額政策