jiazhai commented on a change in pull request #43: Support partition consumer receive async and fix batch logic URL: https://github.com/apache/pulsar-client-go/pull/43#discussion_r313375268
########## File path: pulsar/impl_partition_consumer.go ########## @@ -274,30 +320,45 @@ func (pc *partitionConsumer) ReceiveAsync(ctx context.Context, msgs chan<- Consu case tmpMsg, ok := <-pc.subQueue: if ok { msgs <- tmpMsg - id := &pb.MessageIdData{} - err := proto.Unmarshal(tmpMsg.ID().Serialize(), id) + + err := pc.messageProcessed(tmpMsg.ID(), receivedSinceFlow) if err != nil { - pc.log.WithError(err).Errorf("unserialize message id error:%s", err.Error()) return err } - if pc.unAckTracker != nil { - pc.unAckTracker.Add(id) - } - receivedSinceFlow++ - if receivedSinceFlow >= highwater { - if err := pc.internalFlow(receivedSinceFlow); err != nil { - pc.log.Errorf("Send Flow cmd error:%s", err.Error()) - return err - } - receivedSinceFlow = 0 - } continue } + break case <-ctx.Done(): return ctx.Err() } } +} + +func (pc *partitionConsumer) ReceiveAsyncWithCallback(ctx context.Context, callback func(msg Message, err error)) { + highwater := uint32(math.Max(float64(cap(pc.options.MessageChannel)/2), 1)) + + // request half the buffer's capacity + if err := pc.internalFlow(highwater); err != nil { Review comment: try to do it in background ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services