forked from go-chassis/go-chassis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qps_consumer_flow_control_handler.go
executable file
·39 lines (32 loc) · 1.14 KB
/
qps_consumer_flow_control_handler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package handler
import (
"github.com/go-chassis/go-chassis/control"
"github.com/go-chassis/go-chassis/core/common"
"github.com/go-chassis/go-chassis/core/invocation"
"github.com/go-chassis/go-chassis/core/qpslimiter"
)
// ConsumerRateLimiterHandler consumer rate limiter handler
type ConsumerRateLimiterHandler struct{}
// Handle is handles the consumer rate limiter APIs
func (rl *ConsumerRateLimiterHandler) Handle(chain *Chain, i *invocation.Invocation, cb invocation.ResponseCallBack) {
rlc := control.DefaultPanel.GetRateLimiting(*i, common.Consumer)
if !rlc.Enabled {
chain.Next(i, cb)
return
}
//get operation meta info ms.schema, ms.schema.operation, ms
rl.GetOrCreate(rlc)
chain.Next(i, cb)
}
func newConsumerRateLimiterHandler() Handler {
return &ConsumerRateLimiterHandler{}
}
// Name returns consumerratelimiter string
func (rl *ConsumerRateLimiterHandler) Name() string {
return "consumerratelimiter"
}
// GetOrCreate is for getting or creating qps limiter meta data
func (rl *ConsumerRateLimiterHandler) GetOrCreate(rlc control.RateLimitingConfig) {
qpslimiter.GetQPSTrafficLimiter().ProcessQPSTokenReq(rlc.Key, rlc.Rate)
return
}