当前位置:网站首页>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 |
边栏推荐
- 2022-2028 global portable two-way radio equipment industry research and trend analysis report
- MySQL Cases-MySQL 8.0.26 bug ERROR 1064 (42000) at line1: You have an error
- [tcapulusdb knowledge base] manually view the online operation of tcapulusdb
- PHP verify mailbox format
- Using the database middleware MYCAT to realize read-write separation (dual master and dual slave)
- How to transfer files from the server connected to the fortress machine and how to access the server through the fortress machine
- 2022-2028 global marine wet exhaust hose industry research and trend analysis report
- C common regular expression collation
- Afnetworking usage and cache processing
- Coding helps Jiangsu high-speed information to achieve organizational agility and R & D agility, leading the new infrastructure of Intelligent Transportation
猜你喜欢

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

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

2022-2028 global genome editing mutation detection kit industry survey 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 Industry Survey and trend analysis report on portable pressure monitors for wards

2022-2028 global pilot night vision goggle industry research and trend analysis report

2022-2028 global marine wet exhaust hose industry research and trend analysis report
Cloudpods golang practice

2022-2028 global cell-based seafood industry research and trend analysis report

2022-2028 global tungsten copper alloy industry research and trend analysis report
随机推荐
How to choose the appropriate configuration server?
How to understand EDI requirements of trading partners
How to recover the garbled words in the software?
Gin framework: add API logging Middleware
Create and mount large files
How to build a speech synthesis server
What is the 4A server fortress machine? What is the price of the fortress machine
How to change the cloud desktop domain server password if you forget it?
How to access easynvr management platform through web pages without data?
Pan micro reached cooperation with Tencent to help enterprises connect with banking services and support enterprise digital upgrading
Where is the domain name filed? What materials are required for domain name filing?
Tidb HTAP Getting Started Guide - how to add a copy of tiflash
Grpc: adjust data transfer size limit
The most comprehensive arrangement of safe operation solutions from various manufacturers
How to quickly handle third-party login and easy to expand?
How to handle the occasional address request failure in easygbs live video playback?
Kibana report generation failed due to custom template
C common regular expression collation
[Tencent cloud double 12.12] from 56 yuan! New users of Tencent cloud buy for the first time, which is more cost-effective!
2022-2028 global marine clutch industry research and trend analysis report