Kafka 2.5.0 Admin api, what timestamp used in listOffset method?

Viewed 140

There is a method listOffset in KafkaAdmin API from 2.5.0 version. This method can return offset by timestamp.

/**
 * Used to retrieve the the earliest offset whose timestamp is greater than
 * or equal to the given timestamp in the corresponding partition
 * @param timestamp in milliseconds
 */
public static OffsetSpec forTimestamp(long timestamp) {
    return new TimestampSpec(timestamp);
}

And also this method return object ListOffsetsResultInfo which has the fields offset and timestamp. So my question is -> What timestamp in both cases API mentions? Does it timestamp of KafkaRecord if yes -> can it work with message.timestamp.type=CreateTime ? Or only with message.timestamp.type=LogAppendTime?

1 Answers

When records are sent to Kafka, producers can specify a timestamp or not depending on message.timestamp.type. If the producer did not specify a timestamp, Kafka will set it to its current time. So in the end, each Record has a single value for timestamp.

The timestamp argument of OffsetSpec.forTimestamp() is checked against the timestamp of the Kafka record by the broker.

It applies regardless if the Record's timestamp came from CreateTime (provided by producers) or LogAppendTime provided by the broker.

Related