Class FailOnInvalidTimestamp
- java.lang.Object
-
- org.apache.kafka.streams.processor.FailOnInvalidTimestamp
-
- All Implemented Interfaces:
TimestampExtractor
public class FailOnInvalidTimestamp extends Object
Retrieves embedded metadata timestamps from Kafka messages. If a record has a negative (invalid) timestamp value, this extractor raises an exception.Embedded metadata timestamp was introduced in "KIP-32: Add timestamps to Kafka message" for the new 0.10+ Kafka message format.
Here, "embedded metadata" refers to the fact that compatible Kafka producer clients automatically and transparently embed such timestamps into message metadata they send to Kafka, which can then be retrieved via this timestamp extractor.
If the embedded metadata timestamp represents CreateTime (cf. Kafka broker setting
message.timestamp.type
and Kafka topic settinglog.message.timestamp.type
), this extractor effectively provides event-time semantics. If LogAppendTime is used as broker/topic setting to define the embedded metadata timestamps, using this extractor effectively provides ingestion-time semantics.If you need processing-time semantics, use
WallclockTimestampExtractor
.
-
-
Constructor Summary
Constructors Constructor Description FailOnInvalidTimestamp()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
extract(ConsumerRecord<Object,Object> record, long partitionTime)
Extracts the embedded metadata timestamp from the givenConsumerRecord
.long
onInvalidTimestamp(ConsumerRecord<Object,Object> record, long recordTimestamp, long partitionTime)
Raises an exception on every call.
-
-
-
Method Detail
-
onInvalidTimestamp
public long onInvalidTimestamp(ConsumerRecord<Object,Object> record, long recordTimestamp, long partitionTime) throws StreamsException
Raises an exception on every call.- Parameters:
record
- a data recordrecordTimestamp
- the timestamp extractor from the recordpartitionTime
- the highest extracted valid timestamp of the current record's partition˙ (could be -1 if unknown)- Returns:
- nothing; always raises an exception
- Throws:
StreamsException
- on every invocation
-
extract
public long extract(ConsumerRecord<Object,Object> record, long partitionTime)
Extracts the embedded metadata timestamp from the givenConsumerRecord
.- Specified by:
extract
in interfaceTimestampExtractor
- Parameters:
record
- a data recordpartitionTime
- the highest extracted valid timestamp of the current record's partition˙ (could be -1 if unknown)- Returns:
- the embedded metadata timestamp of the given
ConsumerRecord
-
-