@@ -2,39 +2,39 @@ import { Readable, Writable } from 'stream';
22import { EventEmitter } from 'events' ;
33
44export class KafkaClient extends EventEmitter {
5- constructor ( options ?: KafkaClientOptions ) ;
5+ constructor ( options ?: KafkaClientOptions ) ;
66
7- close ( cb ?: ( ) => void ) : void ;
7+ close ( cb ?: ( ) => void ) : void ;
88
9- topicExists ( topics : string [ ] , cb : ( error ?: TopicsNotExistError | any ) => any ) : void ;
9+ topicExists ( topics : string [ ] , cb : ( error ?: TopicsNotExistError | any ) => any ) : void ;
1010
11- refreshMetadata ( topics : string [ ] , cb ?: ( error ?: any ) => any ) : void ;
11+ refreshMetadata ( topics : string [ ] , cb ?: ( error ?: any ) => any ) : void ;
1212
13- sendOffsetCommitV2Request ( group : string , generationId : number , memberId : string , commits : OffsetCommitRequest [ ] , cb : ( error : any , data : any ) => any ) : void ;
13+ sendOffsetCommitV2Request ( group : string , generationId : number , memberId : string , commits : OffsetCommitRequest [ ] , cb : ( error : any , data : any ) => any ) : void ;
1414
1515 // Note: socket_error is currently KafkaClient only, and zkReconnect is currently Client only.
16- on ( eventName : 'brokersChanged' | 'close' | 'connect' | 'ready' | 'reconnect' | 'zkReconnect' , cb : ( ) => any ) : this;
17- on ( eventName : 'error' | 'socket_error' , cb : ( error : any ) => any ) : this;
16+ on ( eventName : 'brokersChanged' | 'close' | 'connect' | 'ready' | 'reconnect' | 'zkReconnect' , cb : ( ) => any ) : this;
17+ on ( eventName : 'error' | 'socket_error' , cb : ( error : any ) => any ) : this;
1818
19- connect ( ) : void ;
19+ connect ( ) : void ;
2020
21- createTopics ( topics : CreateTopicRequest [ ] , callback : ( error : any , result : CreateTopicResponse [ ] ) => any ) : void ;
21+ createTopics ( topics : CreateTopicRequest [ ] , callback : ( error : any , result : CreateTopicResponse [ ] ) => any ) : void ;
2222
23- loadMetadataForTopics ( topics : string [ ] , callback : ( error : any , result : MetadataResponse ) => any ) : void ;
23+ loadMetadataForTopics ( topics : string [ ] , callback : ( error : any , result : MetadataResponse ) => any ) : void ;
2424}
2525
2626export class Producer extends EventEmitter {
27- constructor ( client : KafkaClient , options ?: ProducerOptions , customPartitioner ?: CustomPartitioner ) ;
27+ constructor ( client : KafkaClient , options ?: ProducerOptions , customPartitioner ?: CustomPartitioner ) ;
2828
29- on ( eventName : 'ready' , cb : ( ) => any ) : this;
30- on ( eventName : 'error' , cb : ( error : any ) => any ) : this;
29+ on ( eventName : 'ready' , cb : ( ) => any ) : this;
30+ on ( eventName : 'error' , cb : ( error : any ) => any ) : this;
3131
32- send ( payloads : ProduceRequest [ ] , cb : ( error : any , data : any ) => any ) : void ;
32+ send ( payloads : ProduceRequest [ ] , cb : ( error : any , data : any ) => any ) : void ;
3333
34- createTopics ( topics : string [ ] , async : boolean , cb : ( error : any , data : any ) => any ) : void ;
35- createTopics ( topics : string [ ] , cb : ( error : any , data : any ) => any ) : void ;
34+ createTopics ( topics : string [ ] , async : boolean , cb : ( error : any , data : any ) => any ) : void ;
35+ createTopics ( topics : string [ ] , cb : ( error : any , data : any ) => any ) : void ;
3636
37- close ( cb ?: ( ) => any ) : void ;
37+ close ( cb ?: ( ) => any ) : void ;
3838}
3939
4040export class HighLevelProducer extends Producer {
@@ -43,106 +43,123 @@ export class HighLevelProducer extends Producer {
4343export class Consumer extends EventEmitter {
4444 client : KafkaClient ;
4545
46- constructor ( client : KafkaClient , fetchRequests : Array < OffsetFetchRequest | string > , options : ConsumerOptions ) ;
46+ constructor ( client : KafkaClient , fetchRequests : Array < OffsetFetchRequest | string > , options : ConsumerOptions ) ;
4747
48- on ( eventName : 'message' , cb : ( message : Message ) => any ) : this;
49- on ( eventName : 'error' | 'offsetOutOfRange' , cb : ( error : any ) => any ) : this;
48+ on ( eventName : 'message' , cb : ( message : Message ) => any ) : this;
49+ on ( eventName : 'error' | 'offsetOutOfRange' , cb : ( error : any ) => any ) : this;
5050
51- addTopics < T extends string [ ] | Topic [ ] > ( topics : T , cb : ( error : any , added : T ) => any , fromOffset ?: boolean ) : void ;
51+ addTopics < T extends string [ ] | Topic [ ] > ( topics : T , cb : ( error : any , added : T ) => any , fromOffset ?: boolean ) : void ;
5252
53- removeTopics ( topics : string | string [ ] , cb : ( error : any , removed : number ) => any ) : void ;
53+ removeTopics ( topics : string | string [ ] , cb : ( error : any , removed : number ) => any ) : void ;
5454
55- commit ( cb : ( error : any , data : any ) => any ) : void ;
56- commit ( force : boolean , cb : ( error : any , data : any ) => any ) : void ;
55+ commit ( cb : ( error : any , data : any ) => any ) : void ;
56+ commit ( force : boolean , cb : ( error : any , data : any ) => any ) : void ;
5757
58- setOffset ( topic : string , partition : number , offset : number ) : void ;
58+ setOffset ( topic : string , partition : number , offset : number ) : void ;
5959
60- pause ( ) : void ;
60+ pause ( ) : void ;
6161
62- resume ( ) : void ;
62+ resume ( ) : void ;
6363
64- pauseTopics ( topics : any [ ] /* Array<string|Topic> */ ) : void ;
64+ pauseTopics ( topics : any [ ] /* Array<string|Topic> */ ) : void ;
6565
66- resumeTopics ( topics : any [ ] /* Array<string|Topic> */ ) : void ;
66+ resumeTopics ( topics : any [ ] /* Array<string|Topic> */ ) : void ;
6767
68- close ( force : boolean , cb : ( error : Error ) => any ) : void ;
69- close ( cb : ( error : Error ) => any ) : void ;
68+ close ( force : boolean , cb : ( error : Error ) => any ) : void ;
69+ close ( cb : ( error : Error ) => any ) : void ;
7070}
7171
7272export class ConsumerGroupStream extends Readable {
7373 client : KafkaClient ;
7474 consumerGroup : ConsumerGroup ;
7575
76- constructor ( options : ConsumerGroupStreamOptions , topics : string | string [ ] ) ;
76+ constructor ( options : ConsumerGroupStreamOptions , topics : string | string [ ] ) ;
7777
78- commit ( message : Message , force ?: boolean , cb ?: ( error : any , data : any ) => any ) : void ;
78+ commit ( message : Message , force ?: boolean , cb ?: ( error : any , data : any ) => any ) : void ;
7979
80- transmitMessages ( ) : void ;
80+ transmitMessages ( ) : void ;
8181
82- close ( cb : ( ) => any ) : void ;
82+ close ( cb : ( ) => any ) : void ;
8383}
8484
85- export class ConsumerGroup {
85+ export class ConsumerGroup extends EventEmitter {
8686 generationId : number ;
8787 memberId : string ;
8888 client : KafkaClient ;
8989
90- constructor ( options : ConsumerGroupOptions , topics : string [ ] | string ) ;
90+ constructor ( options : ConsumerGroupOptions , topics : string [ ] | string ) ;
9191
92- close ( force : boolean , cb : ( error : Error ) => any ) : void ;
93- close ( cb : ( error : Error ) => any ) : void ;
92+ close ( force : boolean , cb : ( error : Error ) => any ) : void ;
93+ close ( cb : ( error : Error ) => any ) : void ;
9494
95- on ( eventName : 'message' , cb : ( message : Message ) => any ) : void ;
96- on ( eventName : 'error' | 'offsetOutOfRange' , cb : ( error : any ) => any ) : void ;
97- on ( eventName : 'rebalancing' | 'rebalanced' | 'connect' , cb : ( ) => any ) : void ;
95+ on ( eventName : 'message' , cb : ( message : Message ) => any ) : this ;
96+ on ( eventName : 'error' | 'offsetOutOfRange' , cb : ( error : any ) => any ) : this ;
97+ on ( eventName : 'rebalancing' | 'rebalanced' | 'connect' , cb : ( ) => any ) : this ;
9898
99- addTopics ( topics : string [ ] | Topic [ ] , cb ?: ( error : any , added : string [ ] | Topic [ ] ) => any ) : void ;
99+ addTopics ( topics : string [ ] | Topic [ ] , cb ?: ( error : any , added : string [ ] | Topic [ ] ) => any ) : void ;
100100
101- removeTopics ( topics : string | string [ ] , cb : ( error : any , removed : number ) => any ) : void ;
101+ removeTopics ( topics : string | string [ ] , cb : ( error : any , removed : number ) => any ) : void ;
102102
103- commit ( cb : ( error : any , data : any ) => any ) : void ;
104- commit ( force : boolean , cb : ( error : any , data : any ) => any ) : void ;
103+ commit ( cb : ( error : any , data : any ) => any ) : void ;
104+ commit ( force : boolean , cb : ( error : any , data : any ) => any ) : void ;
105105
106- sendOffsetCommitRequest ( commits : OffsetCommitRequest [ ] , cb : ( error : any , data : any ) => any ) : void ;
106+ sendOffsetCommitRequest ( commits : OffsetCommitRequest [ ] , cb : ( error : any , data : any ) => any ) : void ;
107107
108- setOffset ( topic : string , partition : number , offset : number ) : void ;
108+ setOffset ( topic : string , partition : number , offset : number ) : void ;
109109
110- pause ( ) : void ;
110+ pause ( ) : void ;
111111
112- resume ( ) : void ;
112+ resume ( ) : void ;
113113}
114114
115- export class Offset {
116- constructor ( client : KafkaClient ) ;
115+ export class Offset extends EventEmitter {
116+ constructor ( client : KafkaClient ) ;
117117
118- on ( eventName : 'ready' | 'connect' , cb : ( ) => any ) : void ;
119- on ( eventName : 'error' , cb : ( error : any ) => any ) : void ;
118+ on ( eventName : 'ready' | 'connect' , cb : ( ) => any ) : this ;
119+ on ( eventName : 'error' , cb : ( error : any ) => any ) : this ;
120120
121- fetch ( payloads : OffsetRequest [ ] , cb : ( error : any , data : any ) => any ) : void ;
121+ fetch ( payloads : OffsetRequest [ ] , cb : ( error : any , data : any ) => any ) : void ;
122122
123- commit ( groupId : string , payloads : OffsetCommitRequest [ ] , cb : ( error : any , data : any ) => any ) : void ;
123+ commit ( groupId : string , payloads : OffsetCommitRequest [ ] , cb : ( error : any , data : any ) => any ) : void ;
124124
125- fetchCommits ( groupId : string , payloads : OffsetFetchRequest [ ] , cb : ( error : any , data : any ) => any ) : void ;
125+ fetchCommits ( groupId : string , payloads : OffsetFetchRequest [ ] , cb : ( error : any , data : any ) => any ) : void ;
126126
127- fetchLatestOffsets ( topics : string [ ] , cb : ( error : any , data : any ) => any ) : void ;
127+ fetchLatestOffsets ( topics : string [ ] , cb : ( error : any , data : any ) => any ) : void ;
128128
129- fetchEarliestOffsets ( topics : string [ ] , cb : ( error : any , data : any ) => any ) : void ;
129+ fetchEarliestOffsets ( topics : string [ ] , cb : ( error : any , data : any ) => any ) : void ;
130130}
131131
132132export class KeyedMessage {
133- constructor ( key : string | Buffer , value : string | Buffer ) ;
133+ constructor ( key : string | Buffer , value : string | Buffer ) ;
134134}
135135
136136export class ProducerStream extends Writable {
137- constructor ( options ?: ProducerStreamOptions ) ;
137+ constructor ( options ?: ProducerStreamOptions ) ;
138138
139- sendPayload ( payloads : ProduceRequest [ ] , cb : ( error : any , data : any ) => any ) : void ;
139+ sendPayload ( payloads : ProduceRequest [ ] , cb : ( error : any , data : any ) => any ) : void ;
140140
141- close ( cb ?: ( ) => any ) : void ;
141+ close ( cb ?: ( ) => any ) : void ;
142142
143- _write ( message : ProduceRequest , encoding : 'buffer' | 'utf8' , cb : ( error : any , data : any ) => any ) : void ;
143+ _write ( message : ProduceRequest , encoding : 'buffer' | 'utf8' , cb : ( error : any , data : any ) => any ) : void ;
144144
145- _writev ( chunks : Chunk [ ] , cb : ( error : any , data : any ) => any ) : void ;
145+ _writev ( chunks : Chunk [ ] , cb : ( error : any , data : any ) => any ) : void ;
146+ }
147+
148+ export class Admin extends EventEmitter {
149+ constructor ( kafkaClient : KafkaClient ) ;
150+
151+ on ( eventName : 'ready' | 'connect' , cb : ( ) => any ) : this;
152+ on ( eventName : 'error' , cb : ( ) => any ) : this;
153+
154+ listGroups ( cb : ( error : any , res : any ) => any ) : void ;
155+
156+ listTopics ( cb : ( error : any , res : any ) => any ) : void ;
157+
158+ describeGroups ( consumerGroups : Array < string > , cb : ( error : any , res : any ) => any ) : void ;
159+
160+ createTopics ( topics : Array < CreateTopicRequest > , cb : ( error : any , res : any ) => any ) : void ;
161+
162+ describeConfigs ( payload : DescribeConfigsRequest , cb : ( error : any , res : any ) => any ) : void ;
146163}
147164
148165// # Interfaces
@@ -206,6 +223,7 @@ export interface ProduceRequest {
206223 key ?: string | Buffer ;
207224 partition ?: number ;
208225 attributes ?: number ;
226+ timestamp ?: number ; // defaults to Date.now() (only available with kafka v0.10+)
209227}
210228
211229export interface ConsumerOptions {
@@ -225,7 +243,7 @@ export interface CustomPartitionAssignmentProtocol {
225243 version : number ;
226244 userData : { } ;
227245
228- assign ( topicPattern : any , groupMembers : any , cb : ( error : any , result : any ) => void ) : void ;
246+ assign ( topicPattern : any , groupMembers : any , cb : ( error : any , result : any ) => void ) : void ;
229247}
230248
231249export interface ConsumerGroupOptions {
@@ -344,7 +362,21 @@ export interface ClusterMetadataResponse {
344362 } ;
345363}
346364
347- export interface MetadataResponse extends Array < BrokerMetadataResponse | ClusterMetadataResponse > {
365+ export interface MetadataResponse extends Array < BrokerMetadataResponse | ClusterMetadataResponse > {
348366 0 : BrokerMetadataResponse ;
349367 1 : ClusterMetadataResponse ;
350368}
369+
370+ export enum RESOURCE_TYPES {
371+ topic = 'topic' ,
372+ broker = 'broker'
373+ }
374+
375+ export interface DescribeConfigsRequest {
376+ resources : Array < {
377+ resourceType : RESOURCE_TYPES ,
378+ resourceName : string ,
379+ configNames : Array < string >
380+ } > ,
381+ includeSynonyms ?: boolean
382+ }
0 commit comments