-
Notifications
You must be signed in to change notification settings - Fork 85
/
producer.d.ts
299 lines (288 loc) · 8.77 KB
/
producer.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
import * as tls from "tls";
import * as Kafka from "./kafka";
import { Client } from "./client";
export class Producer {
constructor(options?: ProducerOptions);
/**
* Initializes the client for the producer.
*
* @returns {Promise<Client>}
*
* @memberOf Producer
*/
init(): Promise<Client>;
/**
* The send can take a single message or an array of messages.
* It can have options
* @memberOf Producer
*/
send(data: Kafka.Message | Kafka.Message[], options?: SendOptions): Promise<Result[]>;
/**
* Close all connections.
*/
end(): Promise<void>;
}
export interface ProducerOptions {
/**
* requiredAcks - require acknoledgments for produce request.
* If it is 0 the server will not send any response.
* If it is 1 (default), the server will wait the data
* is written to the local log before sending a response.
* If it is -1 the server will block until the message is
* committed by all in sync replicas before sending a response.
* For any number > 1 the server will block waiting
* for this number of acknowledgements to occur
* (but the server will never wait for more acknowledgements
* than there are in-sync replicas).
*
* default: 1
*/
requiredAcks?: number;
/**
* timeout - timeout in ms for produce request
*/
timeout?: number;
/**
* clientId - ID of this client.
*
* defaults to "no-kafka-client"
*/
clientId?: string;
/**
* connectionString - comma delimited list of initial brokers list.
*
* default: "127.0.0.1:9092"
*/
connectionString?: string;
/**
* reconnectionDelay - controls optionally progressive
* delay between reconnection attempts in case of network error:
*/
reconnectionDelay?: {
/**
* min - minimum delay, used as increment value for next attempts.
*
* defaults to 1000ms
*/
min?: number;
/**
* max - maximum delay value.
*
* defaults to 1000ms
*/
max?: number;
}
/**
* partitioner - Class instance used to determine topic partition for message.
* If message already specifies a partition,
* the partitioner won't be used.
* The partitioner must inherit from Kafka.DefaultPartitioner.
*/
partitioner?: Kafka.DefaultPartitioner;
/**
* retries - controls number of attempts at delay
* between them when produce request fails
*/
retries?: number;
/**
* attempts - number of total attempts to send the message.
*
* defaults to 3
*/
attempts?: number;
/**
* delay - controls delay between retries,
* the delay is progressive and incrememented
* with each attempt with min value steps up
* to but not exceeding max value
*/
delay?: {
/**
* min - minimum delay, used as increment value for next attempts.
*
* defaults to 1000ms
*/
min?: number;
/**
* max - maximum delay value.
*
* defaults to 3000ms
*/
max?: number;
}
/**
* codec - compression codec.
*/
codec?: Kafka.COMPRESSION;
/**
* batch - control batching (grouping) of requests
*/
batch?: {
/**
* size - group messages together into single batch
* until their total size exceeds this value.
* Set to 0 to disable batching.
*
* defaults to 16384 bytes.
*/
size?: number;
/**
* maxWait - send grouped messages after this
* amount of milliseconds expire even if their
* total size doesn't exceed batch.size yet.
* Set to 0 to disable batching.
*
* defaults to 10ms.
*/
maxWait?: number;
}
/**
* asyncCompression - boolean, use asynchronouse
* compression instead of synchronous.
*
* defaults to false
*/
asyncCompression?: boolean;
/**
* To connect to Kafka with SSL endpoint enabled
* specify SSL certificate and key options to
* load cert/key from files or provide certificate/key
* directly as strings.
*
* Should match `listeners` SSL option in Kafka config
*/
ssl?: tls.ConnectionOptions;
/**
* connectionTimeout - timeout for establishing connection to Kafka in milliseconds
*
* defaults to 3000ms
*/
connectionTimeout?: number
/**
* socketTimeout - timeout for Kafka connection socket in milliseconds
*
* defaults to 0 (disabled)
*/
socketTimeout?: number
brokerRedirection?: Kafka.BrokerRedirectionFunction | Kafka.BrokerRedirectionMap;
logger?: Kafka.Logger;
}
export interface Result {
topic: string;
partition: number;
offset: number;
}
export interface SendOptions {
/**
* requiredAcks - require acknoledgments for produce request.
* If it is 0 the server will not send any response.
* If it is 1, the server will wait the data is
* written to the local log before sending a response.
* If it is -1 the server will block until the message
* is committed by all in sync replicas before sending a response.
* For any number > 1 the server will block waiting for
* this number of acknowledgements to occur
* (but the server will never wait for more acknowledgements
* than there are in-sync replicas).
* default: 1
*/
requiredAcks?: number;
/**
* timeout - timeout in ms for produce request
*/
timeout?: number;
/**
* clientId - ID of this client
* default: 'no-kafka-client'
*/
clientId?: string;
/**
* connectionString - comma delimited list of initial brokers list,
* default: '127.0.0.1:9092'
*/
connectionString?: string;
/**
* reconnectionDelay - controls optionally progressive
* delay between reconnection attempts in case of network error:
*/
reconnectionDelay?: {
/**
* min - minimum delay, used as increment value for next attempts.
* default: 1000ms
*/
min: number;
/**
* max - maximum delay value.
* default: 1000ms
*/
max: number;
}
/**
* partitioner - Class instance used to determine topic partition for message.
* If message already specifies a partition, the partitioner won't be used.
* The partitioner must inherit from Kafka.DefaultPartitioner.
* The partition method receives 3 arguments: the topic name,
* an array with topic partitions, and the message (useful to partition by key, etc.).
* partition can be sync or async (return a Promise).
*/
partitioner?: any;
/**
* retries - controls number of attempts at delay
* between them when produce request fails
*/
retries?: {
/**
* attempts - number of total attempts to send the message.
* default: 3
*/
attempts?: number;
/**
* delay - controls delay between retries,
* the delay is progressive and incrememented
* with each attempt with min value steps up to but not exceeding max value
*/
delay?: {
/**
* min - minimum delay, used as increment value for next attempts.
* default: 1000ms
*/
min?: number;
/**
* max - maximum delay value.
* default: 3000ms
*/
max?: number;
}
}
/**
* codec - compression codec, one of
* Kafka.COMPRESSION_NONE, Kafka.COMPRESSION_SNAPPY, Kafka.COMPRESSION_GZIP
*/
codec?: number; // Kafka.COMPRESSION_NONE | Kafka.COMPRESSION_SNAPPY | Kafka.COMPRESSION_GZIP;
/**
* batch - control batching (grouping) of requests
*/
batch?: {
/**
* size - group messages together into single
* batch until their total size exceeds this value.
* default: 16384 bytes.
* Set to 0 to disable batching.
*/
size?: number;
/**
* maxWait - send grouped messages after this amount of
* milliseconds expire even if their total size
* doesn't exceed batch.size yet.
* default: 10ms.
* Set to 0 to disable batching.
*/
maxWait?: number;
/**
* asyncCompression - boolean,
* use asynchronouse compression instead of synchronous.
* default: false
*/
asyncCompression?: boolean;
}
}