wangjia007bond 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_r364552036
 
 

 ##########
 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:
   sure, removed.

----------------------------------------------------------------
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

Reply via email to