Interceptor rate limit

Enable rate limit interceptor/middleware for the server.


go get

General options

These are general options to start a grpc server with rk-boot

name description type default value Required The name of grpc server string “”, server won’t start Required
grpc.port The port of grpc server integer 0, server won’t start Required
grpc.enabled Enable grpc entry bool false Required
grpc.description Description of grpc entry. string "" Optional
grpc.enableReflection Enable grpc server reflection boolean false Optional
grpc.enableRkGwOption Enable RK style gateway server options. boolean false Optional
grpc.noRecvMsgSizeLimit Disable grpc server side receive message size limit boolean false Optional
grpc.gwMappingFilePaths The grpc gateway mapping file path []string [] Optional

Rate limit options

name description type default value
grpc.interceptors.rateLimit.enabled Enable rate limit interceptor boolean false
grpc.interceptors.rateLimit.algorithm Provide algorithm, tokenBucket and leakyBucket are available options string tokenBucket
grpc.interceptors.rateLimit.reqPerSec Request per second globally int 0
grpc.interceptors.rateLimit.paths.path gRPC full name string ""
grpc.interceptors.rateLimit.paths.reqPerSec Request per second by gRPC full method name int 0

Quick start

1.Create boot.yaml

  - name: greeter
    port: 8080
    enabled: true
      enabled: true          # Enable common service for testing
        enabled: false
        algorithm: "leakyBucket"
        reqPerSec: 0
          - path: "/rk.api.v1.RkCommonService/Healthy"
            reqPerSec: 0

2.Create main.go

package main

import (

// Application entrance.
func main() {
	// Create a new boot instance.
	boot := rkboot.NewBoot()

	// Bootstrap

	// Wait for shutdown sig


Send request

$ grpcurl -plaintext localhost:8080 rk.api.v1.RkCommonService.Healthy
Error invoking method "rk.api.v1.RkCommonService.Healthy": rpc error: code = ResourceExhausted desc = failed to query for service descriptor "rk.api.v1.RkCommonService": Slow down your request
$ curl -X GET localhost:8080/rk/v1/healthy
        "status":"Too Many Requests",
        "message":"Slow down your request.",
                "message":"[from-grpc] Slow down your request."