blob: 70524cc4bc7206659be5f18da57f62d9a9f7b9f7 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (version 1.7.0_80) on Thu Aug 04 13:19:27 BST 2016 -->
<title>StreamPartitioner (kafka 0.10.0.1 API)</title>
<meta name="date" content="2016-08-04">
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
</head>
<body>
<script type="text/javascript"><!--
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="StreamPartitioner (kafka 0.10.0.1 API)";
}
//-->
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="topNav"><a name="navbar_top">
<!-- -->
</a><a href="#skip-navbar_top" title="Skip navigation links"></a><a name="navbar_top_firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">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">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../../../org/apache/kafka/streams/processor/StateStoreSupplier.html" title="interface in org.apache.kafka.streams.processor"><span class="strong">Prev Class</span></a></li>
<li><a href="../../../../../org/apache/kafka/streams/processor/TaskId.html" title="class in org.apache.kafka.streams.processor"><span class="strong">Next Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../../../index.html?org/apache/kafka/streams/processor/StreamPartitioner.html" target="_top">Frames</a></li>
<li><a href="StreamPartitioner.html" target="_top">No Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_top">
<li><a href="../../../../../allclasses-noframe.html">All Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_top");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<div>
<ul class="subNavList">
<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="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Constr&nbsp;|&nbsp;</li>
<li><a href="#method_detail">Method</a></li>
</ul>
</div>
<a name="skip-navbar_top">
<!-- -->
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
<!-- ======== START OF CLASS DATA ======== -->
<div class="header">
<div class="subTitle">org.apache.kafka.streams.processor</div>
<h2 title="Interface StreamPartitioner" class="title">Interface StreamPartitioner&lt;K,V&gt;</h2>
</div>
<div class="contentContainer">
<div class="description">
<ul class="blockList">
<li class="blockList">
<dl><dt><span class="strong">Type Parameters:</span></dt><dd><code>K</code> - the type of keys</dd><dd><code>V</code> - the type of values</dd></dl>
<hr>
<br>
<pre>public interface <span class="strong">StreamPartitioner&lt;K,V&gt;</span></pre>
<div class="block">Determine how records are distributed among the partitions in a Kafka topic. If not specified, the underlying producer's
<code>DefaultPartitioner</code> will be used to determine the partition.
<p>
Kafka topics are divided into one or more <i>partitions</i>. Since each partition must fit on the servers that host it, so
using multiple partitions allows the topic to scale beyond a size that will fit on a single machine. Partitions also enable you
to use multiple instances of your topology to process in parallel all of the records on the topology's source topics.
<p>
When a topology is instantiated, each of its sources are assigned a subset of that topic's partitions. That means that only
those processors in that topology instance will consume the records from those partitions. In many cases, Kafka Streams will
automatically manage these instances, and adjust when new topology instances are added or removed.
<p>
Some topologies, though, need more control over which records appear in each partition. For example, some topologies that have
stateful processors may want all records within a range of keys to always be delivered to and handled by the same topology instance.
An upstream topology producing records to that topic can use a custom <i>stream partitioner</i> to precisely and consistently
determine to which partition each record should be written.
<p>
To do this, create a <code>StreamPartitioner</code> implementation, and when you build your topology specify that custom partitioner
when <a href="../../../../../org/apache/kafka/streams/processor/TopologyBuilder.html#addSink(java.lang.String,%20java.lang.String,%20org.apache.kafka.common.serialization.Serializer,%20org.apache.kafka.common.serialization.Serializer,%20org.apache.kafka.streams.processor.StreamPartitioner,%20java.lang.String...)"><code>adding a sink</code></a>
for that topic.
<p>
All StreamPartitioner implementations should be stateless and a pure function so they can be shared across topic and sink nodes.</div>
<dl><dt><span class="strong">See Also:</span></dt><dd><a href="../../../../../org/apache/kafka/streams/processor/TopologyBuilder.html#addSink(java.lang.String,%20java.lang.String,%20org.apache.kafka.common.serialization.Serializer,%20org.apache.kafka.common.serialization.Serializer,%20org.apache.kafka.streams.processor.StreamPartitioner,%20java.lang.String...)"><code>TopologyBuilder.addSink(String, String, org.apache.kafka.common.serialization.Serializer,
org.apache.kafka.common.serialization.Serializer, StreamPartitioner, String...)</code></a>,
<a href="../../../../../org/apache/kafka/streams/processor/TopologyBuilder.html#addSink(java.lang.String,%20java.lang.String,%20org.apache.kafka.streams.processor.StreamPartitioner,%20java.lang.String...)"><code>TopologyBuilder.addSink(String, String, StreamPartitioner, String...)</code></a></dd></dl>
</li>
</ul>
</div>
<div class="summary">
<ul class="blockList">
<li class="blockList">
<!-- ========== METHOD SUMMARY =========== -->
<ul class="blockList">
<li class="blockList"><a name="method_summary">
<!-- -->
</a>
<h3>Method Summary</h3>
<table class="overviewSummary" border="0" cellpadding="3" cellspacing="0" summary="Method Summary table, listing methods, and an explanation">
<caption><span>Methods</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colLast" scope="col">Method and Description</th>
</tr>
<tr class="altColor">
<td class="colFirst"><code><a href="http://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html?is-external=true" title="class or interface in java.lang">Integer</a></code></td>
<td class="colLast"><code><strong><a href="../../../../../org/apache/kafka/streams/processor/StreamPartitioner.html#partition(K,%20V,%20int)">partition</a></strong>(<a href="../../../../../org/apache/kafka/streams/processor/StreamPartitioner.html" title="type parameter in StreamPartitioner">K</a>&nbsp;key,
<a href="../../../../../org/apache/kafka/streams/processor/StreamPartitioner.html" title="type parameter in StreamPartitioner">V</a>&nbsp;value,
int&nbsp;numPartitions)</code>
<div class="block">Determine the partition number for a record with the given key and value and the current number of partitions.</div>
</td>
</tr>
</table>
</li>
</ul>
</li>
</ul>
</div>
<div class="details">
<ul class="blockList">
<li class="blockList">
<!-- ============ METHOD DETAIL ========== -->
<ul class="blockList">
<li class="blockList"><a name="method_detail">
<!-- -->
</a>
<h3>Method Detail</h3>
<a name="partition(java.lang.Object,java.lang.Object,int)">
<!-- -->
</a><a name="partition(K, V, int)">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>partition</h4>
<pre><a href="http://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html?is-external=true" title="class or interface in java.lang">Integer</a>&nbsp;partition(<a href="../../../../../org/apache/kafka/streams/processor/StreamPartitioner.html" title="type parameter in StreamPartitioner">K</a>&nbsp;key,
<a href="../../../../../org/apache/kafka/streams/processor/StreamPartitioner.html" title="type parameter in StreamPartitioner">V</a>&nbsp;value,
int&nbsp;numPartitions)</pre>
<div class="block">Determine the partition number for a record with the given key and value and the current number of partitions.</div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>key</code> - the key of the record</dd><dd><code>value</code> - the value of the record</dd><dd><code>numPartitions</code> - the total number of partitions</dd>
<dt><span class="strong">Returns:</span></dt><dd>an integer between 0 and <code>numPartitions-1</code>, or <code>null</code> if the default partitioning logic should be used</dd></dl>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
<!-- ========= END OF CLASS DATA ========= -->
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a name="navbar_bottom">
<!-- -->
</a><a href="#skip-navbar_bottom" title="Skip navigation links"></a><a name="navbar_bottom_firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">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">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../../../org/apache/kafka/streams/processor/StateStoreSupplier.html" title="interface in org.apache.kafka.streams.processor"><span class="strong">Prev Class</span></a></li>
<li><a href="../../../../../org/apache/kafka/streams/processor/TaskId.html" title="class in org.apache.kafka.streams.processor"><span class="strong">Next Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../../../index.html?org/apache/kafka/streams/processor/StreamPartitioner.html" target="_top">Frames</a></li>
<li><a href="StreamPartitioner.html" target="_top">No Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_bottom">
<li><a href="../../../../../allclasses-noframe.html">All Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_bottom");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<div>
<ul class="subNavList">
<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="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Constr&nbsp;|&nbsp;</li>
<li><a href="#method_detail">Method</a></li>
</ul>
</div>
<a name="skip-navbar_bottom">
<!-- -->
</a></div>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
</body>
</html>