java.lang.Object
com.networknt.aws.lambda.handler.middleware.limit.RateLimiter

public class RateLimiter extends Object
Rate limit logic for native lambda. The config will define in the limit.yml config file. By default, Rate limit will handle on the server(service) level. But framework support client and address level limitation
Author:
Gavin Chen
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected com.networknt.limit.LimitConfig
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    RateLimiter(com.networknt.limit.LimitConfig config)
    Load config and initial model by Rate limit key.
  • Method Summary

    Modifier and Type
    Method
    Description
    com.networknt.limit.RateLimitResponse
    handleRequest(LightLambdaExchange exchange, com.networknt.limit.LimitKey limitKey)
     
    com.networknt.limit.RateLimitResponse
    Handle logic for Server type (key = server) rate limit
    protected com.networknt.limit.RateLimitResponse
    isAllowDirect(String directKey, String path, String type)
    Handle logic for direct rate limit setting for address, client and user.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • config

      protected com.networknt.limit.LimitConfig config
  • Constructor Details

    • RateLimiter

      public RateLimiter(com.networknt.limit.LimitConfig config) throws Exception
      Load config and initial model by Rate limit key.
      Parameters:
      config - LimitConfig object
      Throws:
      Exception - runtime exception
  • Method Details

    • handleRequest

      public com.networknt.limit.RateLimitResponse handleRequest(LightLambdaExchange exchange, com.networknt.limit.LimitKey limitKey)
    • isAllowDirect

      protected com.networknt.limit.RateLimitResponse isAllowDirect(String directKey, String path, String type)
      Handle logic for direct rate limit setting for address, client and user. Use the type for differential the address/client/user
      Parameters:
      directKey - direct key
      path - String
      type - String
      Returns:
      RateLimitResponse response
    • isAllowByServer

      public com.networknt.limit.RateLimitResponse isAllowByServer(String path)
      Handle logic for Server type (key = server) rate limit
      Parameters:
      path - String
      Returns:
      RateLimitResponse rate limit response