Constructor
new Admin(config, existingClient)
Parameters:
Name | Type | Description |
---|---|---|
config |
||
existingClient |
Example
const { Kafka } = require('@confluentinc/kafka-javascript');
// From a Kafka object.
const kafka = new Kafka({ 'bootstrap.servers': 'localhost:9092' });
const admin = kafka.admin();
await admin.connect();
await admin.createTopics({ });
// From a producer/consumer
const admin = preExistingProducer.dependentAdmin();
await admin.connect();
await admin.createTopics({ });
Methods
(async) connect() → {Promise.<void>}
Set up the client and connect to the bootstrap brokers.
Returns:
Resolves when connection is complete, rejects on error.
- Type
- Promise.<void>
(async) createTopics(options) → {Promise.<boolean>}
Create topics with the given configuration.
Parameters:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
Properties
|
Returns:
Resolves true when the topics are created, false if topic exists already, rejects on error. In case even one topic already exists, this will return false.
- Type
- Promise.<boolean>
(async) deleteGroups(groups, optionsnullable) → {Promise.<Array.<{groupId: string, errorCode: (number|null), error: (RdKafka.LibrdKafkaError|null)}>>}
Delete consumer groups.
Parameters:
Name | Type | Attributes | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
groups |
Array.<string> | The names of the groups to delete. |
|||||||||
options |
object |
<nullable> |
Properties
|
Returns:
Resolves with the list of deletion reports (including per-group errors).
- Type
- Promise.<Array.<{groupId: string, errorCode: (number|null), error: (RdKafka.LibrdKafkaError|null)}>>
(async) deleteTopicRecords(options) → {Promise.<Array.<{topic: string, partition: number, lowWatermark: number, error: (RdKafka.LibrdKafkaError|null)}>>}
Deletes records (messages) in topic partitions older than the offsets provided.
Provide -1 as offset to delete all records in the partition.
Parameters:
Name | Type | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
Properties
|
Returns:
A list of results for each partition.
- Type
- Promise.<Array.<{topic: string, partition: number, lowWatermark: number, error: (RdKafka.LibrdKafkaError|null)}>>
(async) deleteTopics(options) → {Promise.<void>}
Deletes given topics.
Parameters:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
Properties
|
Returns:
Resolves when the topics are deleted, rejects on error.
- Type
- Promise.<void>
(async) describeGroups(groups, optionsnullable) → {Promise.<{groups: Array.<object>}>}
Describe consumer groups.
Parameters:
Name | Type | Attributes | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
groups |
Array.<string> | The names of the groups to describe. |
|||||||||||||
options |
object |
<nullable> |
Properties
|
Returns:
The descriptions of the requested groups.
- Type
- Promise.<{groups: Array.<object>}>
(async) disconnect() → {Promise.<void>}
Disconnect from the brokers, clean-up and tear down the client.
Returns:
Resolves when disconnect is complete, rejects on error.
- Type
- Promise.<void>
(async) fetchOffsets(optionsnullable) → {Promise.<Array.<{topic: string, partitions: Array.<object>}>>}
Fetch the offsets for topic partition(s) for consumer group(s).
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
<nullable> |
Properties
|
Returns:
The list of requested offsets.
- Type
- Promise.<Array.<{topic: string, partitions: Array.<object>}>>
(async) fetchTopicMetadata(optionsnullable) → {Promise.<{topics: Array.<object>}>}
Describe topics.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
<nullable> |
Properties
|
Returns:
- Type
- Promise.<{topics: Array.<object>}>
(async) fetchTopicOffsets(topic, optionsnullable) → {Promise.<Array.<{partition: number, offset: string, high: string, low: string}>>}
List offsets for the specified topic partition(s).
Parameters:
Name | Type | Attributes | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
topic |
string | The topic to fetch offsets for. |
|||||||||||||
options |
object |
<nullable> |
Properties
|
Returns:
- Type
- Promise.<Array.<{partition: number, offset: string, high: string, low: string}>>
(async) listGroups(optionsnullable) → {Promise.<{groups: Array.<{groupId: string, protocolType: string, isSimpleConsumerGroup: boolean, state: KafkaJS.ConsumerGroupStates}>, errors: Array.<RdKafka.LibrdKafkaError>}>}
List consumer groups.
Parameters:
Name | Type | Attributes | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
<nullable> |
Properties
|
Returns:
Resolves with the list of consumer groups, rejects on error.
- Type
- Promise.<{groups: Array.<{groupId: string, protocolType: string, isSimpleConsumerGroup: boolean, state: KafkaJS.ConsumerGroupStates}>, errors: Array.<RdKafka.LibrdKafkaError>}>
(async) listTopics(optionsnullable) → {Promise.<Array.<string>>}
List topics.
Parameters:
Name | Type | Attributes | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
<nullable> |
Properties
|
Returns:
The list of all topics.
- Type
- Promise.<Array.<string>>