forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kafka-node.d.ts
123 lines (107 loc) · 4.64 KB
/
kafka-node.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Type definitions for kafka-node 0.2.22
// Project: https://github.com/SOHU-Co/kafka-node/
// Definitions by: Daniel Imrie-Situnayake <https://github.com/dansitu/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare module 'kafka-node' {
// # Classes
export class Client {
constructor(connectionString: string, clientId: string, options?: ZKOptions);
close(callback?: Function): void;
}
export class Producer {
constructor(client: Client);
on(eventName: string, cb: () => any): void;
on(eventName: string, cb: (error: any) => any): void;
send(payloads: Array<ProduceRequest>, cb: (error: any, data: any) => any): void;
createTopics(topics: Array<string>, async: boolean, cb?: (error: any, data: any) => any): void;
}
export class HighLevelProducer {
constructor(client: Client);
on(eventName: string, cb: () => any): void;
on(eventName: string, cb: (error: any) => any): void;
send(payloads: Array<ProduceRequest>, cb: (error: any, data: any) => any): void;
createTopics(topics: Array<string>, async: boolean, cb?: (error: any, data: any) => any): void;
}
export class Consumer {
constructor(client: Client, fetchRequests: Array<OffsetFetchRequest>, options: ConsumerOptions);
on(eventName: string, cb: (message: string) => any): void;
on(eventName: string, cb: (error: any) => any): void;
addTopics(topics: Array<string>, cb: (error: any, added: boolean) => any): void;
addTopics(topics: Array<Topic>, cb: (error: any, added: boolean) => any, fromOffset: boolean): void;
removeTopics(topics: Array<string>, cb: (error: any, removed: boolean) => any): void;
commit(cb: (error: any, data: any) => any): void;
setOffset(topic: string, partition: number, offset: number): void;
pause(): void;
resume(): void;
pauseTopics(topics: Array<any> /* Array<string|Topic> */): void;
resumeTopics(topics: Array<any> /* Array<string|Topic> */): void;
close(force: boolean, cb: () => any): void;
}
export class HighLevelConsumer {
constructor(client: Client, payloads: Array<Topic>, options: ConsumerOptions);
on(eventName: string, cb: (message: string) => any): void;
on(eventName: string, cb: (error: any) => any): void;
addTopics(topics: Array<string>, cb: (error: any, added: boolean) => any): void;
addTopics(topics: Array<Topic>, cb: (error: any, added: boolean) => any, fromOffset: boolean): void;
removeTopics(topics: Array<string>, cb: (error: any, removed: boolean) => any): void;
commit(cb: (error: any, data: any) => any): void;
setOffset(topic: string, partition: number, offset: number): void;
pause(): void;
resume(): void;
pauseTopics(topics: Array<any> /* Array<string|Topic> */): void;
resumeTopics(topics: Array<any> /* Array<string|Topic> */): void;
close(force: boolean, cb: () => any): void;
}
export class Offset {
constructor(client: Client);
on(eventName: string, cb: () => any): void;
fetch(payloads: Array<OffsetRequest>, cb: (error: any, data: any) => any): void;
commit(groupId: string, payloads: Array<OffsetCommitRequest>, cb: (error: any, data: any) => any): void;
fetchCommits(groupId: string, payloads: Array<OffsetFetchRequest>, cb: (error: any, data: any) => any): void;
}
export class KeyedMessage {
constructor(key: string, message: string);
}
// # Interfaces
export interface ZKOptions {
sessionTimeout?: number;
spinDelay?: number;
retries?: number;
}
export interface ProduceRequest {
topic: string;
messages: any; // Array<string> | Array<KeyedMessage> | string | KeyedMessage
partition?: number;
attributes?: number;
}
export interface ConsumerOptions {
groupId?: string;
autoCommit?: boolean;
autoCommitIntervalMs?: number;
fetchMaxWaitMs?: number;
fetchMinBytes?: number;
fetchMaxBytes?: number;
fromOffset?: boolean;
encoding?: string;
}
export interface Topic {
topic: string;
offset?: number;
}
export interface OffsetRequest {
topic: string;
partition?: number;
time?: number;
maxNum?: number;
}
export interface OffsetCommitRequest {
topic: string;
partition?: number;
offset: number;
metadata?: string;
}
export interface OffsetFetchRequest {
topic: string;
partition?: number;
}
}