public interface SinkTaskContext
Modifier and Type | Method and Description |
---|---|
Set<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<TopicPartition,Long> offsets)
Reset the consumer offsets for the given topic partitions.
|
void |
offset(TopicPartition tp,
long offset)
Reset the consumer offsets for the given topic partition.
|
void |
pause(TopicPartition... partitions)
Pause consumption of messages from the specified TopicPartitions.
|
void |
requestCommit()
Request an offset commit.
|
void |
resume(TopicPartition... partitions)
Resume consumption of messages from previously paused TopicPartitions.
|
void |
timeout(long timeoutMs)
Set the timeout in milliseconds.
|
Map<String,String> configs()
ConfigTransformer
.void offset(Map<TopicPartition,Long> offsets)
offsets
- map of offsets for topic partitionsvoid offset(TopicPartition tp, long offset)
tp
- the topic partition to reset offset.offset
- the offset to reset to.void timeout(long timeoutMs)
timeoutMs
- the backoff timeout in milliseconds.Set<TopicPartition> assignment()
void pause(TopicPartition... partitions)
partitions
- the partitions which should be pausedvoid resume(TopicPartition... partitions)
partitions
- the partitions to resumevoid requestCommit()
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
NoSuchMethodException
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; }