Search code examples
apache-pulsar

how to rewind a subscription cursor to a specific time in Pulsar?


In the document: https://pulsar.apache.org/docs/en/concepts-clients/, it explains that you can start a consumer from earliest or latest position, or you can specify a message id. Can it support this requirement, that to specify a time point and start from there, for example, now I want to iterate the messages from yesterday 12:00 to yesterday 13:00?


Solution

  • Yes, you can rewind a subscription to a time offset. The time option of the pulsar-admin persistent reset-cursor command will do let you do this:

    # bin/pulsar-admin persistent reset-cursor
    
        reset-cursor      Reset position for subscription to position closest to timestamp or messageId
          Usage: reset-cursor [options] persistent://tenant/namespace/topic
            Options:
              --messageId, -m
                 messageId to reset back to (ledgerId:entryId)
            * -s, --subscription
                 Subscription to reset position on
              --time, -t
                 time in minutes to reset back to (or minutes, hours,days,weeks eg:
                 100m, 3h, 2d, 5w)
    

    You can also use the REST admin API.