public interface Fetcher
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the fetcher.
|
<T> void |
run(org.apache.flink.streaming.api.functions.source.SourceFunction.SourceContext<T> sourceContext,
org.apache.flink.streaming.util.serialization.DeserializationSchema<T> valueDeserializer,
long[] lastOffsets)
Starts fetch data from Kafka and emitting it into the stream.
|
void |
seek(org.apache.kafka.common.TopicPartition topicPartition,
long offsetToRead)
Set the next offset to read from for the given partition.
|
void |
setPartitionsToRead(List<org.apache.kafka.common.TopicPartition> partitions)
Set which partitions the fetcher should pull from.
|
void setPartitionsToRead(List<org.apache.kafka.common.TopicPartition> partitions)
partitions - The list of partitions for a topic that the fetcher will pull from.void close()
throws IOException
run(SourceFunction.SourceContext, DeserializationSchema, long[]) method and eventually
close underlying connections and release all resources.IOException<T> void run(org.apache.flink.streaming.api.functions.source.SourceFunction.SourceContext<T> sourceContext,
org.apache.flink.streaming.util.serialization.DeserializationSchema<T> valueDeserializer,
long[] lastOffsets)
throws Exception
To provide exactly once guarantees, the fetcher needs emit a record and update the update of the last consumed offset in one atomic operation:
while (running) {
T next = ...
long offset = ...
int partition = ...
synchronized (sourceContext.getCheckpointLock()) {
sourceContext.collect(next);
lastOffsets[partition] = offset;
}
}
T - The type of elements produced by the fetcher and emitted to the source context.sourceContext - The source context to emit elements to.valueDeserializer - The deserializer to decode the raw values with.lastOffsets - The array into which to store the offsets foe which elements are emitted.Exceptionvoid seek(org.apache.kafka.common.TopicPartition topicPartition,
long offsetToRead)
topicPartition - The partition for which to seek the offset.offsetToRead - To offset to seek to.Copyright © 2014–2015 The Apache Software Foundation. All rights reserved.