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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to