当前位置:网站首页>Grpc: implement service end flow restriction
Grpc: implement service end flow restriction
2022-06-24 02:54:00 【Trespass 】
Introduce
This article will show you how to gRPC Implementation in microservices 【 Current limiting 】 Interceptor / middleware .
We will use rk-boot To start up gRPC service .
Please visit the following address for a complete tutorial :
https://rkdocs.netlify.app/cn ( spare )
install
go get github.com/rookie-ninja/rk-boot go get github.com/rookie-ninja/rk-grpc
Quick start
1. establish boot.yaml
In order to verify , We started commonService,commonService Contains a series of commonly used API, for example /rk/v1/healthy.
We aim at /rk.api.v1.RkCommonService/Healthy Carry out current limiting treatment , Set to 0, other API Set to 100.
---
grpc:
- name: greeter # Name of grpc entry
port: 8080 # Port of grpc entry
enabled: true # Enable grpc entry
commonService:
enabled: true # Enable common service for testing
interceptors:
rateLimit:
enabled: true
reqPerSec: 100
# algorithm: "leakyBucket"
paths:
- path: "/rk.api.v1.RkCommonService/Healthy"
reqPerSec: 02. establish main.go
package main
import (
"context"
"github.com/rookie-ninja/rk-boot"
_ "github.com/rookie-ninja/rk-grpc/boot"
)
// Application entrance.
func main() {
// Create a new boot instance.
boot := rkboot.NewBoot()
// Bootstrap
boot.Bootstrap(context.Background())
// Wait for shutdown sig
boot.WaitForShutdownSig(context.Background())
}3. Folder structure
$ tree . ├── boot.yaml ├── go.mod ├── go.sum └── main.go 0 directories, 4 files
4. start-up main.go
$ go run main.go
5. verification
- Send a request to /rk/v1/healthy, Will be Current limiting .
{
"code":8,
"message":"Slow down your request.",
"details":[
{
"@type":"type.googleapis.com/rk.api.v1.ErrorDetail",
"code":8,
"status":"ResourceExhausted",
"message":"[from-grpc] Slow down your request."
}
]
}- Send a request to /rk/v1/info, normal
{
"appName":"demo",
"az":"",
"description":"Internal RK entry which describes application with fields of appName, version and etc.",
"docsUrl":[
],
"domain":"",
"gid":"20",
"homeUrl":"",
"iconUrl":"",
"keywords":[
],
"maintainers":[
],
"realm":"",
"region":"",
"startTime":"2021-10-25T01:15:48+08:00",
"uid":"501",
"upTimeSec":76,
"upTimeStr":"1 minute",
"username":"Dongxun Yin",
"version":"master-557da30"
}YAML Options
name | describe | type | The default value is |
|---|---|---|---|
grpc.interceptors.rateLimit.enabled | Start current limiting Lan Jie | boolean | false |
grpc.interceptors.rateLimit.algorithm | Current limiting algorithm , Support tokenBucket and leakyBucket | string | tokenBucket |
grpc.interceptors.rateLimit.reqPerSec | Global current limit | int | 0 |
grpc.interceptors.rateLimit.paths.path | gRPC Method path | string | "" |
grpc.interceptors.rateLimit.paths.reqPerSec | be based on gRPC The current limit of the method path | int | 0 |
边栏推荐
- Uiscrollview add gestures show and hide keyboard
- UI automation based on Selenium
- More than 10 million Android users installed a fraud app and doubled the number of blackmail attacks in the UK | global network security hotspot
- 2022-2028 global genome editing mutation detection kit industry survey and trend analysis report
- Visual AI, first!
- Industry ranks first in blackmail attacks, hacker organizations attack Afghanistan and India | global network security hotspot
- How to transfer files from the server connected to the fortress machine and how to access the server through the fortress machine
- Efficient Internet access and systematic learning
- 2022-2028 global tungsten copper alloy industry research and trend analysis report
- 2022-2028 global aircraft front wheel steering system industry research and trend analysis report
猜你喜欢

The cost of on-site development of software talent outsourcing is higher than that of software project outsourcing. Why

2022-2028 global medical modified polypropylene industry research and trend analysis report

Permission maintenance topic: domain controller permission maintenance

2022-2028 global aircraft audio control panel system industry research and trend analysis report
![[51nod] 2653 section XOR](/img/2d/cb4bf4e14939ce432cac6d35b6a41b.jpg)
[51nod] 2653 section XOR

2022-2028 global tungsten copper alloy industry research and trend analysis report

2022-2028 global anti counterfeiting label industry research and trend analysis report

2022-2028 Global Industry Survey and trend analysis report on portable pressure monitors for wards

2022-2028 global aircraft front wheel steering system industry research and trend analysis report

2022-2028 global genome editing mutation detection kit industry survey and trend analysis report
随机推荐
What is etcd and its application scenarios
2022-2028 global cancer biopsy instrument and kit industry research and trend analysis report
Optimization of Clickhouse ConnectionPool link pool
2022-2028 global genome editing mutation detection kit industry survey and trend analysis report
Buddha's foot before examination: the second play of leetcode
What does operation and maintenance audit fortress mean? How to select the operation and maintenance audit fortress machine?
SAP retail characteristic profile I
Deep and shallow copy
What about foreign trade companies? Is this another difficult year?
Gin framework: add Prometheus monitoring
How to install an application publisher
2022-2028 global pilot night vision goggle industry research and trend analysis report
AI intelligent analysis is innovated again. In the future, the technical reserve of the security industry will become the top priority
Is your posture correct—— A detailed discussion on horizontal sub database and sub table
How to enable IPv6 network access for personal broadband
The dealer management and control platform in the leather industry simplifies the purchase approval process and easily controls agents
JMeter script FAQs
How to strengthen prison security measures? Technologies you can't imagine
Compile blender source code
What is the case when easynvr non administrator logs in to view the empty video list?