UNPKG

node-rdkafka-imhoff

Version:
3,927 lines (1,298 loc) 89.2 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Class: KafkaConsumer</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify.css"> <link type="text/css" rel="stylesheet" href="toolkit/css/toolkit/bnet-responsive.min.css"> <link type="text/css" rel="stylesheet" href="styles/main.css"> </head> <body> <!-- HEADER --> <div class="navbar-static"> <header class="navbar header"> <div class="grid-container"> <div class="grid-25"> <a class="brand mark" href="index.html"> Class: KafkaConsumer <span class="tag">3.6.11</span> </a> </div> <div class="grid-75"> <ul class="nav navbar-nav navbar-right"> <li class="dropdown"><a class="dropdown-toggle" role="button" data-toggle="dropdown" href="#" onclick="return false;">Classes</a><ul class="dropdown-menu" role="menu"><li><a href="AdminClient.html">AdminClient</a></li><li><a href="Client.html">Client</a></li><li><a href="HighLevelProducer.html">HighLevelProducer</a></li><li><a href="KafkaConsumer.html">KafkaConsumer</a></li><li><a href="KafkaConsumerStream.html">KafkaConsumerStream</a></li><li><a href="LibrdKafkaError.html">LibrdKafkaError</a></li><li><a href="Producer.html">Producer</a></li><li><a href="ProducerStream.html">ProducerStream</a></li></ul></li><li class="dropdown"><a class="dropdown-toggle" role="button" data-toggle="dropdown" href="#" onclick="return false;">Events</a><ul class="dropdown-menu" role="menu"><li><a href="Client.html#event:disconnected">disconnected</a></li><li><a href="Client.html#event:ready">ready</a></li><li><a href="HighLevelProducer.html#event:disconnected">disconnected</a></li><li><a href="HighLevelProducer.html#event:ready">ready</a></li><li><a href="KafkaConsumer.html#event:data">data</a></li><li><a href="KafkaConsumer.html#event:disconnected">disconnected</a></li><li><a href="KafkaConsumer.html#event:ready">ready</a></li><li><a href="Producer.html#event:disconnected">disconnected</a></li><li><a href="Producer.html#event:ready">ready</a></li></ul></li><li class="dropdown"><a class="dropdown-toggle" role="button" data-toggle="dropdown" href="#" onclick="return false;">Tutorials</a><ul class="dropdown-menu" role="menu"><li><a href="tutorial-consumer-flow.html">consumer-flow</a></li><li><a href="tutorial-consumer-per-partition.html">consumer-per-partition</a></li><li><a href="tutorial-consumer.html">consumer</a></li><li><a href="tutorial-docker-alpine.html">docker-alpine</a></li><li><a href="tutorial-high-level-producer.html">high-level-producer</a></li><li><a href="tutorial-metadata.html">metadata</a></li><li><a href="tutorial-producer-cluster.html">producer-cluster</a></li><li><a href="tutorial-producer_.html">producer</a></li></ul></li><h3>Global</h3><ul><li><a href="global.html#createAdminClient">createAdminClient</a></li><li><a href="global.html#createSerializer">createSerializer</a></li><li><a href="global.html#RefCounter">RefCounter</a></li><li><a href="global.html#Topic">Topic</a></li><li><a href="global.html#TopicPartition">TopicPartition</a></li></ul> </ul> </div> </div> </header> </div> <!-- /HEADER --> <div class="body-content"> <div class="grid-container project-container"> <div class="grid-75 push-25"> <h1>Class: KafkaConsumer</h1> <section> <header> <h2>KafkaConsumer</h2> </header> <article> <div class="container-overview"> <h4 class="name" id="KafkaConsumer"> <span class="type-signature"></span>new KafkaConsumer<span class="signature">(conf, topicConf)</span><span class="type-signature"></span> </h4> <div class="description"> <p>KafkaConsumer class for reading messages from Kafka This is the main entry point for reading data from Kafka. You configure this like you do any other client, with a global configuration and default topic configuration. Once you instantiate this object, connecting will open a socket. Data will not be read until you tell the consumer what topics you want to read from.</p> </div> <div class="clearfix"> <div class="grid-75"> <h4 class="heading-3">Parameters:</h4> </div> </div> <table class="params table table-striped"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name">conf</td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last">Key value pairs to configure the consumer</td> </tr> <tr> <td class="name">topicConf</td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last">Key value pairs to create a default topic configuration</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="pager"><li> <a href="kafka-consumer.js.html#line41">kafka-consumer.js, line 41</a> </li></ul> </dd> </dl> </div> <div class="clearfix"> <div class="grid-75"> <h3 class="heading-2">Extends:</h3> </div> <div class="grid-25 top-link"> <small> <a href="#top" class="inverse"> <i class="icon-chevron-up"></i> &nbsp;Back to top. </a> </small> </div> </div> <ul> <li><a href="Client.html">Client</a></li> </ul> <div class="clearfix"> <div class="grid-75"> <h3 class="heading-2">Members:</h3> </div> <div class="grid-25 top-link"> <small> <a href="#top" class="inverse"> <i class="icon-chevron-up"></i> &nbsp;Back to top. </a> </small> </div> </div> <h4 class="name" id="_metadata"><span class="type-signature"></span>_metadata<span class="type-signature"> :<a href="Client.html#~Metadata">Client~Metadata</a></span></h4> <div class="description"> <p> Metadata object. Starts out empty but will be filled with information after the initial connect. </p> </div> <h5>Type:</h5> <ul> <li> <span class="param-type"><a href="Client.html#~Metadata">Client~Metadata</a></span> </li> </ul> <dl class="details"> <dt class="inherited-from">Inherited From:</dt> <dd class="inherited-from"><ul class="dummy"><li> <a href="Client.html#_metadata">Client#_metadata</a> </li></ul></dd> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="pager"><li> <a href="client.js.html#line101">client.js, line 101</a> </li></ul> </dd> </dl> <div class="clearfix"> <div class="grid-75"> <h3 class="heading-2">Methods:</h3> </div> <div class="grid-25 top-link"> <small> <a href="#top" class="inverse"> <i class="icon-chevron-up"></i> &nbsp;Back to top. </a> </small> </div> </div> <h4 class="name" id=".createReadStream"> <span class="type-signature">(static) </span>createReadStream<span class="signature">(conf, topicConf, streamOptions)</span><span class="type-signature"> &rarr; {<a href="KafkaConsumerStream.html">KafkaConsumerStream</a>}</span> </h4> <div class="description"> <p>Get a stream representation of this KafkaConsumer</p> </div> <div class="clearfix"> <div class="grid-75"> <h4 class="heading-3">Parameters:</h4> </div> </div> <table class="params table table-striped"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name">conf</td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last">Key value pairs to configure the consumer</td> </tr> <tr> <td class="name">topicConf</td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last">Key value pairs to create a default topic configuration</td> </tr> <tr> <td class="name">streamOptions</td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last">Stream options <h6>Properties</h6> <table class="params table table-striped"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name">topics</td> <td class="type"> <span class="param-type">array</span> </td> <td class="description last">Array of topics to subscribe to.</td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="pager"><li> <a href="kafka-consumer.js.html#line174">kafka-consumer.js, line 174</a> </li></ul> </dd> <dt class="tag-see">See:</dt> <dd class="tag-see"> <ul> <li>TopicReadable</li> </ul> </dd> </dl> <h5>Returns:</h5> <div class="param-desc"> - Readable stream that receives messages when new ones become available. </div> <dl> <dt> Type </dt> <dd> <span class="param-type"><a href="KafkaConsumerStream.html">KafkaConsumerStream</a></span> </dd> </dl> <p> <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#modal-example-601-1"> Open Example 1 </button> </p> <div class="modal hide" id="modal-example-601-1"> <div class="modal-header"> <a href="#" class="close" data-dismiss="modal" onclick="return false;"> <i class="icon-remove icon-white"></i></a> <h1>Example 1</h1> </div> <div class="modal-body"> <pre class="prettyprint"><code>var consumerStream = Kafka.KafkaConsumer.createReadStream({ 'metadata.broker.list': 'localhost:9092', 'group.id': 'librd-test', 'socket.keepalive.enable': true, 'enable.auto.commit': false }, {}, { topics: [ 'test' ] });</code></pre> </div> </div> <h4 class="name" id="assign"> <span class="type-signature"></span>assign<span class="signature">(assignments)</span><span class="type-signature"> &rarr; {<a href="Client.html">Client</a>}</span> </h4> <div class="description"> <p>Assign the consumer specific partitions and topics</p> </div> <div class="clearfix"> <div class="grid-75"> <h4 class="heading-3">Parameters:</h4> </div> </div> <table class="params table table-striped"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name">assignments</td> <td class="type"> <span class="param-type">array</span> </td> <td class="description last">Assignments array. Should contain objects with topic and partition set.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="pager"><li> <a href="kafka-consumer.js.html#line262">kafka-consumer.js, line 262</a> </li></ul> </dd> </dl> <h5>Returns:</h5> <div class="param-desc"> - Returns itself </div> <dl> <dt> Type </dt> <dd> <span class="param-type"><a href="Client.html">Client</a></span> </dd> </dl> <h4 class="name" id="assignments"> <span class="type-signature"></span>assignments<span class="signature">()</span><span class="type-signature"> &rarr; {array}</span> </h4> <div class="description"> <p>Get the assignments for the consumer</p> </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="pager"><li> <a href="kafka-consumer.js.html#line285">kafka-consumer.js, line 285</a> </li></ul> </dd> </dl> <h5>Returns:</h5> <div class="param-desc"> assignments - Array of topic partitions </div> <dl> <dt> Type </dt> <dd> <span class="param-type">array</span> </dd> </dl> <h4 class="name" id="commit"> <span class="type-signature"></span>commit<span class="signature">(topicPartition)</span><span class="type-signature"> &rarr; {<a href="KafkaConsumer.html">KafkaConsumer</a>}</span> </h4> <div class="description"> <p>Commit a topic partition or all topic partitions that have been read If you provide a topic partition, it will commit that. Otherwise, it will commit all read offsets for all topic partitions.</p> </div> <div class="clearfix"> <div class="grid-75"> <h4 class="heading-3">Parameters:</h4> </div> </div> <table class="params table table-striped"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name">topicPartition</td> <td class="type"> <span class="param-type">object</span> | <span class="param-type">array</span> | <span class="param-type">null</span> </td> <td class="description last">Topic partition object to commit, list of topic partitions, or null if you want to commit all read offsets.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="pager"><li> <a href="kafka-consumer.js.html#line593">kafka-consumer.js, line 593</a> </li></ul> </dd> </dl> <div class="clearfix"> <div class="grid-75"> <h4 class="heading-3">Throws:</h4> </div> </div> <div class="param-desc"> When commit returns a non 0 error code </div> <h5>Returns:</h5> <div class="param-desc"> - returns itself. </div> <dl> <dt> Type </dt> <dd> <span class="param-type"><a href="KafkaConsumer.html">KafkaConsumer</a></span> </dd> </dl> <h4 class="name" id="commitMessage"> <span class="type-signature"></span>commitMessage<span class="signature">(msg)</span><span class="type-signature"> &rarr; {<a href="KafkaConsumer.html">KafkaConsumer</a>}</span> </h4> <div class="description"> <p>Commit a message This is basically a convenience method to map commit properly. We need to add one to the offset in this case</p> </div> <div class="clearfix"> <div class="grid-75"> <h4 class="heading-3">Parameters:</h4> </div> </div> <table class="params table table-striped"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name">msg</td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last">Message object to commit</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="pager"><li> <a href="kafka-consumer.js.html#line609">kafka-consumer.js, line 609</a> </li></ul> </dd> </dl> <div class="clearfix"> <div class="grid-75"> <h4 class="heading-3">Throws:</h4> </div> </div> <div class="param-desc"> When commit returns a non 0 error code </div> <h5>Returns:</h5> <div class="param-desc"> - returns itself. </div> <dl> <dt> Type </dt> <dd> <span class="param-type"><a href="KafkaConsumer.html">KafkaConsumer</a></span> </dd> </dl> <h4 class="name" id="commitMessageSync"> <span class="type-signature"></span>commitMessageSync<span class="signature">(msg)</span><span class="type-signature"> &rarr; {<a href="KafkaConsumer.html">KafkaConsumer</a>}</span> </h4> <div class="description"> <p>Commit a message synchronously</p> </div> <div class="clearfix"> <div class="grid-75"> <h4 class="heading-3">Parameters:</h4> </div> </div> <table class="params table table-striped"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name">msg</td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last">A message object to commit.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="pager"><li> <a href="kafka-consumer.js.html#line644">kafka-consumer.js, line 644</a> </li></ul> </dd> <dt class="tag-see">See:</dt> <dd class="tag-see"> <ul> <li><a href="KafkaConsumer.html#commitMessageSync">KafkaConsumer#commitMessageSync</a></li> </ul> </dd> </dl> <div class="clearfix"> <div class="grid-75"> <h4 class="heading-3">Throws:</h4> </div> </div> <dl> <dt> <div class="param-desc"> - if the commit fails </div> </dt> <dd></dd> <dt> <dl> <dt> Type </dt> <dd> <span class="param-type"><a href="LibrdKafkaError.html">LibrdKafkaError</a></span> </dd> </dl> </dt> <dd></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> - returns itself. </div> <dl> <dt> Type </dt> <dd> <span class="param-type"><a href="KafkaConsumer.html">KafkaConsumer</a></span> </dd> </dl> <h4 class="name" id="commitSync"> <span class="type-signature"></span>commitSync<span class="signature">(topicPartition)</span><span class="type-signature"> &rarr; {<a href="KafkaConsumer.html">KafkaConsumer</a>}</span> </h4> <div class="description"> <p>Commit a topic partition (or all topic partitions) synchronously</p> </div> <div class="clearfix"> <div class="grid-75"> <h4 class="heading-3">Parameters:</h4> </div> </div> <table class="params table table-striped"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name">topicPartition</td> <td class="type"> <span class="param-type">object</span> | <span class="param-type">array</span> | <span class="param-type">null</span> </td> <td class="description last">Topic partition object to commit, list of topic partitions, or null if you want to commit all read offsets.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="pager"><li> <a href="kafka-consumer.js.html#line629">kafka-consumer.js, line 629</a> </li></ul> </dd> </dl> <div class="clearfix"> <div class="grid-75"> <h4 class="heading-3">Throws:</h4> </div> </div> <dl> <dt> <div class="param-desc"> - if the commit fails </div> </dt> <dd></dd> <dt> <dl> <dt> Type </dt> <dd> <span class="param-type"><a href="LibrdKafkaError.html">LibrdKafkaError</a></span> </dd> </dl> </dt> <dd></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> - returns itself. </div> <dl> <dt> Type </dt> <dd> <span class="param-type"><a href="KafkaConsumer.html">KafkaConsumer</a></span> </dd> </dl> <h4 class="name" id="committed"> <span class="type-signature"></span>committed<span class="signature">(toppars, timeout, cb)</span><span class="type-signature"> &rarr; {<a href="Client.html">Client</a>}</span> </h4> <div class="description"> <p>Get a current list of the committed offsets per topic partition Returns an array of objects in the form of a topic partition list</p> </div> <div class="clearfix"> <div class="grid-75"> <h4 class="heading-3">Parameters:</h4> </div> </div> <table class="params table table-striped"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name">toppars</td> <td class="type"> <span class="param-type">Array.&lt;<a href="global.html#TopicPartition">TopicPartition</a>></span> </td> <td class="description last">Topic partition list to query committed offsets for. Defaults to the current assignment</td> </tr> <tr> <td class="name">timeout</td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last">Number of ms to block before calling back and erroring</td> </tr> <tr> <td class="name">cb</td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last">Callback method to execute when finished or timed out</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="pager"><li> <a href="kafka-consumer.js.html#line192">kafka-consumer.js, line 192</a> </li></ul> </dd> </dl> <h5>Returns:</h5> <div class="param-desc"> - Returns itself </div> <dl> <dt> Type </dt> <dd> <span class="param-type"><a href="Client.html">Client</a></span> </dd> </dl> <h4 class="name" id="connect"> <span class="type-signature"></span>connect<span class="signature">(metadataOptions, cb)</span><span class="type-signature"> &rarr; {<a href="Client.html">Client</a>}</span> </h4> <div class="description"> <p>Connect to the broker and receive its metadata. Connects to a broker by establishing the client and fetches its metadata.</p> </div> <div class="clearfix"> <div class="grid-75"> <h4 class="heading-3">Parameters:</h4> </div> </div> <table class="params table table-striped"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name">metadataOptions</td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last">Options to be sent to the metadata. <h6>Properties</h6> <table class="params table table-striped"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name">topic</td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">Topic to fetch metadata for. Empty string is treated as empty.</td> </tr> <tr> <td class="name">allTopics</td> <td class="type"> <span class="param-type">boolean</span> </td> <td class="description last">Fetch metadata for all topics, not just the ones we know about.</td> </tr> <tr> <td class="name">timeout</td> <td class="type"> <span class="param-type">int</span> </td> <td class="description last">The timeout, in ms, to allow for fetching metadata. Defaults to 30000ms</td> </tr> </tbody> </table> </td> </tr> <tr> <td class="name">cb</td> <td class="type"> <span class="param-type"><a href="Client.html#~connectionCallback">Client~connectionCallback</a></span> </td> <td class="description last">Callback that indicates we are done connecting.</td> </tr> </tbody> </table> <dl class="details"> <dt class="inherited-from">Inherited From:</dt> <dd class="inherited-from"><ul class="dummy"><li> <a href="Client.html#connect">Client#connect</a> </li></ul></dd> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="pager"><li> <a href="client.js.html#line135">client.js, line 135</a> </li></ul> </dd> </dl> <h5>Returns:</h5> <div class="param-desc"> - Returns itself. </div> <dl> <dt> Type </dt> <dd> <span class="param-type"><a href="Client.html">Client</a></span> </dd> </dl> <h4 class="name" id="connectedTime"> <span class="type-signature"></span>connectedTime<span class="signature">()</span><span class="type-signature"> &rarr; {number}</span> </h4> <div class="description"> <p>Find out how long we have been connected to Kafka.</p> </div> <dl class="details"> <dt class="inherited-from">Inherited From:</dt> <dd class="inherited-from"><ul class="dummy"><li> <a href="Client.html#connectedTime">Client#connectedTime</a> </li></ul></dd> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="pager"><li> <a href="client.js.html#line250">client.js, line 250</a> </li></ul> </dd> </dl> <h5>Returns:</h5> <div class="param-desc"> - Milliseconds since the connection has been established. </div> <dl> <dt> Type </dt> <dd> <span class="param-type">number</span> </dd> </dl> <h4 class="name" id="consume"> <span class="type-signature"></span>consume<span class="signature">(size, topic, partition, cb)</span><span class="type-signature"></span> </h4> <div class="description"> <p>Read a number of messages from a specific topic and partition. Can be useful if the consume performance differs per partition. Consuming per partition could prevent slow performance on one partition to effect the consumption of other partitions. To select the right partition it is required to set a topic param, because a consumer can be subscribed to multiple topics.</p> </div> <div class="clearfix"> <div class="grid-75"> <h4 class="heading-3">Parameters:</h4> </div> </div> <table class="params table table-striped"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name">size</td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last">Number of messages to read</td> </tr> <tr> <td class="name">topic</td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last">Name of topic to read</td> </tr> <tr> <td class="name">partition</td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last">Identifier of partition to read</td> </tr> <tr> <td class="name">cb</td> <td class="type"> <span class="param-type"><a href="KafkaConsumer.html#~readCallback">KafkaConsumer~readCallback</a></span> </td> <td class="description last">Callback to return when work is done.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="pager"><li> <a href="kafka-consumer.js.html#line401">kafka-consumer.js, line 401</a> </li></ul> </dd> </dl> <h4 class="name" id="consume"> <span class="type-signature"></span>consume<span class="signature">(size, cb)</span><span class="type-signature"></span> </h4> <div class="description"> <p>Read a number of messages from Kafka. This method is similar to the main one, except that it reads a number of messages before calling back. This may get better performance than reading a single message each time in stream implementations. This will keep going until it gets ERR__PARTITION_EOF or ERR__TIMED_OUT so the array may not be the same size you ask for. The size is advisory, but we will not exceed it.</p> </div> <div class="clearfix"> <div class="grid-75"> <h4 class="heading-3">Parameters:</h4> </div> </div> <table class="params table table-striped"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name">size</td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last">Number of messages to read</td> </tr> <tr> <td class="name">cb</td> <td class="type"> <span class="param-type"><a href="KafkaConsumer.html#~readCallback">KafkaConsumer~readCallback</a></span> </td> <td class="description last">Callback to return when work is done.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="pager"><li> <a href="kafka-consumer.js.html#line401">kafka-consumer.js, line 401</a> </li></ul> </dd> </dl> <h4 class="name" id="consume"> <span class="type-signature"></span>consume<span class="signature">(cb)</span><span class="type-signature"></span> </h4> <div class="description"> <p>Read messages from Kafka as fast as possible This method keeps a background thread running to fetch the messages as quickly as it can, sleeping only in between EOF and broker timeouts. Use this to get the maximum read performance if you don't care about the stream backpressure.</p> </div> <div class="clearfix"> <div class="grid-75"> <h4 class="heading-3">Parameters:</h4> </div> </div> <table class="params table table-striped"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name">cb</td> <td class="type"> <span class="param-type"><a href="KafkaConsumer.html#~readCallback">KafkaConsumer~readCallback</a></span> </td> <td class="description last">Callback to return when a message is fetched.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="pager"><li> <a href="kafka-consumer.js.html#line401">kafka-consumer.js, line 401</a> </li></ul> </dd> </dl> <h4 class="name" id="disconnect"> <span class="type-signature"></span>disconnect<span class="signature">()</span><span class="type-signature"> &rarr; {function}</span> </h4> <div class="description"> <p>Disconnect from the Kafka client. This method will disconnect us from Kafka unless we are already in a disconnecting state. Use this when you're done reading or producing messages on a given client. It will also emit the disconnected event.</p> </div> <dl class="details"> <dt class="inherited-from">Inherited From:</dt> <dd class="inherited-from"><ul class="dummy"><li> <a href="Client.html#disconnect">Client#disconnect</a> </li></ul></dd> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="pager"><li> <a href="client.js.html#line288">client.js, line 288</a> </li></ul> </dd> </dl> <div class="clearfix"> <div class="grid-75"> <h4 class="heading-3">Fires:</h4> </div> </div> <ul> <li><a href="Client.html#event:disconnected">Client#event:disconnected</a></li> </ul> <h5>Returns:</h5> <div class="param-desc"> - Callback to call when disconnection is complete. </div> <dl> <dt> Type </dt> <dd> <span class="param-type">function</span> </dd> </dl> <h4 class="name" id="getClient"> <span class="type-signature"></span>getClient<span class="signature">()</span><span class="type-signature"> &rarr; {Connection}</span> </h4> <div class="description"> <p>Get the native Kafka client. You probably shouldn't use this, but if you want to execute methods directly on the c++ wrapper you can do it here.</p> </div> <dl class="details"> <dt class="inherited-from">Inherited From:</dt> <dd class="inherited-from"><ul class="dummy"><li> <a href="Client.html#getClient">Client#getClient</a> </li></ul></dd> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="pager"><li> <a href="client.js.html#line241">client.js, line 241</a> </li></ul> </dd> <dt class="tag-see">See:</dt> <dd class="tag-see"> <ul> <li>connection.cc</li> </ul> </dd> </dl> <h5>Returns:</h5> <div class="param-desc"> - The native Kafka client. </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Connection</span> </dd> </dl> <h4 class="name" id="getLastError"> <span class="type-signature"></span>getLastError<span class="signature">()</span><span class="type-signature"> &rarr; {<a href="LibrdKafkaError.html">LibrdKafkaError</a>}</span> </h4> <div class="description"> <p>Get the last error emitted if it exists.</p> </div> <dl class="details"> <dt class="inherited-from">Inherited From:</dt> <dd class="inherited-from"><ul class="dummy"><li> <a href="Client.html#getLastError">Client#getLastError</a> </li></ul></dd> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="pager"><li> <a href="client.js.html#line272">client.js, line 272</a> </li></ul> </dd> </dl> <h5>Returns:</h5> <div class="param-desc"> - Returns the LibrdKafkaError or null if one hasn't been thrown. </div> <dl> <dt> Type </dt> <dd> <span class="param-type"><a href="LibrdKafkaError.html">LibrdKafkaError</a></span> </dd> </dl> <h4 class="name" id="getMetadata"> <span class="type-signature"></span>getMetadata<span class="signature">(metadataOptions, cb)</span><span class="type-signature"></span> </h4> <div class="description"> <p>Get client metadata. Note: using a <code>metadataOptions.topic</code> parameter has a potential side-effect. A Topic object will be created, if it did not exist yet, with default options and it will be cached by librdkafka. A subsequent call to create the topic object with specific options (e.g. <code>acks</code>) will return the previous instance and the specific options will be silently ignored. To avoid this side effect, the topic object can be created with the expected options before requesting metadata, or the metadata request can be performed for all topics (by omitting <code>metadataOptions.topic</code>).</p> </div> <div class="clearfix"> <div class="grid-75"> <h4 class="heading-3">Parameters:</h4> </div> </div> <table class="params table table-striped"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name">metadataOptions</td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last">Metadata options to pass to the client. <h6>Properties</h6> <table class="params table table-striped"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name">topic</td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">Topic string for which to fetch metadata</td> </tr> <tr> <td class="name">timeout</td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last">Max time, in ms, to try to fetch metadata before timing out. Defaults to 3000.</td> </tr> </tbody> </table> </td> </tr> <tr> <td class="name">cb</td> <td class="type"> <span class="param-type">Client~metadataCallback</span> </td> <td class="description last">Callback to fire with the metadata.</td> </tr> </tbody> </table> <dl class="details"> <dt class="inherited-from">Inherited From:</dt> <dd class="inherited-from"><ul class="dummy"><li> <a href="Client.html#getMetadata">Client#getMetadata</a> </li></ul></dd> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="pager"><li> <a href="client.js.html#line340">client.js, line 340</a> </li></ul> </dd> </dl> <h4 class="name" id="getWatermarkOffsets"> <span class="type-signature"></span>getWatermarkOffsets<span class="signature">(topic, partition)</span><span class="type-signature"> &rarr; {<a href="Client.html#~watermarkOffsets">Client~watermarkOffsets</a>}</span> </h4> <div class="description"> <p>Get last known offsets from the client. The low offset is updated periodically (if statistics.interval.ms is set) while the high offset is updated on each fetched message set from the broker. If there is no cached offset (either low or high, or both), then this will throw an error.</p> </div> <div class="clearfix"> <div class="grid-75"> <h4 class="heading-3">Parameters:</h4> </div> </div> <table class="params table table-striped"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name">topic</td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">Topic to recieve offsets from.</td> </tr> <tr> <td class="name">partition</td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last">Partition of the provided topic to recieve offsets from</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="pager"><li> <a href="kafka-consumer.js.html#line671">kafka-consumer.js, line 671</a> </li></ul> </dd> </dl> <div class="clearfix"> <div class="grid-75"> <h4 class="heading-3">Throws:</h4> </div> </div> <dl> <dt> <div class="param-desc"> - Throws when there is no offset stored </div> </dt> <dd></dd> <dt> <dl> <dt> Type </dt> <dd> <span class="param-type"><a href="LibrdKafkaError.html">LibrdKafkaError</a></span> </dd> </dl> </dt> <dd></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> - Returns an object with a high and low property, specifying the high and low offsets for the topic partition </div> <dl> <dt> Type </dt> <dd> <span class="param-type"><a href="Client.html#~watermarkOffsets">Client~watermarkOffsets</a></span> </dd> </dl> <h4 class="name" id="isConnected"> <span class="type-signature"></span>isConnected<span class="signature">()</span><span class="type-signature"> &rarr; {boolean}</span> </h4> <div class="description"> <p>Whether or not we are connected to Kafka.</p> </div> <dl class="details"> <dt class="inherited-from">Inherited From:</dt> <dd class="inherited-from"><ul class="dummy"><li> <a href="Client.html#isConnected">Client#isConnected</a> </li></ul></dd> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="pager"><li> <a href="client.js.html#line262">client.js, line 262</a> </li></ul> </dd> </dl> <h5>Returns:</h5> <div class="param-desc"> - Whether we are connected. </div> <dl> <dt> Type </dt> <dd> <span class="param-type">boolean</span> </dd> </dl> <h4 class="name" id="offsetsForTimes"> <span class="type-signature"></span>offsetsForTimes<span class="signature">(toppars, timeout, cb)</span><span class="type-signature"></span> </h4> <div class="description"> <p>Query offsets for times from the broker. This function makes a call to the broker to get the offsets for times specified.</p> </div> <div class="clearfix"> <div class="grid-