Interface OffsetsInitializer
- All Superinterfaces:
Serializable
- All Known Implementing Classes:
NoStoppingOffsetsInitializer
An interface for users to specify the starting / stopping offset of a
KafkaPartitionSplit.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceAn interface that provides necessary information to theOffsetsInitializerto get the initial offsets of the Kafka partitions. -
Method Summary
Modifier and TypeMethodDescriptionstatic OffsetsInitializerGet anOffsetsInitializerwhich initializes the offsets to the committed offsets.static OffsetsInitializercommittedOffsets(org.apache.kafka.clients.consumer.OffsetResetStrategy offsetResetStrategy) Get anOffsetsInitializerwhich initializes the offsets to the committed offsets.static OffsetsInitializerearliest()Get anOffsetsInitializerwhich initializes the offsets to the earliest available offsets of each partition.org.apache.kafka.clients.consumer.OffsetResetStrategyGet the auto offset reset strategy in case the initialized offsets falls out of the range.getPartitionOffsets(Collection<org.apache.kafka.common.TopicPartition> partitions, OffsetsInitializer.PartitionOffsetsRetriever partitionOffsetsRetriever) Get the initial offsets for the given Kafka partitions.static OffsetsInitializerlatest()Get anOffsetsInitializerwhich initializes the offsets to the latest offsets of each partition.static OffsetsInitializerGet anOffsetsInitializerwhich initializes the offsets to the specified offsets.static OffsetsInitializeroffsets(Map<org.apache.kafka.common.TopicPartition, Long> offsets, org.apache.kafka.clients.consumer.OffsetResetStrategy offsetResetStrategy) Get anOffsetsInitializerwhich initializes the offsets to the specified offsets.static OffsetsInitializertimestamp(long timestamp) Get anOffsetsInitializerwhich initializes the offsets in each partition so that the initialized offset is the offset of the first record whose record timestamp is greater than or equals the given timestamp (milliseconds).
-
Method Details
-
getPartitionOffsets
Map<org.apache.kafka.common.TopicPartition,Long> getPartitionOffsets(Collection<org.apache.kafka.common.TopicPartition> partitions, OffsetsInitializer.PartitionOffsetsRetriever partitionOffsetsRetriever) Get the initial offsets for the given Kafka partitions. These offsets will be used as either starting offsets or stopping offsets of the Kafka partitions.If the implementation returns a starting offset which causes
OffsetsOutOfRangeExceptionfrom Kafka. TheOffsetResetStrategyprovided by thegetAutoOffsetResetStrategy()will be used to reset the offset.- Parameters:
partitions- the Kafka partitions to get the starting offsets.partitionOffsetsRetriever- a helper to retrieve information of the Kafka partitions.- Returns:
- A mapping from Kafka partition to their offsets to start consuming from.
-
getAutoOffsetResetStrategy
org.apache.kafka.clients.consumer.OffsetResetStrategy getAutoOffsetResetStrategy()Get the auto offset reset strategy in case the initialized offsets falls out of the range.The OffsetStrategy is only used when the offset initializer is used to initialize the starting offsets and the starting offsets is out of range.
- Returns:
- An
OffsetResetStrategyto use if the initialized offsets are out of the range.
-
committedOffsets
Get anOffsetsInitializerwhich initializes the offsets to the committed offsets. An exception will be thrown at runtime if there is no committed offsets.- Returns:
- an offset initializer which initialize the offsets to the committed offsets.
-
committedOffsets
static OffsetsInitializer committedOffsets(org.apache.kafka.clients.consumer.OffsetResetStrategy offsetResetStrategy) Get anOffsetsInitializerwhich initializes the offsets to the committed offsets. Use the givenOffsetResetStrategyto initialize the offsets if the committed offsets does not exist.- Parameters:
offsetResetStrategy- the offset reset strategy to use when the committed offsets do not exist.- Returns:
- an
OffsetsInitializerwhich initializes the offsets to the committed offsets.
-
timestamp
Get anOffsetsInitializerwhich initializes the offsets in each partition so that the initialized offset is the offset of the first record whose record timestamp is greater than or equals the given timestamp (milliseconds).- Parameters:
timestamp- the timestamp (milliseconds) to start the consumption.- Returns:
- an
OffsetsInitializerwhich initializes the offsets based on the given timestamp. - See Also:
-
earliest
Get anOffsetsInitializerwhich initializes the offsets to the earliest available offsets of each partition.- Returns:
- an
OffsetsInitializerwhich initializes the offsets to the earliest available offsets.
-
latest
Get anOffsetsInitializerwhich initializes the offsets to the latest offsets of each partition.- Returns:
- an
OffsetsInitializerwhich initializes the offsets to the latest offsets.
-
offsets
Get anOffsetsInitializerwhich initializes the offsets to the specified offsets.- Parameters:
offsets- the specified offsets for each partition.- Returns:
- an
OffsetsInitializerwhich initializes the offsets to the specified offsets.
-
offsets
static OffsetsInitializer offsets(Map<org.apache.kafka.common.TopicPartition, Long> offsets, org.apache.kafka.clients.consumer.OffsetResetStrategy offsetResetStrategy) Get anOffsetsInitializerwhich initializes the offsets to the specified offsets. Use the givenOffsetResetStrategyto initialize the offsets in case the specified offset is out of range.- Parameters:
offsets- the specified offsets for each partition.offsetResetStrategy- theOffsetResetStrategyto use when the specified offset is out of range.- Returns:
- an
OffsetsInitializerwhich initializes the offsets to the specified offsets.
-