Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions consumer/push_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type pushConsumer struct {
done chan struct{}
closeOnce sync.Once
crCh map[string]chan struct{}
crChLock sync.Mutex
}

func NewPushConsumer(opts ...Option) (*pushConsumer, error) {
Expand Down Expand Up @@ -297,9 +298,12 @@ func (pc *pushConsumer) Subscribe(topic string, selector MessageSelector,
if pc.option.Namespace != "" {
topic = pc.option.Namespace + "%" + topic
}
pc.crChLock.Lock()
if _, ok := pc.crCh[topic]; !ok {
pc.crCh[topic] = make(chan struct{}, pc.defaultConsumer.option.ConsumeGoroutineNums)
}
pc.crChLock.Unlock()

data := buildSubscriptionData(topic, selector)
pc.subscriptionDataTable.Store(topic, data)
pc.subscribedTopic[topic] = ""
Expand Down Expand Up @@ -1086,9 +1090,12 @@ func (pc *pushConsumer) consumeMessageConcurrently(pq *processQueue, mq *primiti

limiter := pc.option.Limiter
limiterOn := limiter != nil
pc.crChLock.Lock()
if _, ok := pc.crCh[mq.Topic]; !ok {
pc.crCh[mq.Topic] = make(chan struct{}, pc.defaultConsumer.option.ConsumeGoroutineNums)
}
crCh := pc.crCh[mq.Topic]
pc.crChLock.Unlock()

for count := 0; count < len(msgs); count++ {
var subMsgs []*primitive.MessageExt
Expand All @@ -1104,7 +1111,7 @@ func (pc *pushConsumer) consumeMessageConcurrently(pq *processQueue, mq *primiti
if limiterOn {
limiter(utils.WithoutNamespace(mq.Topic))
}
pc.crCh[mq.Topic] <- struct{}{}
crCh <- struct{}{}

go primitive.WithRecover(func() {
defer func() {
Expand All @@ -1114,7 +1121,7 @@ func (pc *pushConsumer) consumeMessageConcurrently(pq *processQueue, mq *primiti
rlog.LogKeyConsumerGroup: pc.consumerGroup,
})
}
<-pc.crCh[mq.Topic]
<-crCh
}()
RETRY:
if pq.IsDroppd() {
Expand Down