Kafka: Seek to a timestamp to replay from a point in time

Offsets are opaque; timestamps are how humans ask for "everything since 9am".

Code
var query = consumer.assignment().stream()
        .collect(toMap(tp -> tp, tp -> startInstant.toEpochMilli()));

consumer.offsetsForTimes(query).forEach((tp, offsetAndTs) -> {
    if (offsetAndTs != null) consumer.seek(tp, offsetAndTs.offset());
});
Output
orders-0 -> offset 182034 (2026-08-10T09:00:00Z)
orders-1 -> offset 97112

Null means no record on that partition is that new.
Advertisement

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-08-11