public interface SinkTaskContext
SinkTask
s, allowing them to access utilities in the Kafka Connect runtime.Modifier and Type | Method and Description |
---|---|
Set<org.apache.kafka.common.TopicPartition> |
assignment()
Get the current set of assigned TopicPartitions for this task.
|
Map<String,String> |
configs()
Get the Task configuration.
|
default ErrantRecordReporter |
errantRecordReporter()
Get the reporter to which the sink task can report problematic or failed
records
passed to the SinkTask.put(java.util.Collection) method. |
void |
offset(Map<org.apache.kafka.common.TopicPartition,Long> offsets)
Reset the consumer offsets for the given topic partitions.
|
void |
offset(org.apache.kafka.common.TopicPartition tp,
long offset)
Reset the consumer offsets for the given topic partition.
|
void |
pause(org.apache.kafka.common.TopicPartition... partitions)
Pause consumption of messages from the specified TopicPartitions.
|
void |
requestCommit()
Request an offset commit.
|
void |
resume(org.apache.kafka.common.TopicPartition... partitions)
Resume consumption of messages from previously paused TopicPartitions.
|
void |
timeout(long timeoutMs)
Set the timeout in milliseconds.
|
Map<String,String> configs()
For example, this method can be used to obtain the latest configuration if an external secret has changed,
and the configuration is using variable references such as those compatible with
ConfigTransformer
.
void offset(Map<org.apache.kafka.common.TopicPartition,Long> offsets)
SinkTasks that do not manage their own offsets do not need to use this method.
offsets
- map of offsets for topic partitionsvoid offset(org.apache.kafka.common.TopicPartition tp, long offset)
SinkTasks that do not manage their own offsets do not need to use this method.
tp
- the topic partition to reset offset.offset
- the offset to reset to.void timeout(long timeoutMs)
timeoutMs
- the backoff timeout in milliseconds.Set<org.apache.kafka.common.TopicPartition> assignment()
void pause(org.apache.kafka.common.TopicPartition... partitions)
partitions
- the partitions which should be pausedvoid resume(org.apache.kafka.common.TopicPartition... partitions)
partitions
- the partitions to resumevoid requestCommit()
It is only a hint to the runtime and no timing guarantee should be assumed.
default ErrantRecordReporter errantRecordReporter()
records
passed to the SinkTask.put(java.util.Collection)
method. When reporting a failed record,
the sink task will receive a Future
that the task can optionally use to wait until
the failed record and exception have been written to Kafka. Note that the result of
this method may be null if this connector has not been configured to use a reporter.
This method was added in Apache Kafka 2.6. Sink tasks that use this method but want to
maintain backward compatibility so they can also be deployed to older Connect runtimes
should guard the call to this method with a try-catch block, since calling this method will result in a
NoSuchMethodError
or NoClassDefFoundError
when the sink connector is deployed to
Connect runtimes older than Kafka 2.6. For example:
ErrantRecordReporter reporter; try { reporter = context.errantRecordReporter(); } catch (NoSuchMethodError | NoClassDefFoundError e) { reporter = null; }