Class: AdminClient

RdKafka.AdminClient(conf, existingClient)

new AdminClient(conf, existingClient)

AdminClient class for administering Kafka clusters (promise-based, async API).

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 methods (see RdKafka.AdminClient.create and RdKafka.AdminClient.createFrom).

Once you instantiate this object, it will have a handle to the kafka broker. Unlike the other confluent-kafka-javascript classes, this class does not ensure that it is connected to the upstream broker. Instead, making an action will validate that.

Parameters:
Name Type Description
conf object | null

Key value pairs to configure the admin client

existingClient RdKafka.Producer | RdKafka.KafkaConsumer | null

An existing producer or consumer to create the admin client from (optional).

Example
var client = AdminClient.create({ ... }); // From configuration
var client = AdminClient.createFrom(existingClient); // From existing producer or consumer

Methods

createPartitions(topic, totalPartitions, timeoutnullable, cb)

Create new partitions for a topic.

Parameters:
Name Type Attributes Description
topic string

The topic to add partitions to, by name.

totalPartitions number

The total number of partitions the topic should have after the request.

timeout number <nullable>

Number of milliseconds to wait while trying to create the partitions. Set to 5000 by default.

cb function

The callback to be executed when finished.

createTopic(topic, timeoutnullable, cb)

Create a topic with a given config.

Parameters:
Name Type Attributes Description
topic object

Topic to create.

Properties
Name Type Attributes Description
topic string

The name of the topic to create.

num_partitions number

The number of partitions for the topic.

replication_factor number

The replication factor for the topic.

config object <nullable>

The topic configuration. The keys of this object denote the keys of the configuration.

timeout number <nullable>

Number of milliseconds to wait while trying to create the topic. Set to 5000 by default.

cb function

The callback to be executed when finished.

deleteGroups(groups, options, cb)

Delete consumer groups.

Parameters:
Name Type Description
groups Array.<string>

The names of the groups to delete.

options object
Properties
Name Type Attributes Description
timeout number <nullable>

The request timeout in milliseconds. May be unset (default: 5000).

cb function

The callback to be executed when finished.

Example
// Valid ways to call this function:
deleteGroups(groups, cb)
deleteGroups(groups, options, cb)

deleteRecords(delRecords, options, cb)

Deletes records (messages) in topic partitions older than the offsets provided. Provide Topic.OFFSET_END or -1 as the offset to delete all records.

Parameters:
Name Type Description
delRecords Array.<{topic: string, partition: number, offset: number}>

The list of topic partitions and offsets to delete records up to.

options object
Properties
Name Type Attributes Description
operationTimeout number <nullable>

The operation timeout in milliseconds. May be unset (default: 60000).

timeout number <nullable>

The request timeout in milliseconds. May be unset (default: 5000).

cb function

The callback to be executed when finished.

deleteTopic(topic, timeoutnullable, cb)

Delete a topic.

Parameters:
Name Type Attributes Description
topic string

The topic to delete, by name.

timeout number <nullable>

Number of milliseconds to wait while trying to delete the topic. Set to 5000 by default.

cb function

The callback to be executed when finished.

describeGroups(groups, options, cb)

Describe consumer groups.

Parameters:
Name Type Description
groups Array.<string>

The names of the groups to describe.

options object
Properties
Name Type Attributes Description
timeout number <nullable>

The request timeout in milliseconds. May be unset (default: 5000).

includeAuthorizedOperations boolean <nullable>

If true, include operations allowed on the group by the calling client (default: false).

cb function

The callback to be executed when finished.

Example
// Valid ways to call this function:
describeGroups(groups, cb)
describeGroups(groups, options, cb)

describeTopics(topics, options, cb)

Describe topics.

Parameters:
Name Type Description
topics Array.<string>

The names of the topics to describe.

options object
Properties
Name Type Attributes Description
timeout number <nullable>

The request timeout in milliseconds. May be unset (default: 5000).

includeAuthorizedOperations boolean <nullable>

If true, include operations allowed on the topic by the calling client. (default: false).

cb function

The callback to be executed when finished.

disconnect()

Disconnect the admin client.

This is a synchronous method, but all it does is clean up some memory and shut some threads down.

listConsumerGroupOffsets(listGroupOffsets, options, cb)

List offsets for topic partition(s) for consumer group(s).

Parameters:
Name Type Description
listGroupOffsets Object

The list of groupId, partitions to fetch offsets for. If partitions is null, list offsets for all partitions in the group.

options object
Properties
Name Type Attributes Description
timeout number <nullable>

The request timeout in milliseconds. May be unset (default: 5000).

requireStableOffsets boolean <nullable>

Whether broker should return stable offsets (transaction-committed). (default: false).

cb function

The callback to be executed when finished.

listGroups(options, cb)

List consumer groups.

Parameters:
Name Type Description
options any
Properties
Name Type Attributes Description
timeout number <nullable>

The request timeout in milliseconds. May be unset (default: 5000).

matchConsumerGroupStates Array.<RdKafka.ConsumerGroupStates> <nullable>

A list of consumer group states to match. May be unset, fetches all states (default: unset).

cb function

The callback to be executed when finished.

Example
// Valid ways to call this function:
listGroups(cb);
listGroups(options, cb);

listOffsets(partitions, optionsnullable, cb)

List offsets for topic partition(s).

Parameters:
Name Type Attributes Description
partitions Array.<{topic: string, partition: number, offset: OffsetSpec}>

The list of partitions to fetch offsets for.

options any <nullable>
Properties
Name Type Attributes Description
timeout number <nullable>

The request timeout in milliseconds. May be unset (default: 5000)

isolationLevel RdKafka.IsolationLevel <nullable>

The isolation level for reading the offsets. (default: READ_UNCOMMITTED)

cb function

The callback to be executed when finished.

listTopics(options, cb)

List topics.

Parameters:
Name Type Description
options object
Properties
Name Type Attributes Description
timeout number <nullable>

The request timeout in milliseconds. May be unset (default: 5000).

cb function

The callback to be executed when finished.

Example
// Valid ways to call this function:
listTopics(cb)
listTopics(options, cb)

(static) create(conf, eventHandlersnullable)

Create a new AdminClient using the provided configuration.

This is a factory method because it immediately starts an active handle with the brokers.

Parameters:
Name Type Attributes Description
conf object

Key value pairs to configure the admin client.

eventHandlers object <nullable>

Optional key value pairs of event handlers to attach to the client.

(static) createFrom(existingClient, eventHandlersnullable)

Create a new AdminClient from an existing producer or consumer.

This is a factory method because it immediately starts an active handle with the brokers.

The producer or consumer being used must be connected before creating the admin client, and the admin client can only be used while the producer or consumer is connected.

Logging and other events from this client will be emitted on the producer or consumer.

Parameters:
Name Type Attributes Description
existingClient RdKafka.Producer | RdKafka.KafkaConsumer

A producer or consumer to create the admin client from.

eventHandlers object <nullable>

Optional key value pairs of event handlers to attach to the client.