Skip to content

Commit

Permalink
feat: mq push consume supports ratelimit (#948)
Browse files Browse the repository at this point in the history
Co-authored-by: hulongjun <[email protected]>
  • Loading branch information
hjxp and hulongjun authored Aug 2, 2023
1 parent 5393a4d commit 95b46f4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
6 changes: 6 additions & 0 deletions pkg/client/rocketmq/push_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,17 @@ func (conf *PushConsumerConfig) Build() *PushConsumer {

xlog.Jupiter().Debug("rocketmq's config: ", xlog.String("name", name), xlog.Any("conf", conf))

var bucket *ratelimit.Bucket
if conf.Rate > 0 && conf.Capacity > 0 {
bucket = ratelimit.NewBucketWithRate(conf.Rate, conf.Capacity)
}

cc := &PushConsumer{
name: name,
PushConsumerConfig: *conf,
subscribers: make(map[string]func(context.Context, ...*primitive.MessageExt) (consumer.ConsumeResult, error)),
interceptors: []primitive.Interceptor{},
bucket: bucket,
}
cc.interceptors = append(cc.interceptors,
consumerMetricInterceptor(),
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ require (
go.opentelemetry.io/otel/trace v1.16.0 // indirect
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/automaxprocs v1.5.2 // indirect
go.uber.org/automaxprocs v1.5.3 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/arch v0.3.0 // indirect
Expand Down
1 change: 1 addition & 0 deletions test/e2e/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
go.uber.org/automaxprocs v1.5.2 h1:2LxUOGiR3O6tw8ui5sZa2LAaHnsviZdVOUZw4fvbnME=
go.uber.org/automaxprocs v1.5.2/go.mod h1:eRbA25aqJrxAbsLO0xy5jVwPt7FQnRgjW+efnwa1WM0=
go.uber.org/automaxprocs v1.5.3/go.mod h1:eRbA25aqJrxAbsLO0xy5jVwPt7FQnRgjW+efnwa1WM0=
go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
Expand Down

0 comments on commit 95b46f4

Please sign in to comment.