当前位置:网站首页>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 |
边栏推荐
- 5g Gigabit router dual band industrial grade
- Grpc: based on cloud native environment, distinguish configuration files
- Iranian gas station paralyzed by cyber attack, babuk blackmail software source code leaked | global network security hotspot
- 2022-2028 global third-party data platform industry research and trend analysis report
- LeetCode 205. Isomorphic Strings
- Permission maintenance topic: domain controller permission maintenance
- Easycvr cannot be played when cascaded to the superior platform. Troubleshooting
- How to choose the appropriate configuration server?
- Gartner released the magic quadrant of enterprise low code platform in 2021. Low code integrated platform becomes a trend!
- 2022-2028 global anti counterfeiting label industry research and trend analysis report
猜你喜欢

What is etcd and its application scenarios
Cloudpods golang practice

2022-2028 global third-party data platform industry research and trend analysis report

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

IOS development - multithreading - thread safety (3)

2022-2028 global aircraft audio control panel system industry research and trend analysis report

2022-2028 global marine wet exhaust hose industry research and trend analysis report
![[51nod] 2653 section XOR](/img/2d/cb4bf4e14939ce432cac6d35b6a41b.jpg)
[51nod] 2653 section XOR

2022-2028 global high tibial osteotomy plate industry research and trend analysis report
随机推荐
How to recover the garbled words in the software?
Gin framework: add API logging Middleware
Buddha's foot before examination: the third bullet of leetcode
Create and mount large files
How does [lightweight application server] build a cross-border e-commerce management environment?
Using the database middleware MYCAT to realize read-write separation (dual master and dual slave)
What is the performance improvement after upgrading the 4800h to the 5800h?
Cloudpods golang practice
LeetCode 1323. Maximum number of 6 and 9
More than 10 million Android users installed a fraud app and doubled the number of blackmail attacks in the UK | global network security hotspot
How to enable IPv6 network access for personal broadband
Easycvr cannot be played when cascaded to the superior platform. Troubleshooting
How to change the cloud desktop domain server password if you forget it?
[Tencent cloud double 12.12] from 56 yuan! New users of Tencent cloud buy for the first time, which is more cost-effective!
Iranian gas station paralyzed by cyber attack, babuk blackmail software source code leaked | global network security hotspot
[tcapulusdb knowledge base] manually view the online operation of tcapulusdb
Precautions for VPN client on Tencent cloud
How much does it cost to rent a cloud game server? Which cloud game server is more reliable?
Afnetworking server client
Is AI face detection and face recognition a concept? What's the difference?