blob: 94699d89e65e7a033dac61d052f491640d3734f2 [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 (1.8.0_77) on Mon Oct 24 00:05:44 UTC 2016 -->
<title>KafkaConsumer (Edgent v1.0.0)</title>
<meta name="date" content="2016-10-24">
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../../../script.js"></script>
</head>
<body>
<script type="text/javascript"><!--
try {
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="KafkaConsumer (Edgent v1.0.0)";
}
}
catch(err) {
}
//-->
var methods = {"i0":10,"i1":10};
var tabs = {65535:["t0","All Methods"],2:["t2","Instance Methods"],8:["t4","Concrete Methods"]};
var altColor = "altColor";
var rowColor = "rowColor";
var tableTab = "tableTab";
var activeTableTab = "activeTableTab";
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="topNav"><a name="navbar.top">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div>
<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="class-use/KafkaConsumer.html">Use</a></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>Prev&nbsp;Class</li>
<li><a href="../../../../../org/apache/edgent/connectors/kafka/KafkaConsumer.ByteConsumerRecord.html" title="interface in org.apache.edgent.connectors.kafka"><span class="typeNameLink">Next&nbsp;Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../../../index.html?org/apache/edgent/connectors/kafka/KafkaConsumer.html" target="_top">Frames</a></li>
<li><a href="KafkaConsumer.html" target="_top">No&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_top">
<li><a href="../../../../../allclasses-noframe.html">All&nbsp;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><a href="#nested.class.summary">Nested</a>&nbsp;|&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor.summary">Constr</a>&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><a href="#constructor.detail">Constr</a>&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.edgent.connectors.kafka</div>
<h2 title="Class KafkaConsumer" class="title">Class KafkaConsumer</h2>
</div>
<div class="contentContainer">
<ul class="inheritance">
<li>java.lang.Object</li>
<li>
<ul class="inheritance">
<li>org.apache.edgent.connectors.kafka.KafkaConsumer</li>
</ul>
</li>
</ul>
<div class="description">
<ul class="blockList">
<li class="blockList">
<hr>
<br>
<pre>public class <span class="typeNameLabel">KafkaConsumer</span>
extends java.lang.Object</pre>
<div class="block"><code>KafkaConsumer</code> is a connector for creating a stream of tuples
by subscribing to Apache Kafka messaging system topics.
<p>
The connector uses and includes components from the Kafka 0.8.2.2 release.
It has been successfully tested against a kafka_2.11-0.9.0.0 server as well.
For more information about Kafka see
<a href="http://kafka.apache.org">http://kafka.apache.org</a>
<p>
Sample use:
<pre><code>
String zookeeperConnect = "localhost:2181";
String groupId = "myGroupId";
String topic = "mySensorReadingsTopic";
Map&lt;String,Object&gt; config = new HashMap&lt;&gt;();
config.put("zookeeper.connect", zookeeperConnect);
config.put("groupId", groupId);
Topology t = ...
KafkaConsumer kafka = new KafkaConsumer(t, () -&gt; config);
// subscribe to a topic where sensor readings are published as JSON,
// creating a stream of JSON tuples
TStream&lt;String&gt; sensorReadingsJson =
kafka.subscribe(rec -&gt; rec.value(), topic);
// print the received messages
sensorReadingsJson.print();
</code></pre></div>
</li>
</ul>
</div>
<div class="summary">
<ul class="blockList">
<li class="blockList">
<!-- ======== NESTED CLASS SUMMARY ======== -->
<ul class="blockList">
<li class="blockList"><a name="nested.class.summary">
<!-- -->
</a>
<h3>Nested Class Summary</h3>
<table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Nested Class Summary table, listing nested classes, and an explanation">
<caption><span>Nested Classes</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colLast" scope="col">Class and Description</th>
</tr>
<tr class="altColor">
<td class="colFirst"><code>static interface&nbsp;</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../org/apache/edgent/connectors/kafka/KafkaConsumer.ByteConsumerRecord.html" title="interface in org.apache.edgent.connectors.kafka">KafkaConsumer.ByteConsumerRecord</a></span></code>
<div class="block">A Kafka record with byte[] typed key and value members</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>static interface&nbsp;</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../org/apache/edgent/connectors/kafka/KafkaConsumer.ConsumerRecord.html" title="interface in org.apache.edgent.connectors.kafka">KafkaConsumer.ConsumerRecord</a>&lt;<a href="../../../../../org/apache/edgent/connectors/kafka/KafkaConsumer.ConsumerRecord.html" title="type parameter in KafkaConsumer.ConsumerRecord">K</a>,<a href="../../../../../org/apache/edgent/connectors/kafka/KafkaConsumer.ConsumerRecord.html" title="type parameter in KafkaConsumer.ConsumerRecord">V</a>&gt;</span></code>
<div class="block">A received Kafka record</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>static interface&nbsp;</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../org/apache/edgent/connectors/kafka/KafkaConsumer.StringConsumerRecord.html" title="interface in org.apache.edgent.connectors.kafka">KafkaConsumer.StringConsumerRecord</a></span></code>
<div class="block">A Kafka record with String typed key and value members</div>
</td>
</tr>
</table>
</li>
</ul>
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
<ul class="blockList">
<li class="blockList"><a name="constructor.summary">
<!-- -->
</a>
<h3>Constructor Summary</h3>
<table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Constructor Summary table, listing constructors, and an explanation">
<caption><span>Constructors</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colOne" scope="col">Constructor and Description</th>
</tr>
<tr class="altColor">
<td class="colOne"><code><span class="memberNameLink"><a href="../../../../../org/apache/edgent/connectors/kafka/KafkaConsumer.html#KafkaConsumer-org.apache.edgent.topology.Topology-org.apache.edgent.function.Supplier-">KafkaConsumer</a></span>(<a href="../../../../../org/apache/edgent/topology/Topology.html" title="interface in org.apache.edgent.topology">Topology</a>&nbsp;t,
<a href="../../../../../org/apache/edgent/function/Supplier.html" title="interface in org.apache.edgent.function">Supplier</a>&lt;java.util.Map&lt;java.lang.String,java.lang.Object&gt;&gt;&nbsp;config)</code>
<div class="block">Create a consumer connector for subscribing to Kafka topics
and creating tuples from the received messages.</div>
</td>
</tr>
</table>
</li>
</ul>
<!-- ========== METHOD SUMMARY =========== -->
<ul class="blockList">
<li class="blockList"><a name="method.summary">
<!-- -->
</a>
<h3>Method Summary</h3>
<table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Method Summary table, listing methods, and an explanation">
<caption><span id="t0" class="activeTableTab"><span>All Methods</span><span class="tabEnd">&nbsp;</span></span><span id="t2" class="tableTab"><span><a href="javascript:show(2);">Instance Methods</a></span><span class="tabEnd">&nbsp;</span></span><span id="t4" class="tableTab"><span><a href="javascript:show(8);">Concrete Methods</a></span><span class="tabEnd">&nbsp;</span></span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colLast" scope="col">Method and Description</th>
</tr>
<tr id="i0" class="altColor">
<td class="colFirst"><code>&lt;T&gt;&nbsp;<a href="../../../../../org/apache/edgent/topology/TStream.html" title="interface in org.apache.edgent.topology">TStream</a>&lt;T&gt;</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../org/apache/edgent/connectors/kafka/KafkaConsumer.html#subscribe-org.apache.edgent.function.Function-java.lang.String...-">subscribe</a></span>(<a href="../../../../../org/apache/edgent/function/Function.html" title="interface in org.apache.edgent.function">Function</a>&lt;<a href="../../../../../org/apache/edgent/connectors/kafka/KafkaConsumer.StringConsumerRecord.html" title="interface in org.apache.edgent.connectors.kafka">KafkaConsumer.StringConsumerRecord</a>,T&gt;&nbsp;toTupleFn,
java.lang.String...&nbsp;topics)</code>
<div class="block">Subscribe to the specified topics and yield a stream of tuples
from the published Kafka records.</div>
</td>
</tr>
<tr id="i1" class="rowColor">
<td class="colFirst"><code>&lt;T&gt;&nbsp;<a href="../../../../../org/apache/edgent/topology/TStream.html" title="interface in org.apache.edgent.topology">TStream</a>&lt;T&gt;</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../org/apache/edgent/connectors/kafka/KafkaConsumer.html#subscribeBytes-org.apache.edgent.function.Function-java.lang.String...-">subscribeBytes</a></span>(<a href="../../../../../org/apache/edgent/function/Function.html" title="interface in org.apache.edgent.function">Function</a>&lt;<a href="../../../../../org/apache/edgent/connectors/kafka/KafkaConsumer.ByteConsumerRecord.html" title="interface in org.apache.edgent.connectors.kafka">KafkaConsumer.ByteConsumerRecord</a>,T&gt;&nbsp;toTupleFn,
java.lang.String...&nbsp;topics)</code>
<div class="block">Subscribe to the specified topics and yield a stream of tuples
from the published Kafka records.</div>
</td>
</tr>
</table>
<ul class="blockList">
<li class="blockList"><a name="methods.inherited.from.class.java.lang.Object">
<!-- -->
</a>
<h3>Methods inherited from class&nbsp;java.lang.Object</h3>
<code>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</code></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<div class="details">
<ul class="blockList">
<li class="blockList">
<!-- ========= CONSTRUCTOR DETAIL ======== -->
<ul class="blockList">
<li class="blockList"><a name="constructor.detail">
<!-- -->
</a>
<h3>Constructor Detail</h3>
<a name="KafkaConsumer-org.apache.edgent.topology.Topology-org.apache.edgent.function.Supplier-">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>KafkaConsumer</h4>
<pre>public&nbsp;KafkaConsumer(<a href="../../../../../org/apache/edgent/topology/Topology.html" title="interface in org.apache.edgent.topology">Topology</a>&nbsp;t,
<a href="../../../../../org/apache/edgent/function/Supplier.html" title="interface in org.apache.edgent.function">Supplier</a>&lt;java.util.Map&lt;java.lang.String,java.lang.Object&gt;&gt;&nbsp;config)</pre>
<div class="block">Create a consumer connector for subscribing to Kafka topics
and creating tuples from the received messages.
<p>
See the Apache Kafka documentation for "Old Consumer Configs"
configuration properties at <a href="http://kafka.apache.org">http://kafka.apache.org</a>.
Configuration property values are strings.
<p>
The Kafka "Old Consumer" configs are used. Minimal configuration
typically includes:
<ul>
<li><code>zookeeper.connect</code></li>
<li><code>group.id</code></li>
</ul></div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>t</code> - Topology to add to</dd>
<dd><code>config</code> - KafkaConsumer configuration information.</dd>
</dl>
</li>
</ul>
</li>
</ul>
<!-- ============ METHOD DETAIL ========== -->
<ul class="blockList">
<li class="blockList"><a name="method.detail">
<!-- -->
</a>
<h3>Method Detail</h3>
<a name="subscribeBytes-org.apache.edgent.function.Function-java.lang.String...-">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>subscribeBytes</h4>
<pre>public&nbsp;&lt;T&gt;&nbsp;<a href="../../../../../org/apache/edgent/topology/TStream.html" title="interface in org.apache.edgent.topology">TStream</a>&lt;T&gt;&nbsp;subscribeBytes(<a href="../../../../../org/apache/edgent/function/Function.html" title="interface in org.apache.edgent.function">Function</a>&lt;<a href="../../../../../org/apache/edgent/connectors/kafka/KafkaConsumer.ByteConsumerRecord.html" title="interface in org.apache.edgent.connectors.kafka">KafkaConsumer.ByteConsumerRecord</a>,T&gt;&nbsp;toTupleFn,
java.lang.String...&nbsp;topics)</pre>
<div class="block">Subscribe to the specified topics and yield a stream of tuples
from the published Kafka records.
<p>
Kafka's consumer group management functionality is used to automatically
allocate, and dynamically reallocate, the topic's partitions to this connector.
<p>
In line with Kafka's evolving new KafkaConsumer interface, subscribing
to a topic advertises a single thread to the server for partition allocation.
<p>
Currently, subscribe*() can only be called once for a KafkaConsumer
instance. This restriction will be removed once we migrate to Kafka 0.9.0.0.</div>
<dl>
<dt><span class="paramLabel">Type Parameters:</span></dt>
<dd><code>T</code> - tuple type</dd>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>toTupleFn</code> - A function that yields a tuple from a <code>ByteConsumerRecord</code></dd>
<dd><code>topics</code> - the topics to subscribe to.</dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>stream of tuples</dd>
<dt><span class="throwsLabel">Throws:</span></dt>
<dd><code>java.lang.IllegalArgumentException</code> - for a duplicate or conflicting subscription</dd>
</dl>
</li>
</ul>
<a name="subscribe-org.apache.edgent.function.Function-java.lang.String...-">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>subscribe</h4>
<pre>public&nbsp;&lt;T&gt;&nbsp;<a href="../../../../../org/apache/edgent/topology/TStream.html" title="interface in org.apache.edgent.topology">TStream</a>&lt;T&gt;&nbsp;subscribe(<a href="../../../../../org/apache/edgent/function/Function.html" title="interface in org.apache.edgent.function">Function</a>&lt;<a href="../../../../../org/apache/edgent/connectors/kafka/KafkaConsumer.StringConsumerRecord.html" title="interface in org.apache.edgent.connectors.kafka">KafkaConsumer.StringConsumerRecord</a>,T&gt;&nbsp;toTupleFn,
java.lang.String...&nbsp;topics)</pre>
<div class="block">Subscribe to the specified topics and yield a stream of tuples
from the published Kafka records.
<p>
Kafka's consumer group management functionality is used to automatically
allocate, and dynamically reallocate, the topic's partitions to this connector.
<p>
In line with Kafka's evolving new KafkaConsumer interface, subscribing
to a topic advertises a single thread to the server for partition allocation.
<p>
Currently, subscribe*() can only be called once for a KafkaConsumer
instance. This restriction will be removed once we migrate to Kafka 0.9.0.0.</div>
<dl>
<dt><span class="paramLabel">Type Parameters:</span></dt>
<dd><code>T</code> - tuple type</dd>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>toTupleFn</code> - A function that yields a tuple from a <code>StringConsumerRecord</code></dd>
<dd><code>topics</code> - the topics to subscribe to.</dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>stream of tuples</dd>
<dt><span class="throwsLabel">Throws:</span></dt>
<dd><code>java.lang.IllegalArgumentException</code> - for a duplicate or conflicting subscription</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>
<div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div>
<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="class-use/KafkaConsumer.html">Use</a></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 class="aboutLanguage"><a href="http://edgent.incubator.apache.org">Apache Edgent (incubating)</a></div>
</div>
<div class="subNav">
<ul class="navList">
<li>Prev&nbsp;Class</li>
<li><a href="../../../../../org/apache/edgent/connectors/kafka/KafkaConsumer.ByteConsumerRecord.html" title="interface in org.apache.edgent.connectors.kafka"><span class="typeNameLink">Next&nbsp;Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../../../index.html?org/apache/edgent/connectors/kafka/KafkaConsumer.html" target="_top">Frames</a></li>
<li><a href="KafkaConsumer.html" target="_top">No&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_bottom">
<li><a href="../../../../../allclasses-noframe.html">All&nbsp;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><a href="#nested.class.summary">Nested</a>&nbsp;|&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor.summary">Constr</a>&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><a href="#constructor.detail">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method.detail">Method</a></li>
</ul>
</div>
<a name="skip.navbar.bottom">
<!-- -->
</a></div>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
<p class="legalCopy"><small>Copyright &#169; 2016 The Apache Software Foundation. All Rights Reserved - 59dfbdf-20161024-0005</small></p>
</body>
</html>