MonetizationLimitsCheck 政策

<ph type="x-smartling-placeholder"></ph> 您正在查看 Apigee Edge 文档。
转到 Apigee X 文档
信息

概览

通过 MonetizeLimitsCheck 政策,您可以对发出的 API 调用强制执行变现限制 由应用开发者提供

下面列举了一些会触发政策的情况:

  • 如果访问用于创收的 API 的应用开发者尚未购买 关联的 API 产品
  • 开发者的账号余额不足。
  • 开发者已超出交易量限制。

如需了解如何将政策附加到 API 代理,请参阅 对 API 代理强制执行创收上限

<MonetizationLimitsCheck> 元素

指定 MonetizationLimitsCheck 政策。

默认值 不适用
是否必需? 必填
类型 复杂类型
父元素 不适用
子元素 <DisplayName>
<FaultResponse>
<IgnoreUnresolvedVariables>
<Variables>

下表提供了 <MonetizationLimitsCheck> 的子元素的简要说明:

子元素 是否必需? 说明
<DisplayName> 可选 政策的自定义名称。
<FaultResponse> 可选 指定在以下情况下返回给请求客户端的响应消息: 引发故障
<IgnoreUnresolvedVariables> 可选 确定在遇到无法解析的变量时处理是否停止。
<Variables> 可选 指定要检查变现限制的流程变量。

<MonetizationLimitsCheck> 元素使用以下语法:

语法

<?xml version="1.0" encoding="UTF-8"?>
<MonetizationLimitsCheck async="false" continueOnError="false" enabled="true" name="POLICY_NAME">
    <DisplayName>DISPLAY_NAME</DisplayName>
    <IgnoreUnresolvedVariables>[true|false]</IgnoreUnresolvedVariables>
    <Variables>
        <Product>VARIABLE_NAME</Product>
    </Variables>
    <FaultResponse>
        <Set>
            <Payload contentType="text/xml">
                <error>
                    <messages>
                        <message>MESSAGE_TEXT</message>
                        <message>MESSAGE_TEXT</message>
                    </messages>
                </error>
            </Payload>
            <StatusCode>HTTP_STATUS</StatusCode>
            <ReasonPhrase>REASON_TEXT</ReasonPhrase>
        </Set>
    </FaultResponse>
</MonetizationLimitsCheck>

示例

以下示例展示了 MonetizeLimitsCheck 政策定义:

<?xml version="1.0" encoding="UTF-8"?>
<MonetizationLimitsCheck async="false" continueOnError="false" enabled="true" name="Monetization-Limits-Check">
    <DisplayName>Monetization Limits Check</DisplayName>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <Variables>
        <Product>myproductvar.name</Product>
    </Variables>
	<FaultResponse>
	        <Set>
	            <Payload contentType="text/xml">
	                <error>
	                    <messages>
	                        <message>Developer has reached usage quota</message>
	                        <message>Is Developer Suspended - {monetizationLimits.isDeveloperSuspended} </message>
	                    </messages>
	                </error>
	            </Payload>
	            <StatusCode>403</StatusCode>
	            <ReasonPhrase>Forbidden</ReasonPhrase>
	        </Set>
	</FaultResponse>
 </MonetizationLimitsCheck>

This element has the following attributes that are common to all policies:

Attribute Default Required? Description
name N/A Required

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.

continueOnError false Optional 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.
enabled true Optional 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.
async   false Deprecated This attribute is deprecated.

子元素参考

本部分介绍 <MonetizationLimitsCheck> 的子元素。

<DisplayName>

除了用于 name 属性之外,还可用于在管理界面代理编辑器中使用其他更加自然的名称标记政策。

<DisplayName> 元素适用于所有政策。

默认值 不适用
是否必需? 可选。如果省略 <DisplayName>,则会使用政策的 name 属性的值
Type 字符串
父元素 <PolicyElement>
子元素

<DisplayName> 元素使用以下语法:

语法

<PolicyElement>
  <DisplayName>policy_display_name</DisplayName>
  ...
</PolicyElement>

示例

<PolicyElement>
  <DisplayName>My Validation Policy</DisplayName>
</PolicyElement>

<DisplayName> 元素没有属性或子元素。

<IgnoreUnresolvedVariables>

确定当 Apigee 遇到未解析变量时是否应停止处理政策。

默认值
是否必需? 可选
类型 布尔值
父元素 <MonetizationLimitsCheck>
子元素

如需忽略未解析的变量并继续处理,请将值设置为 true; 否则为 false。默认值为 true

<IgnoreUnresolvedVariables> 设置为 true 与设置 <MonetizationLimitsCheck> 元素的 continueOnErrortrue。如果将 continueOnError 设置为 true,则 Apigee 会忽略 仅包含变量错误,而是所有错误。

<IgnoreUnresolvedVariables> 元素使用以下语法:

语法

<IgnoreUnresolvedVariables>[true|false]</IgnoreUnresolvedVariables>

示例

以下示例将 <IgnoreUnresolvedVariables> 设置为 false

<IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>

<Variables>

指定要从中提取 实体或资源名称。

您只能在 <Variables> 元素中指定 <Product> 元素。Apigee 获得的 <Product> 元素中指定的流程变量中的 API 产品名称。如果您 未指定 <Variables> 元素,则 Apigee 会默认从 apiproduct.name 上下文变量。通过使用 API 产品名称,Apigee 可获取 为产品创建对应的费率方案,并检查创收限额。

默认值 不适用
是否必需? 可选
类型 复杂类型
父元素 <MonetizationLimitsCheck>
子元素 <Product>

<Variables> 元素使用以下语法:

语法

<Variables>
    <Product>VARIABLE_NAME</Product>
</Variables>

示例

以下示例从 myproductvar.name 自定义流程变量获取 API 产品名称 。

<Variables>
    <Product>myproductvar.name</Product>
</Variables>

您可以使用 AssignMessageJavaScript 等政策设置自定义流变量。

<Product>

指定具有 API 产品名称的变量。

默认值 不适用
是否必需? 可选
类型 字符串
父元素 <Variables>
子元素

<Product> 元素使用以下语法:

语法

<Product>VARIABLE_NAME</Product>

示例

以下示例从 myproductvar.name 自定义流程变量获取 API 产品名称 。

<Product>myproductvar.name</Product>

您可以使用 AssignMessageJavaScript 等政策设置自定义流变量。

<FaultResponse>

定义在发生故障时返回给请求客户端的响应消息。 你可以自定义回答 根据您的要求显示消息。如需详细了解 元素及其所有子元素,请参阅 FaultResponse

流变量

如果您将 <MonetizationLimitsCheck> 元素的 将 ContinueOnError 属性设置为 true,则不会引发任何错误。在这种情况下, 流变量 mint.limitsViolatedmint.isDeveloperSuspended 和 系统会自动设置 mint.limitsPolicyError。这些变量可用于 执行进一步的异常处理。