UNPKG

node-rdkafka-imhoff

Version:
311 lines (264 loc) • 12.2 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Source: admin.js</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"> Source: admin.js <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>Source: admin.js</h1> <section> <article> <pre class="prettyprint source linenums"><code>/* * node-rdkafka - Node.js wrapper for RdKafka C/C++ library * * Copyright (c) 2016 Blizzard Entertainment * * This software may be modified and distributed under the terms * of the MIT license. See the LICENSE.txt file for details. */ 'use strict'; module.exports = { create: createAdminClient, }; var Client = require('./client'); var util = require('util'); var Kafka = require('../librdkafka'); var LibrdKafkaError = require('./error'); var shallowCopy = require('./util').shallowCopy; /** * Create a new AdminClient for making topics, partitions, and more. * * This is a factory method because it immediately starts an * active handle with the brokers. * */ function createAdminClient(conf) { var client = new AdminClient(conf); // Wrap the error so we throw if it failed with some context LibrdKafkaError.wrap(client.connect(), true); // Return the client if we succeeded return client; } /** * AdminClient class for administering Kafka * * This client is the way you can interface with the Kafka Admin APIs. * This class should not be made using the constructor, but instead * should be made using the factory method. * * &lt;code> * var client = AdminClient.create({ ... }); * &lt;/code> * * Once you instantiate this object, it will have a handle to the kafka broker. * Unlike the other node-rdkafka classes, this class does not ensure that * it is connected to the upstream broker. Instead, making an action will * validate that. * * @param {object} conf - Key value pairs to configure the admin client * topic configuration * @constructor */ function AdminClient(conf) { if (!(this instanceof AdminClient)) { return new AdminClient(conf); } conf = shallowCopy(conf); /** * NewTopic model. * * This is the representation of a new message that is requested to be made * using the Admin client. * * @typedef {object} AdminClient~NewTopic * @property {string} topic - the topic name to create * @property {number} num_partitions - the number of partitions to give the topic * @property {number} replication_factor - the replication factor of the topic * @property {object} config - a list of key values to be passed as configuration * for the topic. */ this._client = new Kafka.AdminClient(conf); this._isConnected = false; this.globalConfig = conf; } /** * Connect using the admin client. * * Should be run using the factory method, so should never * need to be called outside. * * Unlike the other connect methods, this one is synchronous. */ AdminClient.prototype.connect = function() { LibrdKafkaError.wrap(this._client.connect(), true); this._isConnected = true; }; /** * Disconnect the admin client. * * This is a synchronous method, but all it does is clean up * some memory and shut some threads down */ AdminClient.prototype.disconnect = function() { LibrdKafkaError.wrap(this._client.disconnect(), true); this._isConnected = false; }; /** * Create a topic with a given config. * * @param {NewTopic} topic - Topic to create. * @param {number} timeout - Number of milliseconds to wait while trying to create the topic. * @param {function} cb - The callback to be executed when finished */ AdminClient.prototype.createTopic = function(topic, timeout, cb) { if (!this._isConnected) { throw new Error('Client is disconnected'); } if (typeof timeout === 'function') { cb = timeout; timeout = 5000; } if (!timeout) { timeout = 5000; } this._client.createTopic(topic, timeout, function(err) { if (err) { if (cb) { cb(LibrdKafkaError.create(err)); } return; } if (cb) { cb(); } }); }; /** * Delete a topic. * * @param {string} topic - The topic to delete, by name. * @param {number} timeout - Number of milliseconds to wait while trying to delete the topic. * @param {function} cb - The callback to be executed when finished */ AdminClient.prototype.deleteTopic = function(topic, timeout, cb) { if (!this._isConnected) { throw new Error('Client is disconnected'); } if (typeof timeout === 'function') { cb = timeout; timeout = 5000; } if (!timeout) { timeout = 5000; } this._client.deleteTopic(topic, timeout, function(err) { if (err) { if (cb) { cb(LibrdKafkaError.create(err)); } return; } if (cb) { cb(); } }); }; /** * Create new partitions for a topic. * * @param {string} topic - The topic to add partitions to, by name. * @param {number} totalPartitions - The total number of partitions the topic should have * after the request * @param {number} timeout - Number of milliseconds to wait while trying to create the partitions. * @param {function} cb - The callback to be executed when finished */ AdminClient.prototype.createPartitions = function(topic, totalPartitions, timeout, cb) { if (!this._isConnected) { throw new Error('Client is disconnected'); } if (typeof timeout === 'function') { cb = timeout; timeout = 5000; } if (!timeout) { timeout = 5000; } this._client.createPartitions(topic, totalPartitions, timeout, function(err) { if (err) { if (cb) { cb(LibrdKafkaError.create(err)); } return; } if (cb) { cb(); } }); }; </code></pre> </article> </section> </div> <div class="grid-25 pull-75"> <div class="navigation-sidebar"> <ul class="nav nav-list"> <li><a href="javascript: void(0);">Classes</a><ul class="nav nav-list" 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><a href="javascript: void(0);">Events</a><ul class="nav nav-list" 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><a href="javascript: void(0);">Tutorials</a><ul class="nav nav-list" 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> <!-- <ul class="nav nav-list collapse"> --> </div> </div> </div> </div> </div> <!-- /.body-content --> <br class="clear"> <!-- FOOTER --> <footer class="footer"> <div class="grid-container"> <div class="footer-content"> <div class="grid-75"> <div class="legal"> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc </a> on Thu Jan 11 2024 10:36:33 GMT+0100 (Central European Standard Time) </div> </div> <div class="grid-25"> <span class="blizzard">Blizzard® Entertainment</span> </div> </div> </div> </footer> <!-- /FOOTER --> <script> prettyPrint(); </script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script> <script src="toolkit/js/toolkit/toolkit.min.js"> </script> </body> </html>