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 "Connect Data" section in the Revenium UI. 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=292a3440-884f-49d7-8c82-b1a1d3641367 \
-Dexchange.username=YOUR_EXCHANGE_USERNAME \
-Dexchange.password=YOUR_EXCHANGE_PASSWORD \
-Dmule.username=MULE_NEXUS_REPO_USERNAME \
-Dmule.password=MULE_NEXUS_REPO_PASSWORD

To use a different control plane, such as the EU control plane, you can pass a base platform URL using the mule.platform.baseUrl variable. For example:

mvn --settings hc-settings.xml clean deploy \
-Dapplication.groupId=292a3440-884f-49d7-8c82-b1a1d3641367 \
-Dexchange.username=YOUR_EXCHANGE_USERNAME \
-Dexchange.password=YOUR_EXCHANGE_PASSWORD \
-Dmule.username=MULE_NEXUS_REPO_USERNAME \
-Dmule.password=MULE_NEXUS_REPO_PASSWORD \
-Dmule.platform.baseUrl=eu1.anypoint.mulesoft.com

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 follow the instructions here: https://docs.mulesoft.com/exchange/connected-app-authentication.

Specifically you must:

  • set "exchange.user" to ~~client~~~

  • set "exchange.password" to CLIENT_ID~?~CLIENT_SECRET

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 a Source, a Product, a Subscription, and Credentials, which are described in depth here.

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:

  • Revenium Platform URL: Base URL of the Revenium platform API

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

  • Revenium Source 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.

  • Subscription Expression: An optional DataWeave expression to extract the Revenium Subscription 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.

  • Subscription Credential 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 Subscriptions: If a request contains an invalid Subscription (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.

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

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 Source ID" to be blank.

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

Last updated

© Revenium - www.revenium.io