[kafka-node] New Admin class methods (#37876)

* Added Admin class new methods https://www.npmjs.com/package/kafka-node#admin

* Fixed tslint issues, added tests.

* fixed identation
This commit is contained in:
rstpv 2019-09-09 19:37:30 -05:00 committed by Andrew Casey
parent 5d2b848c4a
commit f560b262e0
2 changed files with 46 additions and 6 deletions

View File

@ -5,6 +5,7 @@
// Michael Haan <https://github.com/sfrooster>
// Amiram Korach <https://github.com/amiram>
// Insanehong <https://github.com/insanehong>
// Roger <https://github.com/rstpv>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
@ -103,9 +104,32 @@ export class KeyedMessage {
export class Admin {
constructor(kafkaClient: KafkaClient);
listGroups(cb: (error: any, data: any) => any): void;
describeGroups(consumerGroups: any, cb: (error: any, data: any) => any): void;
describeGroups(
consumerGroups: any,
cb: (error: any, data: any) => any,
): void;
listTopics(cb: (error: any, data: any) => any): void;
createTopics(
topics: TopicConfigData[],
cb: (error: any, data: any) => any,
): void;
describeConfigs(
payload: { resources: Resource[]; includeSynonyms: boolean },
cb: (error: any, data: any) => any,
): void;
}
export interface Resource {
resourceType: string;
resourceName: string;
configNames: string[];
}
export interface TopicConfigData {
topic: string;
partitions?: number;
replicationFactor?: number;
configEntry?: Array<{ name: string; value: string }>;
}
// # Interfaces
export interface Message {
@ -115,7 +139,7 @@ export interface Message {
partition?: number;
highWaterOffset?: number;
key?: string;
}
}
export interface ProducerOptions {
requireAcks?: number;
@ -173,10 +197,10 @@ export interface ConsumerOptions {
}
export interface HighLevelConsumerOptions extends ConsumerOptions {
id?: string;
maxNumSegments?: number;
maxTickMessages?: number;
rebalanceRetry?: RetryOptions;
id?: string;
maxNumSegments?: number;
maxTickMessages?: number;
rebalanceRetry?: RetryOptions;
}
export interface CustomPartitionAssignmentProtocol {

View File

@ -280,3 +280,19 @@ admin.listGroups((err, data) => {
});
admin.describeGroups({}, (err, data) => {
});
admin.createTopics([{ topic: 'testing' }], (err, data) => {});
admin.listTopics((err, data) => {
});
const resource = {
resourceType: "", // 'broker' or 'topic'
resourceName: 'my-topic-name',
configNames: [] // specific config names, or empty array to return all,
};
const payload = {
resources: [resource],
includeSynonyms: false // requires kafka 2.0+
};
admin.describeConfigs(payload, (err, res) => {
console.log(JSON.stringify(res, null, 1));
});