Documentation ¶
Index ¶
- Constants
- Variables
- func NewHystrixLimitter(opts ...Option) middleware.Middleware
- type HystrixLimitter
- func (hl *HystrixLimitter) StreamClient(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, ...) (cs grpc.ClientStream, err error)
- func (hl *HystrixLimitter) StreamHandler(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo, ...) (err error)
- func (hl *HystrixLimitter) UnaryClient(ctx context.Context, method string, req, reply interface{}, ...) (err error)
- func (hl *HystrixLimitter) UnaryHandler(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, ...) (resp interface{}, err error)
- type HystrixLimitterType
- type Option
- func ErrorPercentThreshold(threshold int) Option
- func FilterOutFunc(filterOutFunc middleware.FilterFunc) Option
- func Limiter(limiter time.Duration) Option
- func LimiterBurst(limiterBurst int) Option
- func Logger(logger *zap.SugaredLogger) Option
- func MaxConcurrentRequests(max int) Option
- func RequestVolumeThreshold(threshold int) Option
- func ServiceName(serviceName string) Option
- func SleepWindow(sleep int) Option
- func StreamLimiter(limiter time.Duration) Option
- func StreamLimiterBurst(limiterBurst int) Option
- func Timeout(t int) Option
- func Type(typ HystrixLimitterType) Option
- type Options
Constants ¶
View Source
const ( // DefaultLimiter 默认3毫秒 DefaultLimiter = 3 * time.Millisecond // DefaultLimiterBurst 默认缓存token数 DefaultLimiterBurst = 100 // DefaultStreamLimiter 流调用 默认3毫米 DefaultStreamLimiter = 3 * time.Millisecond // DefaultStreamLimiterBurst 流调用 默认缓存token数 DefaultStreamLimiterBurst = 3 // HystrixLimitterTypeServer 服务端 HystrixLimitterTypeServer = "server" // HystrixLimitterTypeClient 客户端 HystrixLimitterTypeClient = "client" )
默认值
Variables ¶
View Source
var ( // ErrLimitExceed 超出限流器限制 ErrLimitExceed = errors.New("Rate limit exceed!") )
Functions ¶
func NewHystrixLimitter ¶
func NewHystrixLimitter(opts ...Option) middleware.Middleware
NewHystrixLimitter 创建熔断限流中间件
Types ¶
type HystrixLimitter ¶
type HystrixLimitter struct { Options *Options Limiter *rate.Limiter // 限流器 StreamLimiter *rate.Limiter // 流调用 限流器 }
HystrixLimitter 熔断限流中间件
func (*HystrixLimitter) StreamClient ¶
func (hl *HystrixLimitter) StreamClient(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, streamer grpc.Streamer, opts ...grpc.CallOption) (cs grpc.ClientStream, err error)
StreamClient 流式服客户中间件 grpc.StreamClientInterceptor
func (*HystrixLimitter) StreamHandler ¶
func (hl *HystrixLimitter) StreamHandler(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) (err error)
StreamHandler 流式中间件
func (*HystrixLimitter) UnaryClient ¶
func (hl *HystrixLimitter) UnaryClient(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) (err error)
UnaryClient 非流式客户端中间件 grpc.UnaryClientInterceptor
func (*HystrixLimitter) UnaryHandler ¶
func (hl *HystrixLimitter) UnaryHandler(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error)
UnaryHandler 非流式中间件
type Option ¶
type Option func(*Options)
Option 实例值设置
func ErrorPercentThreshold ¶
ErrorPercentThreshold 错误数量阀值,达到阀值,启动熔断
func FilterOutFunc ¶
func FilterOutFunc(filterOutFunc middleware.FilterFunc) Option
FilterOutFunc 设置中间件忽略函数列表
func MaxConcurrentRequests ¶
MaxConcurrentRequests 最大并发数,超过并发返回错误
func RequestVolumeThreshold ¶
RequestVolumeThreshold 请求数量的阀值,用这些数量的请求来计算阀值
func StreamLimiterBurst ¶
StreamLimiterBurst 限流缓存token数量
type Options ¶
type Options struct { Type HystrixLimitterType FilterOutFunc middleware.FilterFunc Logger *zap.SugaredLogger /* 限流 */ Limiter time.Duration // 限流器,多久生成一个token StreamLimiter time.Duration // 流调用 限流器,多久生成一个token LimiterBurst int // 缓存token数量 StreamLimiterBurst int // 流调用 缓存token数量 /* 熔断 */ ServiceName string // 服务名 Timeout int // 单位毫秒 MaxConcurrentRequests int // 最大并发数,超过并发返回错误 RequestVolumeThreshold int // 请求数量的阀值,用这些数量的请求来计算阀值 ErrorPercentThreshold int // 错误数量阀值,达到阀值,启动熔断 SleepWindow int // 熔断尝试恢复时间 }
Options 注册相关参数
Click to show internal directories.
Click to hide internal directories.