本頁適用於 Apigee 和 Apigee Hybrid。
查看
Apigee Edge 說明文件。
結果
用於動態修改目標配額政策允許的剩餘要求數量。您通常會使用這項政策來減少目標配額政策的目前配額計數,而非等待配額計數重設。
舉例來說,目標配額政策會限制開發人員每週只能提出 1000 次要求。到了當週的第二天,開發人員就已達到這個上限。使用「Reset Quota」政策,從配額計數器中減去 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> 標記與「Reset Quota」政策指定的值相符:
<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">
下表說明所有政策父項元素的共同屬性:
屬性 | 說明 | 預設 | 存在必要性 |
---|---|---|---|
name |
政策的內部名稱。 您可以選擇使用 |
不適用 | 必填 |
continueOnError |
將其設為 將其設為 |
false | 選用 |
enabled |
設為 設為 |
是 | 選用 |
async |
此屬性已淘汰。 |
false | 已淘汰 |
<DisplayName> 元素
除了 name
屬性之外,您也可以在管理 UI 代理程式編輯器中使用不同的自然語言名稱標示政策。
<DisplayName>Policy Display Name</DisplayName>
預設 |
不適用 如果省略這個元素,系統會使用政策的 |
---|---|
存在必要性 | 選用 |
類型 | 字串 |
<Quota> 元素
指出應更新計數器的目標配額政策。
<Quota name="quotaName" ref="request.header.quotapolicy"> <Identifier name="identifierName" ref="request.header.identifier"> <Allow>100</Allow> </Identifier> </Quota>
預設值: | 不適用 |
外觀狀態: | 必填 |
類型: | 不適用 |
屬性
屬性 | 說明 | 預設 | 存在必要性 |
---|---|---|---|
名稱 |
指定目標配額政策的名稱。 |
不適用 | 選用 |
ref | 包含目標配額政策名稱的流程變數。如果同時指定 ref 和 name,則 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 名稱。如果同時指定 ref 和 name,則 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 傳回的錯誤代碼和錯誤訊息,以及 Apigee 設定的錯誤變數。如果您要開發錯誤處理規則,就必須瞭解這項資訊。如需更多資訊,請參閱「關於政策錯誤的相關資訊」和「處理錯誤」。
執行階段錯誤
政策執行時可能會發生這些錯誤。
錯誤代碼 | HTTP 狀態 | 原因 | 修正 |
---|---|---|---|
policies.resetquota.InvalidRLPolicy |
500 |
ResetQuota 政策的 <Quota> 元素中指定的 Quota 政策並未在 API Proxy 中定義,因此在流程中無法使用。<Quota> 元素為必要元素,可識別目標 Quota 政策,其計數器應透過 ResetQuota 政策更新。 |
build |
policies.resetquota.FailedToResolveAllowCountRef |
不適用 | 政策 <Allow> 元素中含有允許計數的變數參照無法解析為值。此元素為必要元素,可指定減少配額計數器的金額。 |
build |
policies.resetquota.FailedToResolveRLPolicy |
500 |
無法解析 <Quota> 元素中 ref 屬性參照的變數。 |
build |
部署錯誤
部署含有這項政策的 Proxy 時,可能會發生這些錯誤。
錯誤名稱 | 原因 | 修正 |
---|---|---|
InvalidCount |
如果 ResetQuota 政策的 <Allow> 元素中指定的計數值不是整數,則 API 代理程式會部署失敗。 |
build |