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:
NameTypeDescription
confobject | null

Key value pairs to configure the admin client

existingClientRdKafka.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:
NameTypeAttributesDescription
topicstring

The topic to add partitions to, by name.

totalPartitionsnumber

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

timeoutnumber <nullable>

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

cbfunction

The callback to be executed when finished.

createTopic(topic, timeoutnullable, cb)

Create a topic with a given config.

Parameters:
NameTypeAttributesDescription
topicobject

Topic to create.

Properties
NameTypeAttributesDescription
topicstring

The name of the topic to create.

num_partitionsnumber

The number of partitions for the topic.

replication_factornumber

The replication factor for the topic.

configobject <nullable>

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

timeoutnumber <nullable>

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

cbfunction

The callback to be executed when finished.

deleteGroups(groups, options, cb)

Delete consumer groups.

Parameters:
NameTypeDescription
groupsArray.<string>

The names of the groups to delete.

optionsobject
Properties
NameTypeAttributesDescription
timeoutnumber <nullable>

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

cbfunction

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:
NameTypeDescription
delRecordsArray.<{topic: string, partition: number, offset: number}>

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

optionsobject
Properties
NameTypeAttributesDescription
operationTimeoutnumber <nullable>

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

timeoutnumber <nullable>

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

cbfunction

The callback to be executed when finished.

deleteTopic(topic, timeoutnullable, cb)

Delete a topic.

Parameters:
NameTypeAttributesDescription
topicstring

The topic to delete, by name.

timeoutnumber <nullable>

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

cbfunction

The callback to be executed when finished.

describeGroups(groups, options, cb)

Describe consumer groups.

Parameters:
NameTypeDescription
groupsArray.<string>

The names of the groups to describe.

optionsobject
Properties
NameTypeAttributesDescription
timeoutnumber <nullable>

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

includeAuthorizedOperationsboolean <nullable>

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

cbfunction

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:
NameTypeDescription
topicsArray.<string>

The names of the topics to describe.

optionsobject
Properties
NameTypeAttributesDescription
timeoutnumber <nullable>

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

includeAuthorizedOperationsboolean <nullable>

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

cbfunction

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:
NameTypeDescription
listGroupOffsetsObject

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

optionsobject
Properties
NameTypeAttributesDescription
timeoutnumber <nullable>

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

requireStableOffsetsboolean <nullable>

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

cbfunction

The callback to be executed when finished.

listGroups(options, cb)

List consumer groups.

Parameters:
NameTypeDescription
optionsany
Properties
NameTypeAttributesDescription
timeoutnumber <nullable>

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

matchConsumerGroupStatesArray.<RdKafka.ConsumerGroupStates> <nullable>

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

matchConsumerGroupTypesArray.<RdKafka.ConsumerGroupTypes> <nullable>

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

cbfunction

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:
NameTypeAttributesDescription
partitionsArray.<{topic: string, partition: number, offset: OffsetSpec}>

The list of partitions to fetch offsets for.

optionsany <nullable>
Properties
NameTypeAttributesDescription
timeoutnumber <nullable>

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

isolationLevelRdKafka.IsolationLevel <nullable>

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

cbfunction

The callback to be executed when finished.

listTopics(options, cb)

List topics.

Parameters:
NameTypeDescription
optionsobject
Properties
NameTypeAttributesDescription
timeoutnumber <nullable>

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

cbfunction

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:
NameTypeAttributesDescription
confobject

Key value pairs to configure the admin client.

eventHandlersobject <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:
NameTypeAttributesDescription
existingClientRdKafka.Producer | RdKafka.KafkaConsumer

A producer or consumer to create the admin client from.

eventHandlersobject <nullable>

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