blob: 120f69c6af89719559fa75ce3ab8106ccb715f77 [file] [log] [blame]
<!DOCTYPE HTML>
<html lang="en">
<head>
<!-- Generated by javadoc (17) -->
<title>SinkTaskContext (kafka 3.6.1 API)</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="description" content="declaration: package: org.apache.kafka.connect.sink, interface: SinkTaskContext">
<meta name="generator" content="javadoc/ClassWriterImpl">
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
<link rel="stylesheet" type="text/css" href="../../../../../script-dir/jquery-ui.min.css" title="Style">
<link rel="stylesheet" type="text/css" href="../../../../../jquery-ui.overrides.css" title="Style">
<script type="text/javascript" src="../../../../../script.js"></script>
<script type="text/javascript" src="../../../../../script-dir/jquery-3.5.1.min.js"></script>
<script type="text/javascript" src="../../../../../script-dir/jquery-ui.min.js"></script>
</head>
<body class="class-declaration-page">
<script type="text/javascript">var evenRowColor = "even-row-color";
var oddRowColor = "odd-row-color";
var tableTab = "table-tab";
var activeTableTab = "active-table-tab";
var pathtoroot = "../../../../../";
loadScripts(document, 'script');</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<div class="flex-box">
<header role="banner" class="flex-header">
<nav role="navigation">
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="top-nav" id="navbar-top">
<div class="skip-nav"><a href="#skip-navbar-top" title="Skip navigation links">Skip navigation links</a></div>
<ul id="navbar-top-firstrow" class="nav-list" title="Navigation">
<li><a href="../../../../../index.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="nav-bar-cell1-rev">Class</li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../../index-all.html">Index</a></li>
<li><a href="../../../../../help-doc.html#class">Help</a></li>
</ul>
</div>
<div class="sub-nav">
<div>
<ul class="sub-nav-list">
<li>Summary:&nbsp;</li>
<li>Nested&nbsp;|&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Constr&nbsp;|&nbsp;</li>
<li><a href="#method-summary">Method</a></li>
</ul>
<ul class="sub-nav-list">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Constr&nbsp;|&nbsp;</li>
<li><a href="#method-detail">Method</a></li>
</ul>
</div>
<div class="nav-list-search"><label for="search-input">SEARCH:</label>
<input type="text" id="search-input" value="search" disabled="disabled">
<input type="reset" id="reset-button" value="reset" disabled="disabled">
</div>
</div>
<!-- ========= END OF TOP NAVBAR ========= -->
<span class="skip-nav" id="skip-navbar-top"></span></nav>
</header>
<div class="flex-content">
<main role="main">
<!-- ======== START OF CLASS DATA ======== -->
<div class="header">
<div class="sub-title"><span class="package-label-in-type">Package</span>&nbsp;<a href="package-summary.html">org.apache.kafka.connect.sink</a></div>
<h1 title="Interface SinkTaskContext" class="title">Interface SinkTaskContext</h1>
</div>
<section class="class-description" id="class-description">
<hr>
<div class="type-signature"><span class="modifiers">public interface </span><span class="element-name type-name-label">SinkTaskContext</span></div>
<div class="block">Context passed to <a href="SinkTask.html" title="class in org.apache.kafka.connect.sink"><code>SinkTask</code></a>s, allowing them to access utilities in the Kafka Connect runtime.</div>
</section>
<section class="summary">
<ul class="summary-list">
<!-- ========== METHOD SUMMARY =========== -->
<li>
<section class="method-summary" id="method-summary">
<h2>Method Summary</h2>
<div id="method-summary-table">
<div class="table-tabs" role="tablist" aria-orientation="horizontal"><button id="method-summary-table-tab0" role="tab" aria-selected="true" aria-controls="method-summary-table.tabpanel" tabindex="0" onkeydown="switchTab(event)" onclick="show('method-summary-table', 'method-summary-table', 3)" class="active-table-tab">All Methods</button><button id="method-summary-table-tab2" role="tab" aria-selected="false" aria-controls="method-summary-table.tabpanel" tabindex="-1" onkeydown="switchTab(event)" onclick="show('method-summary-table', 'method-summary-table-tab2', 3)" class="table-tab">Instance Methods</button><button id="method-summary-table-tab3" role="tab" aria-selected="false" aria-controls="method-summary-table.tabpanel" tabindex="-1" onkeydown="switchTab(event)" onclick="show('method-summary-table', 'method-summary-table-tab3', 3)" class="table-tab">Abstract Methods</button><button id="method-summary-table-tab5" role="tab" aria-selected="false" aria-controls="method-summary-table.tabpanel" tabindex="-1" onkeydown="switchTab(event)" onclick="show('method-summary-table', 'method-summary-table-tab5', 3)" class="table-tab">Default Methods</button></div>
<div id="method-summary-table.tabpanel" role="tabpanel">
<div class="summary-table three-column-summary" aria-labelledby="method-summary-table-tab0">
<div class="table-header col-first">Modifier and Type</div>
<div class="table-header col-second">Method</div>
<div class="table-header col-last">Description</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab3"><code><a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/Set.html" title="class or interface in java.util" class="external-link">Set</a>&lt;<a href="../../common/TopicPartition.html" title="class in org.apache.kafka.common">TopicPartition</a>&gt;</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab3"><code><a href="#assignment()" class="member-name-link">assignment</a>()</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab3">
<div class="block">Get the current set of assigned TopicPartitions for this task.</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab3"><code><a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/Map.html" title="class or interface in java.util" class="external-link">Map</a>&lt;<a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/String.html" title="class or interface in java.lang" class="external-link">String</a>,<wbr><a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/String.html" title="class or interface in java.lang" class="external-link">String</a>&gt;</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab3"><code><a href="#configs()" class="member-name-link">configs</a>()</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab3">
<div class="block">Get the Task configuration.</div>
</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab5"><code>default <a href="ErrantRecordReporter.html" title="interface in org.apache.kafka.connect.sink">ErrantRecordReporter</a></code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab5"><code><a href="#errantRecordReporter()" class="member-name-link">errantRecordReporter</a>()</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab5">
<div class="block">Get the reporter to which the sink task can report problematic or failed <a href="SinkRecord.html" title="class in org.apache.kafka.connect.sink"><code>records</code></a>
passed to the <a href="SinkTask.html#put(java.util.Collection)"><code>SinkTask.put(java.util.Collection)</code></a> method.</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab3"><code>void</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab3"><code><a href="#offset(java.util.Map)" class="member-name-link">offset</a><wbr>(<a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/Map.html" title="class or interface in java.util" class="external-link">Map</a>&lt;<a href="../../common/TopicPartition.html" title="class in org.apache.kafka.common">TopicPartition</a>,<wbr><a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Long.html" title="class or interface in java.lang" class="external-link">Long</a>&gt;&nbsp;offsets)</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab3">
<div class="block">Reset the consumer offsets for the given topic partitions.</div>
</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab3"><code>void</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab3"><code><a href="#offset(org.apache.kafka.common.TopicPartition,long)" class="member-name-link">offset</a><wbr>(<a href="../../common/TopicPartition.html" title="class in org.apache.kafka.common">TopicPartition</a>&nbsp;tp,
long&nbsp;offset)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab3">
<div class="block">Reset the consumer offsets for the given topic partition.</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab3"><code>void</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab3"><code><a href="#pause(org.apache.kafka.common.TopicPartition...)" class="member-name-link">pause</a><wbr>(<a href="../../common/TopicPartition.html" title="class in org.apache.kafka.common">TopicPartition</a>...&nbsp;partitions)</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab3">
<div class="block">Pause consumption of messages from the specified TopicPartitions.</div>
</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab3"><code>void</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab3"><code><a href="#requestCommit()" class="member-name-link">requestCommit</a>()</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab3">
<div class="block">Request an offset commit.</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab3"><code>void</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab3"><code><a href="#resume(org.apache.kafka.common.TopicPartition...)" class="member-name-link">resume</a><wbr>(<a href="../../common/TopicPartition.html" title="class in org.apache.kafka.common">TopicPartition</a>...&nbsp;partitions)</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab3">
<div class="block">Resume consumption of messages from previously paused TopicPartitions.</div>
</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab3"><code>void</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab3"><code><a href="#timeout(long)" class="member-name-link">timeout</a><wbr>(long&nbsp;timeoutMs)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab3">
<div class="block">Set the timeout in milliseconds.</div>
</div>
</div>
</div>
</div>
</section>
</li>
</ul>
</section>
<section class="details">
<ul class="details-list">
<!-- ============ METHOD DETAIL ========== -->
<li>
<section class="method-details" id="method-detail">
<h2>Method Details</h2>
<ul class="member-list">
<li>
<section class="detail" id="configs()">
<h3>configs</h3>
<div class="member-signature"><span class="return-type"><a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/Map.html" title="class or interface in java.util" class="external-link">Map</a>&lt;<a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/String.html" title="class or interface in java.lang" class="external-link">String</a>,<wbr><a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/String.html" title="class or interface in java.lang" class="external-link">String</a>&gt;</span>&nbsp;<span class="element-name">configs</span>()</div>
<div class="block">Get the Task configuration. This is the latest configuration and may differ from that passed on startup.
<p>
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
<a href="../../common/config/ConfigTransformer.html" title="class in org.apache.kafka.common.config"><code>ConfigTransformer</code></a>.</div>
</section>
</li>
<li>
<section class="detail" id="offset(java.util.Map)">
<h3>offset</h3>
<div class="member-signature"><span class="return-type">void</span>&nbsp;<span class="element-name">offset</span><wbr><span class="parameters">(<a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/Map.html" title="class or interface in java.util" class="external-link">Map</a>&lt;<a href="../../common/TopicPartition.html" title="class in org.apache.kafka.common">TopicPartition</a>,<wbr><a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Long.html" title="class or interface in java.lang" class="external-link">Long</a>&gt;&nbsp;offsets)</span></div>
<div class="block">Reset the consumer offsets for the given topic partitions. SinkTasks should use this if they manage offsets
in the sink data store rather than using Kafka consumer offsets. For example, an HDFS connector might record
offsets in HDFS to provide exactly once delivery. When the SinkTask is started or a rebalance occurs, the task
would reload offsets from HDFS and use this method to reset the consumer to those offsets.
<p>
SinkTasks that do not manage their own offsets do not need to use this method.</div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>offsets</code> - map of offsets for topic partitions</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="offset(org.apache.kafka.common.TopicPartition,long)">
<h3>offset</h3>
<div class="member-signature"><span class="return-type">void</span>&nbsp;<span class="element-name">offset</span><wbr><span class="parameters">(<a href="../../common/TopicPartition.html" title="class in org.apache.kafka.common">TopicPartition</a>&nbsp;tp,
long&nbsp;offset)</span></div>
<div class="block">Reset the consumer offsets for the given topic partition. SinkTasks should use this if they manage offsets
in the sink data store rather than using Kafka consumer offsets. For example, an HDFS connector might record
offsets in HDFS to provide exactly once delivery. When the topic partition is recovered the task
would reload offsets from HDFS and use this method to reset the consumer to the offset.
<p>
SinkTasks that do not manage their own offsets do not need to use this method.</div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>tp</code> - the topic partition to reset offset.</dd>
<dd><code>offset</code> - the offset to reset to.</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="timeout(long)">
<h3>timeout</h3>
<div class="member-signature"><span class="return-type">void</span>&nbsp;<span class="element-name">timeout</span><wbr><span class="parameters">(long&nbsp;timeoutMs)</span></div>
<div class="block">Set the timeout in milliseconds. SinkTasks should use this to indicate that they need to retry certain
operations after the timeout. SinkTasks may have certain operations on external systems that may need
to be retried in case of failures. For example, appending a record to an HDFS file may fail due to temporary
network issues. SinkTasks can use this method to set how long to wait before retrying.</div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>timeoutMs</code> - the backoff timeout in milliseconds.</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="assignment()">
<h3>assignment</h3>
<div class="member-signature"><span class="return-type"><a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/Set.html" title="class or interface in java.util" class="external-link">Set</a>&lt;<a href="../../common/TopicPartition.html" title="class in org.apache.kafka.common">TopicPartition</a>&gt;</span>&nbsp;<span class="element-name">assignment</span>()</div>
<div class="block">Get the current set of assigned TopicPartitions for this task.</div>
<dl class="notes">
<dt>Returns:</dt>
<dd>the set of currently assigned TopicPartitions</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="pause(org.apache.kafka.common.TopicPartition...)">
<h3>pause</h3>
<div class="member-signature"><span class="return-type">void</span>&nbsp;<span class="element-name">pause</span><wbr><span class="parameters">(<a href="../../common/TopicPartition.html" title="class in org.apache.kafka.common">TopicPartition</a>...&nbsp;partitions)</span></div>
<div class="block">Pause consumption of messages from the specified TopicPartitions.</div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>partitions</code> - the partitions which should be paused</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="resume(org.apache.kafka.common.TopicPartition...)">
<h3>resume</h3>
<div class="member-signature"><span class="return-type">void</span>&nbsp;<span class="element-name">resume</span><wbr><span class="parameters">(<a href="../../common/TopicPartition.html" title="class in org.apache.kafka.common">TopicPartition</a>...&nbsp;partitions)</span></div>
<div class="block">Resume consumption of messages from previously paused TopicPartitions.</div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>partitions</code> - the partitions to resume</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="requestCommit()">
<h3>requestCommit</h3>
<div class="member-signature"><span class="return-type">void</span>&nbsp;<span class="element-name">requestCommit</span>()</div>
<div class="block">Request an offset commit. Sink tasks can use this to minimize the potential for redelivery
by requesting an offset commit as soon as they flush data to the destination system.
<p>
It is only a hint to the runtime and no timing guarantee should be assumed.</div>
</section>
</li>
<li>
<section class="detail" id="errantRecordReporter()">
<h3>errantRecordReporter</h3>
<div class="member-signature"><span class="modifiers">default</span>&nbsp;<span class="return-type"><a href="ErrantRecordReporter.html" title="interface in org.apache.kafka.connect.sink">ErrantRecordReporter</a></span>&nbsp;<span class="element-name">errantRecordReporter</span>()</div>
<div class="block">Get the reporter to which the sink task can report problematic or failed <a href="SinkRecord.html" title="class in org.apache.kafka.connect.sink"><code>records</code></a>
passed to the <a href="SinkTask.html#put(java.util.Collection)"><code>SinkTask.put(java.util.Collection)</code></a> method. When reporting a failed record,
the sink task will receive a <a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/concurrent/Future.html" title="class or interface in java.util.concurrent" class="external-link"><code>Future</code></a> 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.
<p>
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
<a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/NoSuchMethodError.html" title="class or interface in java.lang" class="external-link"><code>NoSuchMethodError</code></a> or <a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/NoClassDefFoundError.html" title="class or interface in java.lang" class="external-link"><code>NoClassDefFoundError</code></a> when the sink connector is deployed to
Connect runtimes older than Kafka 2.6. For example:
<pre>
ErrantRecordReporter reporter;
try {
reporter = context.errantRecordReporter();
} catch (NoSuchMethodError | NoClassDefFoundError e) {
reporter = null;
}
</pre></div>
<dl class="notes">
<dt>Returns:</dt>
<dd>the reporter; null if no error reporter has been configured for the connector</dd>
<dt>Since:</dt>
<dd>2.6</dd>
</dl>
</section>
</li>
</ul>
</section>
</li>
</ul>
</section>
<!-- ========= END OF CLASS DATA ========= -->
</main>
</div>
</div>
</body>
</html>