当前位置:网站首页>Alibaba cloud MSE supports go language traffic protection
Alibaba cloud MSE supports go language traffic protection
2022-07-28 16:56:00 【InfoQ】
summary
What is current limiting degradation

- Target: For what kind of traffic
- Strategy: Current limiting and degrading strategy
- FallbackAction: Triggered behavior

How to use MSE Current limiting the drop
Application access
- download**MSE Go SDK[1]**, Unzip to the of the project ./pkg-custom/github.com/aliyun/aliyun-mse-go-sdk-v1.0.7 Catalog .
- You can refer to SDK Of example Examples in the directory , To access .
- stay go.mod In file , Add the following dependency declaration :
require (
github.com/aliyun/aliyun-mse-go-sdk v1.0.7
)
replace github.com/aliyun/aliyun-mse-go-sdk => ./pkg-custom/github.com/aliyun/aliyun-mse-go-sdk
- During application startup , add to MSE SDK Initialization command :
import (
mse_sdk "github.com/aliyun/aliyun-mse-go-sdk"
)
// Add the following code to the initialization logic of the application .
// Sentinel core Initialization of is included here . If you have called Sentinel Initialization function for , Need to get rid of it. .
err := mse_sdk.InitMseDefault
if err != nil {
log.Fatalf("Failed to init MSE: %+v", err)
}
Application deployment


Resource definition
- Sentinel Define resources
import (
sentinel "github.com/alibaba/sentinel-golang/api"
)
// Entry The method is used for burying points
e, b := sentinel.Entry("your-resource-name", sentinel.WithTrafficType(base.Inbound))
if b != nil {
// Request is flow controlled , It can be downloaded from BlockError For current limiting details
} else {
// Requests can be made through , Write your business logic here
// Make sure that after the business logic is over Exit
e.Exit()
}
- dubbo-go How to define resources
import (
_ "github.com/alibaba/sentinel-golang/adapter/dubbo"
)
- Dubbo Application is in code through import In the form of package Dubbo adapter, Among them init() Function will automatically inject Correlation filter.Dubbo-Go Version needs to be ≥1.3.0.Sentinel Dubbo adapter It will automatically count all provider and consumer Call to .
- gRPC Application access
import (
sentinelPlugin "github.com/alibaba/sentinel-golang/adapter/grpc"
"google.golang.org/grpc"
)
s := grpc.NewServer(grpc.UnaryInterceptor(sentinelPlugin.NewUnaryServerInterceptor()))
- gRPC Apply to gRPC In the initialization code of Sentinel Provided interceptor,Sentinel in the light of Server and Client provide unary and streaming Two kinds of interceptor, The above code is in Server End as an example . The default flow limiting processing logic is to return Sentinel Of BlockError. You can also create interceptor Provide customized fallback Processing logic .
- Gin Web Application access
import (
sentinelPlugin "github.com/alibaba/sentinel-golang/adapter/gin"
"github.com/gin-gonic/gin"
)
r := gin.New()
r.Use(sentinelPlugin.SentinelMiddleware())
- Gin Web Apply to Gin In the initialization code of SentinelMiddleware.Sentinel For each API route Make statistics , The resource name is similar to GET:/foo/:id. The default flow limiting processing logic is to return 429 (Too Many Requests) Error code .
- Micro Application access
import (
sentinelPlugin "github.com/alibaba/sentinel-golang/adapter/micro"
"github.com/micro/go-micro/v2"
)
svc := micro.NewService(micro.WrapHandler(sentinelPlugin.NewHandlerWrapper()))
- stay Go-Micro In the initialization code of Sentinel Provided wrapper.Sentinel in the light of Go-Micro Server and Client provide wrapper. The above code is in Server End as an example . The embedded point will extract the service by default method As a resource name , The default flow control processing logic is to return Sentinel Of BlockError. You can also create wrapper Provide customized fallback Processing logic .
How to configure current limiting degradation rules
- Check the application



- Configure flow control rules


- Configure isolation rules

- Configure fusing rules

- Configure hotspot rules

- For the most frequently purchased goods in a period of time ID Limit , Prevent the situation of breaking down the cache and causing a large number of requests to the database .
- For users who visit frequently over a period of time ID Limit , Prevent malicious swiping .
MSE Microservice governance Planning
边栏推荐
- Interesting kotlin 0x08:what am I
- "Wei Lai Cup" 2022 Niuke summer multi school training camp 3 acfhj
- 日常开发方案设计指北
- Brother Ali teaches you how to correctly understand the problem of standard IO buffer
- ERROR: transport library not found: dt_ socket
- Efficiency comparison of three methods for obtaining timestamp
- 微软100题-天天做-第16题
- Some suggestions on Oracle SQL tuning
- Outline and principle of structured design -- modularization
- Hdu1847 problem solving ideas
猜你喜欢

IM即时通讯软件开发网络请求成功率的优化

在AD中添加差分对及连线

Re13: read the paper gender and racial stereotype detection in legal opinion word embeddings

Learn ABAQUS script programming script in an hour

Ansa secondary development - build ansa/meta secondary development environment on pycharm

Some suggestions on optimizing HyperMesh script performance

Fx3 development board and schematic diagram

Several methods of HyperMesh running script files

Do you really understand CMS garbage collector?

【指针内功修炼】字符指针 + 指针数组 + 数组指针 + 指针参数(一)
随机推荐
Using pyqt to design gui in ABAQUS
ERROR: transport library not found: dt_ socket
Ansa secondary development - build ansa/meta secondary development environment on pycharm
Multiple commands produce '... /xxx.app/assets.car' problem
日常开发方案设计指北
Learn to use MySQL explain to execute the plan, and SQL performance tuning is no longer difficult
PostgreSQL每周新闻—2022年7月20日
HTAP是有代价的
Oracle table partition
Re14:读论文 ILLSI Interpretable Low-Resource Legal Decision Making
Microsoft question 100 - do it every day - question 16
Debugging methods of USB products (fx3, ccg3pa)
Signal shielding and processing
QT designer for QT learning
CRC16 data verification supports modelbus and XMODEM verification modes (C language)
【JS】1394- ES2022 的 8 个实用的新功能
IM即时通讯软件开发网络请求成功率的优化
Jsonarray traversal
egg(十九):使用egg-redis性能优化,缓存数据提升响应效率
有趣的 Kotlin 0x07:Composition