Metering Policy Configuration

Revenium uses a lightweight custom policy to asynchronously send metering metadata to a Metering Beacon.

The Revenium metering policy relies on DataWeave expressions, which are only available in MuleSoft Enterprise Edition.

Installing the Revenium Metering Policy

The Revenium Metering Policy can be obtained from the Revenium Customer Success Team. Once you’ve obtained the policy, you can uncompress it and follow these steps:

  1. Open the pom.xml file and replace the two instances of the "ANYPOINT_GROUPID" placeholder with your Anypoint Organization ID:

    1. "groupId" field

    2. “exchange.url” field

  2. Ensure your Maven settings.xml file has an "exchange-server" defined along with the MuleSoft Enterprise repository with appropriate access credentials. Here is a minimal settings.xml file to publish a Custom Policy:

Run the following command:

mvn --settings hc-settings.xml clean deploy -Dapplication.groupId=GROUP_ID`` ``-Dexchange.username=EXCHANGE_USERNAME`` ``-Dexchange.password=EXCHANGE_PASSWORD`` ``-Dmule.username=MULESOFT_NEXUS_USER`` ``-Dmule.password=MULESOFT_NEXUS_PASSWORD

If you are using MFA then you will need to create a Connected App within Anypoint Platform (https://docs.mulesoft.com/access-management/connected-apps-overview) and use the associated client_id and client_secret for the exchange parameters above.

The Exchange Maven plugin requires Java 8 to run properly. You can set your JAVA_HOME for Maven like this:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home

The Revenium Metering Policy should now be available in the Anypoint Platform Exchange:

Configuring the Revenium Metering Policy

In order to configure the policy we need to have created an Asset, a Product, a Product License, and an Application, which are described in depth here.

We then need to obtain the API’s ID from Revenium. The API’s ID in Revenium is required to meter the API through an Anypoint API Gateway.

Navigate to the Manage → Assets tab. Select an Asset and click on the “copy” icon to copy the APIs ID. Paste the ID somewhere you can refer to it later:

An upcoming Revenium release will automate the process of obtaining the Asset ID.

In the Anypoint API Manager, navigate to the API to be metered:

Navigate to “Policies” and then “Apply New Policy”:

Select the Revenium Metering Policy:

The Metering Policy takes the following configuration parameters:

  • Metering Beacon Host: The hostname of the Metering Beacon. You can leave this as the default

  • Metering Beacon API Key: The Revenium API integration key. This is obtained via Manage -> External Configurations -> API Integration Keys.

  • Revenium Asset ID: The ID of the API. Use the ID of the API we copied earlier from the Revenium User Interface.

  • Metering Expression: An optional DataWeave expression that determines whether or not an API request should be metered. The default behavior is to meter any request that has a 2xx series (successful) response from the API implementation.

  • Product License Expression: An optional DataWeave expression to extract the Revenium Product License from the API request. The default behavior is to determine the header from either the X-REVENIUM-PRODUCT-KEY __ or, if its not present, using the "client_id" header.

  • Client ID Expression: An optional DataWeave expression to extract the Anypoint Client ID from the API request. The default behavior is to use the "client_id" header. For more information on linking Anypoint Client IDs to Revenium please see the documentation here.

  • Metadata Expression: An optional DataWeave expression to extract arbitrary metadata from the API request.

  • Metering Header Name: An optional backend-provided header that contains a dynamic call count for metering

  • Reject Requests with Invalid Product Licenses: If a request contains an invalid Product License (ie, the key is expired, its quota has been exceeded, etc) then the policy will block the request and return a 402 "Payment Required" response.

  • Reject Requests with Missing Monetization Headers: Reject requests that are missing a Product License or Client ID expression

  • Product License Cache TTL (Minutes): If Reject Requests with Invalid Product Licenses is enabled the amount of time to cache invalid keys.

  • Async Mode: Whether or not to run in async mode (enabling can adversely affect performance in non-multicore machines)

  • WebSocket Mode: Enable WebSocket mode for extremely high throughput use cases.

Async Mode is recommended for best performance when utilizing 2+ vCore CloudHub Workers or on-premise runtimes. It is not recommended when using 1 vCore or fractional vCores.

WebSocket Mode is experimental, please contact the Revenium Customer Success team for advice on when to enable this option.

The Policy should now be applied and your API is now ready to be metered.

Configuring Revenium Metering as an Automated Policy

Revenium Metering Policy can be configured as an Automated Policy to ensure that all APIs registered with the Anypoint Platform are metered.

To configure an Automated Policy navigate to "Automated Policies" and click on "Add Automated Policy".

You can then configure the policy as defined in the previous step making sure to leave the "Revenium Asset ID" to be blank.

API URL/URIs must be unique for the Revenium Metering Policy to function correctly when applied automatically. The Revenium Asset ID must be set in APIs with non-unique URLs.

Last updated

© Revenium - www.revenium.io