@InterfaceStability.Unstable public abstract class SinkTask extends Object implements Task
put(java.util.Collection<org.apache.kafka.connect.sink.SinkRecord>)
interface, SinkTasks must also implement flush(java.util.Map<org.apache.kafka.common.TopicPartition, org.apache.kafka.clients.consumer.OffsetAndMetadata>)
to support offset commits.Modifier and Type | Field and Description |
---|---|
protected SinkTaskContext |
context |
static String |
TOPICS_CONFIG
The configuration key that provides the list of topics that are inputs for this
SinkTask.
|
Constructor and Description |
---|
SinkTask() |
Modifier and Type | Method and Description |
---|---|
abstract void |
flush(Map<org.apache.kafka.common.TopicPartition,org.apache.kafka.clients.consumer.OffsetAndMetadata> offsets)
Flush all records that have been
put(java.util.Collection<org.apache.kafka.connect.sink.SinkRecord>) for the specified topic-partitions. |
void |
initialize(SinkTaskContext context) |
void |
onPartitionsAssigned(Collection<org.apache.kafka.common.TopicPartition> partitions)
The SinkTask use this method to create writers for newly assigned partitions in case of partition
re-assignment.
|
void |
onPartitionsRevoked(Collection<org.apache.kafka.common.TopicPartition> partitions)
The SinkTask use this method to close writers and commit offsets for partitions that are
longer assigned to the SinkTask.
|
abstract void |
put(Collection<SinkRecord> records)
Put the records in the sink.
|
abstract void |
start(Map<String,String> props)
Start the Task.
|
abstract void |
stop()
Perform any cleanup to stop this task.
|
public static final String TOPICS_CONFIG
The configuration key that provides the list of topics that are inputs for this SinkTask.
protected SinkTaskContext context
public void initialize(SinkTaskContext context)
public abstract void start(Map<String,String> props)
public abstract void put(Collection<SinkRecord> records)
RetriableException
to
indicate that the framework should attempt to retry the same call again. Other exceptions will cause the task to
be stopped immediately. SinkTaskContext.timeout(long)
can be used to set the maximum time before the
batch will be retried.records
- the set of records to sendpublic abstract void flush(Map<org.apache.kafka.common.TopicPartition,org.apache.kafka.clients.consumer.OffsetAndMetadata> offsets)
put(java.util.Collection<org.apache.kafka.connect.sink.SinkRecord>)
for the specified topic-partitions. The
offsets are provided for convenience, but could also be determined by tracking all offsets
included in the SinkRecords passed to put(java.util.Collection<org.apache.kafka.connect.sink.SinkRecord>)
.offsets
- mapping of TopicPartition to committed offsetpublic void onPartitionsAssigned(Collection<org.apache.kafka.common.TopicPartition> partitions)
partitions
- The list of partitions that are now assigned to the task (may include
partitions previously assigned to the task)public void onPartitionsRevoked(Collection<org.apache.kafka.common.TopicPartition> partitions)
partitions
- The list of partitions that were assigned to the consumer on the last
rebalancepublic abstract void stop()
put(Collection)
has returned) and a final flush(Map)
and offset
commit has completed. Implementations of this method should only need to perform final cleanup operations, such
as closing network connections to the sink system.