You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2022/08/18 09:59:24 UTC

[GitHub] [rocketmq-client-go] superhx opened a new issue, #896: Add user defined topic dimension consumer limiter

superhx opened a new issue, #896:
URL: https://github.com/apache/rocketmq-client-go/issues/896

   **FEATURE REQUEST**
   
   1. Please describe the feature you are requesting.
   Require user defined consume rate limiter which is topic dimension. The user could use self defined Limiter 'block' consume to controller topic consume rate based on TPS / Concurrent / Load or any other condition.
   
   2. Provide any additional detail on your proposed use case for this feature.
   ex. limit by TPS
   ```
   rocketmq.NewPushConsumer(
   	...
           consumer.WithLimiter(func(topic string) {
           	limiter.Wait()
   	}),
   )
   
   type Limiter struct {
   	maxCount int
   	count    int
   	ticker   *time.Ticker
   	ch       chan struct{}
   }
   
   func (l *Limiter) run() {
   	for {
   		// if counter has reached 0: block until next tick
   		if l.count <= 0 {
   			<-l.ticker.C
   			l.count = l.maxCount
   		}
   
   		// otherwise:
   		// decrement 'count' each time a message is sent on channel,
   		// reset 'count' to 'maxCount' when ticker says so
   		select {
   		case l.ch <- struct{}{}:
   			l.count--
   
   		case <-l.ticker.C:
   			l.count = l.maxCount
   		}
   	}
   }
   
   func (l *Limiter) Wait() {
   	<-l.ch
   }
   
   func NewLimiter(d time.Duration, count int) *Limiter {
   	l := &Limiter{
   		maxCount: count,
   		count:    count,
   		ticker:   time.NewTicker(d),
   		ch:       make(chan struct{}),
   	}
   	go l.run()
   
   	return l
   }
   
   ```
   
   3. Indicate the importance of this issue to you (blocker, must-have, should-have, nice-to-have). Are you currently using any workarounds to address this issue?
   should-have
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [rocketmq-client-go] ShannonDing closed issue #896: Add user defined topic dimension consumer limiter

Posted by GitBox <gi...@apache.org>.
ShannonDing closed issue #896: Add user defined topic dimension consumer limiter
URL: https://github.com/apache/rocketmq-client-go/issues/896


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org