cckellogg commented on a change in pull request #168:
[Issue-148][pulsar-client-go] add seek by messageID
URL: https://github.com/apache/pulsar-client-go/pull/168#discussion_r364342728
##########
File path: pulsar/consumer_partition.go
##########
@@ -256,6 +256,50 @@ func (pc *partitionConsumer) Close() {
<-req.doneCh
}
+func (pc *partitionConsumer) Seek(msgID *messageID) error {
+ req := &seekRequest{
+ doneCh: make(chan struct{}),
+ msgID: msgID,
+ }
+ pc.eventsCh <- req
+
+ // wait for the request to complete
+ <-req.doneCh
+ return req.err
+}
+
+func (pc *partitionConsumer) internalSeek(seek *seekRequest) {
+ defer close(seek.doneCh)
+
+ if pc.state == consumerClosing || pc.state == consumerClosed {
+ err := fmt.Errorf("the consumer %s was already closed when
seeking the subscription %s of the topic "+
+ "%s to the message %s", pc.name,
pc.options.subscription, pc.topic, seek.msgID.Serialize())
+ pc.log.WithError(err).Error("Consumer was already closed")
+ seek.err = err
+ }
+
+ id := &pb.MessageIdData{}
+ err := proto.Unmarshal(seek.msgID.Serialize(), id)
+ if err != nil {
+ pc.log.WithError(err).Errorf("deserialize message id error:
%s", err.Error())
+ seek.err = err
+ }
+
+ requestID := pc.client.rpcClient.NewRequestID()
+ cmdSeek := &pb.CommandSeek{
+ ConsumerId: proto.Uint64(pc.consumerID),
+ RequestId: proto.Uint64(requestID),
+ MessageId: id,
+ }
+ _, err = pc.client.rpcClient.RequestOnCnx(pc.conn, requestID,
pb.BaseCommand_SEEK, cmdSeek)
+ if err != nil {
+ pc.log.WithError(err).Error("Failed to reset to message id")
+ seek.err = err
+ }
+
+ pc.conn.DeleteConsumeHandler(pc.consumerID)
Review comment:
Why are we deleting the consumer handler here? That does not seem correct.
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services