LogoLogo
  • User Guide
    • Getting Started
      • Building a Usage-Based Product in Revenium
      • Setting Up & Using API Analytics & Observability
      • Setting Up & Using Product Analytics
      • Sending Data to Revenium's Metering API
      • Key Concepts & Relationships
    • Connect Your Data
      • cURL Commands for Testing
      • Container-Native Metering
      • Kong
        • Kubernetes Installation
      • Salesforce
        • Revenium Unmanaged Package
          • Anypoint API Experience Hub (AEH)
            • Anypoint API Experience Hub Unmanaged Package Post Installation Instructions
          • Anypoint Community Manager (ACM)
            • Anypoint Community Manager Package Post Installation Instructions
        • Revenium Lightning Web Components
          • Add Components to Experience Cloud site
          • Drop-In Storefront
          • Product Card
          • Product Card (Anypoint)
          • Product Checkout
          • Product Details Button
          • Usage History
          • API Access Requester
      • MuleSoft
        • Metering Policy Configuration
        • Offline Metering Policy Configuration
        • Anypoint API & API Group Synchronization
        • Revenium Connector
        • Disable Default Anypoint Community Manager (ACM) Email Notifications
      • Gravitee
      • Istio
      • Envoy
      • AWS API Gateway
      • Python & Django
      • Golang
      • Spring Boot
      • .Net
      • NodeJs
      • Java/JVM
      • Snowflake
      • Azure API Management
      • IBM
      • Custom Integrations Using Metering Beacons
        • JWT Enrichment
      • Offline Metering via Log Parsing
    • Sources
      • Metering Elements
      • Alerts
        • Alert History
    • API Keys
    • Products & Pricing
      • Product Lines
      • Pricing Rules
        • Revenium Scripting Language
          • RSL Reference
        • Execution Logs
      • SLA Definitions
      • SLA Violation Review
    • Customers
      • Customers
      • Subscribers
      • Subscriptions
      • Subscribers Credentials
      • Subscribers Notifications
    • Billing and Invoicing
      • Manage Refunds
    • Analytics
      • Revenue Analytics
      • Product Analytics
        • Custom Reports (Products)
      • Subscriber Analytics
        • New Subscribers
        • (Daily/Weekly/Monthly) Active Subscribers
        • Most Engaged Subscribers & Customers
        • Historical Usage
      • API Analytics
        • Performance & Availability
        • Compare Periods
        • Traffic by Geography
        • Advanced Search
        • Custom Reports
    • Profile
      • Profile
      • Revenium API Documentation
    • Settings
      • Revenium Users & Organizations
        • Access Permissions by User Type
      • Revenium Subscription
      • Revenium Organizations
      • Notification Templates
      • Transactions Logs
        • Analytics Transaction Log
        • Product Transaction Log
        • Subscription Audit Log
        • No Code Transaction Testing
      • Integrations
        • Data Sync
        • Export Configurations
        • Notification Providers
        • Payment Configurations
          • Customer VAT ID Support
        • ERP Configurations
        • External Integration Logs
        • Identity Providers
      • System Logs
      • Default Configuration Limits
Powered by GitBook

© Revenium - www.revenium.io

On this page
  • Installation
  • Maven
  • Gradle
  • Configuration
  • Usage
  • Example Usage in a REST Controller
  1. User Guide
  2. Connect Your Data

Spring Boot

Revenium provides a Spring Boot Starter to easily meter method invocations in Spring Boot applications.

Installation

You'll need to add the Revenium dependency to either your pom.xml or build.gradle file.

Maven

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.revenium.metering</groupId>
    <artifactId>revenium-spring-boot-starter</artifactId>
    <version>1.0.0</version>
</dependency>

Gradle

implementation 'io.revenium.metering:revenium-spring-boot-starter:1.0.0'

Configuration

You'll need to add the following properties to your application.properties or application.yml file:

revenium.metering.api-key=hak_api_key
revenium.metering.url=https://api.revenium.io/meter/v1/api
revenium:
  metering:
    api-key: hak_api_key
    url: https://api.revenium.io/meter/v1/api

Usage

The Revenium Spring Boot starter provides an aspect that can be annotated on a method to send metering data to the Revenium platform. This can be applied to any method in your Spring Boot application but is typically used to meter REST controller or service method invocations.

The annotation accepts the following parameters:

  • subscriptionId: The subscription id identifying who is consuming the data

  • sourceId: The source (asset) id of the metering data

  • elements: A JSON string representing the metering elements to send to the Revenium platform. This can be a JSON string or a SpEL expression that evaluates to a JSON string. The SpEL expression can reference the method arguments and return value.

The metered aspect provides "result" and "args" context variables ino the SpEL expression. The "result" variable contains the return value of the method being metered and the "args" variable contains the method arguments.

Example Usage in a REST Controller

Here's an example of how to use the @Metered annotation on a REST controller POST operation:

@PostMapping
@Metered(
        subscriptionId = "#args[1]",
        sourceId = "'text-summarizer'",
        elements = "{'tokens': #result.tokensConsumed}"
)
public SummarizationResponse summarize(@RequestBody SummarizationRequest request,
                                              @RequestHeader("x-api-key") String apiKey) {
    SummarizationResult result = summarizationService.summarize(request.getText());
    SummarizationResponse response = new SummarizationResponse();
    response.setText(result.getText());
    response.setTokensConsumed(result.getTokensConsumed());
    return response;
}

This example sends metering data to the Revenium platform when the summarize method is invoked. The sourceId is statically set to "text-summarizer" and the subscriptionId is dynamically set to the second argument of the method. The metering elements are set to a JSON object containing the number of LLM tokens consumed by the method.

Last updated 10 months ago