-
-
Notifications
You must be signed in to change notification settings - Fork 527
/
index.d.ts
1311 lines (1157 loc) · 34.1 KB
/
index.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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/// <reference types="node" />
import * as tls from 'tls'
import * as net from 'net'
type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never }
type XOR<T, U> = T | U extends object ? (Without<T, U> & U) | (Without<U, T> & T) : T | U
export class Kafka {
constructor(config: KafkaConfig)
producer(config?: ProducerConfig): Producer
consumer(config: ConsumerConfig): Consumer
admin(config?: AdminConfig): Admin
logger(): Logger
}
export type BrokersFunction = () => string[] | Promise<string[]>
type SaslAuthenticationRequest = {
encode: () => Buffer | Promise<Buffer>
}
type SaslAuthenticationResponse<ParseResult> = {
decode: (rawResponse: Buffer) => Buffer | Promise<Buffer>
parse: (data: Buffer) => ParseResult
}
export type Authenticator = {
authenticate: () => Promise<void>
}
export type SaslAuthenticateArgs<ParseResult> = {
request: SaslAuthenticationRequest
response?: SaslAuthenticationResponse<ParseResult>
}
export type AuthenticationProviderArgs = {
host: string
port: number
logger: Logger
saslAuthenticate: <ParseResult>(
args: SaslAuthenticateArgs<ParseResult>
) => Promise<ParseResult | void>
}
export type Mechanism = {
mechanism: string
authenticationProvider: (args: AuthenticationProviderArgs) => Authenticator
}
export interface KafkaConfig {
brokers: string[] | BrokersFunction
ssl?: tls.ConnectionOptions | boolean
sasl?: SASLOptions | Mechanism
clientId?: string
connectionTimeout?: number
authenticationTimeout?: number
reauthenticationThreshold?: number
requestTimeout?: number
enforceRequestTimeout?: boolean
retry?: RetryOptions
socketFactory?: ISocketFactory
logLevel?: logLevel
logCreator?: logCreator
}
export interface ISocketFactoryArgs {
host: string
port: number
ssl: tls.ConnectionOptions
onConnect: () => void
}
export type ISocketFactory = (args: ISocketFactoryArgs) => net.Socket
export interface OauthbearerProviderResponse {
value: string
}
type SASLMechanismOptionsMap = {
plain: { username: string; password: string }
'scram-sha-256': { username: string; password: string }
'scram-sha-512': { username: string; password: string }
aws: {
authorizationIdentity: string
accessKeyId: string
secretAccessKey: string
sessionToken?: string
}
oauthbearer: { oauthBearerProvider: () => Promise<OauthbearerProviderResponse> }
}
export type SASLMechanism = keyof SASLMechanismOptionsMap
type SASLMechanismOptions<T> = T extends SASLMechanism
? { mechanism: T } & SASLMechanismOptionsMap[T]
: never
export type SASLOptions = SASLMechanismOptions<SASLMechanism>
export interface ProducerConfig {
createPartitioner?: ICustomPartitioner
retry?: RetryOptions
metadataMaxAge?: number
allowAutoTopicCreation?: boolean
idempotent?: boolean
transactionalId?: string
transactionTimeout?: number
maxInFlightRequests?: number
}
export interface Message {
key?: Buffer | string | null
value: Buffer | string | null
partition?: number
headers?: IHeaders
timestamp?: string
}
export interface PartitionerArgs {
topic: string
partitionMetadata: PartitionMetadata[]
message: Message
}
export type ICustomPartitioner = () => (args: PartitionerArgs) => number
export type DefaultPartitioner = ICustomPartitioner
export type LegacyPartitioner = ICustomPartitioner
export const Partitioners: {
DefaultPartitioner: DefaultPartitioner
LegacyPartitioner: LegacyPartitioner
/**
* @deprecated Use DefaultPartitioner instead
*
* The JavaCompatiblePartitioner was renamed DefaultPartitioner
* and made to be the default in 2.0.0.
*/
JavaCompatiblePartitioner: DefaultPartitioner
}
export type PartitionMetadata = {
partitionErrorCode: number
partitionId: number
leader: number
replicas: number[]
isr: number[]
offlineReplicas?: number[]
}
export interface IHeaders {
[key: string]: Buffer | string | (Buffer | string)[] | undefined
}
export interface ConsumerConfig {
groupId: string
partitionAssigners?: PartitionAssigner[]
metadataMaxAge?: number
sessionTimeout?: number
rebalanceTimeout?: number
heartbeatInterval?: number
maxBytesPerPartition?: number
minBytes?: number
maxBytes?: number
maxWaitTimeInMs?: number
retry?: RetryOptions & { restartOnFailure?: (err: Error) => Promise<boolean> }
allowAutoTopicCreation?: boolean
maxInFlightRequests?: number
readUncommitted?: boolean
rackId?: string
}
export type PartitionAssigner = (config: {
cluster: Cluster
groupId: string
logger: Logger
}) => Assigner
export interface CoordinatorMetadata {
errorCode: number
coordinator: {
nodeId: number
host: string
port: number
}
}
export type Cluster = {
getNodeIds(): number[]
metadata(): Promise<BrokerMetadata>
removeBroker(options: { host: string; port: number }): void
addMultipleTargetTopics(topics: string[]): Promise<void>
isConnected(): boolean
connect(): Promise<void>
disconnect(): Promise<void>
refreshMetadata(): Promise<void>
refreshMetadataIfNecessary(): Promise<void>
addTargetTopic(topic: string): Promise<void>
findBroker(node: { nodeId: string }): Promise<Broker>
findControllerBroker(): Promise<Broker>
findTopicPartitionMetadata(topic: string): PartitionMetadata[]
findLeaderForPartitions(topic: string, partitions: number[]): { [leader: string]: number[] }
findGroupCoordinator(group: { groupId: string }): Promise<Broker>
findGroupCoordinatorMetadata(group: { groupId: string }): Promise<CoordinatorMetadata>
defaultOffset(config: { fromBeginning: boolean }): number
fetchTopicsOffset(
topics: Array<
{
topic: string
partitions: Array<{ partition: number }>
} & XOR<{ fromBeginning: boolean }, { fromTimestamp: number }>
>
): Promise<TopicOffsets[]>
}
export type Assignment = { [topic: string]: number[] }
export type GroupMember = { memberId: string; memberMetadata: Buffer }
export type GroupMemberAssignment = { memberId: string; memberAssignment: Buffer }
export type GroupState = { name: string; metadata: Buffer }
export type Assigner = {
name: string
version: number
assign(group: { members: GroupMember[]; topics: string[] }): Promise<GroupMemberAssignment[]>
protocol(subscription: { topics: string[] }): GroupState
}
export interface RetryOptions {
maxRetryTime?: number
initialRetryTime?: number
factor?: number
multiplier?: number
retries?: number
restartOnFailure?: (e: Error) => Promise<boolean>
}
export interface AdminConfig {
retry?: RetryOptions
}
export interface ITopicConfig {
topic: string
numPartitions?: number
replicationFactor?: number
replicaAssignment?: ReplicaAssignment[]
configEntries?: IResourceConfigEntry[]
}
export interface ITopicPartitionConfig {
topic: string
count: number
assignments?: Array<Array<number>>
}
export interface ITopicMetadata {
name: string
partitions: PartitionMetadata[]
}
export interface ReplicaAssignment {
partition: number
replicas: Array<number>
}
export interface PartitionReassignment {
topic: string
partitionAssignment: Array<ReplicaAssignment>
}
export enum AclResourceTypes {
UNKNOWN = 0,
ANY = 1,
TOPIC = 2,
GROUP = 3,
CLUSTER = 4,
TRANSACTIONAL_ID = 5,
DELEGATION_TOKEN = 6,
}
export enum ConfigResourceTypes {
UNKNOWN = 0,
TOPIC = 2,
BROKER = 4,
BROKER_LOGGER = 8,
}
export enum ConfigSource {
UNKNOWN = 0,
TOPIC_CONFIG = 1,
DYNAMIC_BROKER_CONFIG = 2,
DYNAMIC_DEFAULT_BROKER_CONFIG = 3,
STATIC_BROKER_CONFIG = 4,
DEFAULT_CONFIG = 5,
DYNAMIC_BROKER_LOGGER_CONFIG = 6,
}
export enum AclPermissionTypes {
UNKNOWN = 0,
ANY = 1,
DENY = 2,
ALLOW = 3,
}
export enum AclOperationTypes {
UNKNOWN = 0,
ANY = 1,
ALL = 2,
READ = 3,
WRITE = 4,
CREATE = 5,
DELETE = 6,
ALTER = 7,
DESCRIBE = 8,
CLUSTER_ACTION = 9,
DESCRIBE_CONFIGS = 10,
ALTER_CONFIGS = 11,
IDEMPOTENT_WRITE = 12,
}
export enum ResourcePatternTypes {
UNKNOWN = 0,
ANY = 1,
MATCH = 2,
LITERAL = 3,
PREFIXED = 4,
}
export interface ResourceConfigQuery {
type: ConfigResourceTypes
name: string
configNames?: string[]
}
export interface ConfigEntries {
configName: string
configValue: string
isDefault: boolean
configSource: ConfigSource
isSensitive: boolean
readOnly: boolean
configSynonyms: ConfigSynonyms[]
}
export interface ConfigSynonyms {
configName: string
configValue: string
configSource: ConfigSource
}
export interface DescribeConfigResponse {
resources: {
configEntries: ConfigEntries[]
errorCode: number
errorMessage: string
resourceName: string
resourceType: ConfigResourceTypes
}[]
throttleTime: number
}
export interface IResourceConfigEntry {
name: string
value: string
}
export interface IResourceConfig {
type: ConfigResourceTypes
name: string
configEntries: IResourceConfigEntry[]
}
type ValueOf<T> = T[keyof T]
export type AdminEvents = {
CONNECT: 'admin.connect'
DISCONNECT: 'admin.disconnect'
REQUEST: 'admin.network.request'
REQUEST_TIMEOUT: 'admin.network.request_timeout'
REQUEST_QUEUE_SIZE: 'admin.network.request_queue_size'
}
export interface InstrumentationEvent<T> {
id: string
type: string
timestamp: number
payload: T
}
export type RemoveInstrumentationEventListener<T> = () => void
export type ConnectEvent = InstrumentationEvent<null>
export type DisconnectEvent = InstrumentationEvent<null>
export type RequestEvent = InstrumentationEvent<{
apiKey: number
apiName: string
apiVersion: number
broker: string
clientId: string
correlationId: number
createdAt: number
duration: number
pendingDuration: number
sentAt: number
size: number
}>
export type RequestTimeoutEvent = InstrumentationEvent<{
apiKey: number
apiName: string
apiVersion: number
broker: string
clientId: string
correlationId: number
createdAt: number
pendingDuration: number
sentAt: number
}>
export type RequestQueueSizeEvent = InstrumentationEvent<{
broker: string
clientId: string
queueSize: number
}>
export type SeekEntry = PartitionOffset
export type FetchOffsetsPartition = PartitionOffset & { metadata: string | null }
export interface Acl {
principal: string
host: string
operation: AclOperationTypes
permissionType: AclPermissionTypes
}
export interface AclResource {
resourceType: AclResourceTypes
resourceName: string
resourcePatternType: ResourcePatternTypes
}
export type AclEntry = Acl & AclResource
export type DescribeAclResource = AclResource & {
acls: Acl[]
}
export interface DescribeAclResponse {
throttleTime: number
errorCode: number
errorMessage?: string
resources: DescribeAclResource[]
}
export interface AclFilter {
resourceType: AclResourceTypes
resourceName?: string
resourcePatternType: ResourcePatternTypes
principal?: string
host?: string
operation: AclOperationTypes
permissionType: AclPermissionTypes
}
export interface MatchingAcl {
errorCode: number
errorMessage?: string
resourceType: AclResourceTypes
resourceName: string
resourcePatternType: ResourcePatternTypes
principal: string
host: string
operation: AclOperationTypes
permissionType: AclPermissionTypes
}
export interface DeleteAclFilterResponses {
errorCode: number
errorMessage?: string
matchingAcls: MatchingAcl[]
}
export interface DeleteAclResponse {
throttleTime: number
filterResponses: DeleteAclFilterResponses[]
}
export interface ListPartitionReassignmentsResponse {
topics: OngoingTopicReassignment[]
}
export interface OngoingTopicReassignment {
topic: string
partitions: OngoingPartitionReassignment[]
}
export interface OngoingPartitionReassignment {
partitionIndex: number
replicas: number[]
addingReplicas?: number[]
removingReplicas?: number[]
}
export type Admin = {
connect(): Promise<void>
disconnect(): Promise<void>
listTopics(): Promise<string[]>
createTopics(options: {
validateOnly?: boolean
waitForLeaders?: boolean
timeout?: number
topics: ITopicConfig[]
}): Promise<boolean>
deleteTopics(options: { topics: string[]; timeout?: number }): Promise<void>
createPartitions(options: {
validateOnly?: boolean
timeout?: number
topicPartitions: ITopicPartitionConfig[]
}): Promise<boolean>
fetchTopicMetadata(options?: { topics: string[] }): Promise<{ topics: Array<ITopicMetadata> }>
fetchOffsets(options: {
groupId: string
topics?: string[]
resolveOffsets?: boolean
}): Promise<Array<{ topic: string; partitions: FetchOffsetsPartition[] }>>
fetchTopicOffsets(topic: string): Promise<Array<SeekEntry & { high: string; low: string }>>
fetchTopicOffsetsByTimestamp(topic: string, timestamp?: number): Promise<Array<SeekEntry>>
describeCluster(): Promise<{
brokers: Array<{ nodeId: number; host: string; port: number }>
controller: number | null
clusterId: string
}>
setOffsets(options: { groupId: string; topic: string; partitions: SeekEntry[] }): Promise<void>
resetOffsets(options: { groupId: string; topic: string; earliest: boolean }): Promise<void>
describeConfigs(configs: {
resources: ResourceConfigQuery[]
includeSynonyms: boolean
}): Promise<DescribeConfigResponse>
alterConfigs(configs: { validateOnly: boolean; resources: IResourceConfig[] }): Promise<any>
listGroups(): Promise<{ groups: GroupOverview[] }>
deleteGroups(groupIds: string[]): Promise<DeleteGroupsResult[]>
describeGroups(groupIds: string[]): Promise<GroupDescriptions>
describeAcls(options: AclFilter): Promise<DescribeAclResponse>
deleteAcls(options: { filters: AclFilter[] }): Promise<DeleteAclResponse>
createAcls(options: { acl: AclEntry[] }): Promise<boolean>
deleteTopicRecords(options: { topic: string; partitions: SeekEntry[] }): Promise<void>
alterPartitionReassignments(request: {
topics: PartitionReassignment[]
timeout?: number
}): Promise<void>
listPartitionReassignments(request: {
topics?: TopicPartitions[]
timeout?: number
}): Promise<ListPartitionReassignmentsResponse>
logger(): Logger
on(
eventName: AdminEvents['CONNECT'],
listener: (event: ConnectEvent) => void
): RemoveInstrumentationEventListener<typeof eventName>
on(
eventName: AdminEvents['DISCONNECT'],
listener: (event: DisconnectEvent) => void
): RemoveInstrumentationEventListener<typeof eventName>
on(
eventName: AdminEvents['REQUEST'],
listener: (event: RequestEvent) => void
): RemoveInstrumentationEventListener<typeof eventName>
on(
eventName: AdminEvents['REQUEST_QUEUE_SIZE'],
listener: (event: RequestQueueSizeEvent) => void
): RemoveInstrumentationEventListener<typeof eventName>
on(
eventName: AdminEvents['REQUEST_TIMEOUT'],
listener: (event: RequestTimeoutEvent) => void
): RemoveInstrumentationEventListener<typeof eventName>
on(
eventName: ValueOf<AdminEvents>,
listener: (event: InstrumentationEvent<any>) => void
): RemoveInstrumentationEventListener<typeof eventName>
readonly events: AdminEvents
}
export const PartitionAssigners: { roundRobin: PartitionAssigner }
export interface ISerializer<T> {
encode(value: T): Buffer
decode(buffer: Buffer): T | null
}
export type MemberMetadata = {
version: number
topics: string[]
userData: Buffer
}
export type MemberAssignment = {
version: number
assignment: Assignment
userData: Buffer
}
export const AssignerProtocol: {
MemberMetadata: ISerializer<MemberMetadata>
MemberAssignment: ISerializer<MemberAssignment>
}
export enum logLevel {
NOTHING = 0,
ERROR = 1,
WARN = 2,
INFO = 4,
DEBUG = 5,
}
export interface LogEntry {
namespace: string
level: logLevel
label: string
log: LoggerEntryContent
}
export interface LoggerEntryContent {
readonly timestamp: string
readonly message: string
[key: string]: any
}
export type logCreator = (logLevel: logLevel) => (entry: LogEntry) => void
export type Logger = {
info: (message: string, extra?: object) => void
error: (message: string, extra?: object) => void
warn: (message: string, extra?: object) => void
debug: (message: string, extra?: object) => void
namespace: (namespace: string, logLevel?: logLevel) => Logger
setLogLevel: (logLevel: logLevel) => void
}
export interface BrokerMetadata {
brokers: Array<{ nodeId: number; host: string; port: number; rack?: string }>
topicMetadata: Array<{
topicErrorCode: number
topic: string
partitionMetadata: PartitionMetadata[]
}>
}
export interface ApiVersions {
[apiKey: number]: {
minVersion: number
maxVersion: number
}
}
export type Broker = {
isConnected(): boolean
connect(): Promise<void>
disconnect(): Promise<void>
apiVersions(): Promise<ApiVersions>
metadata(topics: string[]): Promise<BrokerMetadata>
describeGroups: (options: { groupIds: string[] }) => Promise<any>
offsetCommit(request: {
groupId: string
groupGenerationId: number
memberId: string
retentionTime?: number
topics: TopicOffsets[]
}): Promise<any>
offsetFetch(request: {
groupId: string
topics: TopicOffsets[]
}): Promise<{
responses: TopicOffsets[]
}>
fetch(request: {
replicaId?: number
isolationLevel?: number
maxWaitTime?: number
minBytes?: number
maxBytes?: number
topics: Array<{
topic: string
partitions: Array<{ partition: number; fetchOffset: string; maxBytes: number }>
}>
rackId?: string
}): Promise<any>
produce(request: {
topicData: Array<{
topic: string
partitions: Array<{ partition: number; firstSequence?: number; messages: Message[] }>
}>
transactionalId?: string
producerId?: number
producerEpoch?: number
acks?: number
timeout?: number
compression?: CompressionTypes
}): Promise<any>
alterPartitionReassignments(request: {
topics: PartitionReassignment[]
timeout?: number
}): Promise<any>
listPartitionReassignments(request: {
topics?: TopicPartitions[]
timeout?: number
}): Promise<ListPartitionReassignmentsResponse>
}
interface MessageSetEntry {
key: Buffer | null
value: Buffer | null
timestamp: string
attributes: number
offset: string
size: number
headers?: never
}
interface RecordBatchEntry {
key: Buffer | null
value: Buffer | null
timestamp: string
attributes: number
offset: string
headers: IHeaders
size?: never
}
export type KafkaMessage = MessageSetEntry | RecordBatchEntry
export interface ProducerRecord {
topic: string
messages: Message[]
acks?: number
timeout?: number
compression?: CompressionTypes
}
export type RecordMetadata = {
topicName: string
partition: number
errorCode: number
offset?: string
timestamp?: string
baseOffset?: string
logAppendTime?: string
logStartOffset?: string
}
export interface TopicMessages {
topic: string
messages: Message[]
}
export interface ProducerBatch {
acks?: number
timeout?: number
compression?: CompressionTypes
topicMessages?: TopicMessages[]
}
export interface PartitionOffset {
partition: number
offset: string
}
export interface TopicOffsets {
topic: string
partitions: PartitionOffset[]
}
export interface Offsets {
topics: TopicOffsets[]
}
type Sender = {
send(record: ProducerRecord): Promise<RecordMetadata[]>
sendBatch(batch: ProducerBatch): Promise<RecordMetadata[]>
}
export type ProducerEvents = {
CONNECT: 'producer.connect'
DISCONNECT: 'producer.disconnect'
REQUEST: 'producer.network.request'
REQUEST_TIMEOUT: 'producer.network.request_timeout'
REQUEST_QUEUE_SIZE: 'producer.network.request_queue_size'
}
export type Producer = Sender & {
connect(): Promise<void>
disconnect(): Promise<void>
isIdempotent(): boolean
readonly events: ProducerEvents
on(
eventName: ProducerEvents['CONNECT'],
listener: (event: ConnectEvent) => void
): RemoveInstrumentationEventListener<typeof eventName>
on(
eventName: ProducerEvents['DISCONNECT'],
listener: (event: DisconnectEvent) => void
): RemoveInstrumentationEventListener<typeof eventName>
on(
eventName: ProducerEvents['REQUEST'],
listener: (event: RequestEvent) => void
): RemoveInstrumentationEventListener<typeof eventName>
on(
eventName: ProducerEvents['REQUEST_QUEUE_SIZE'],
listener: (event: RequestQueueSizeEvent) => void
): RemoveInstrumentationEventListener<typeof eventName>
on(
eventName: ProducerEvents['REQUEST_TIMEOUT'],
listener: (event: RequestTimeoutEvent) => void
): RemoveInstrumentationEventListener<typeof eventName>
on(
eventName: ValueOf<ProducerEvents>,
listener: (event: InstrumentationEvent<any>) => void
): RemoveInstrumentationEventListener<typeof eventName>
transaction(): Promise<Transaction>
logger(): Logger
}
export type Transaction = Sender & {
sendOffsets(offsets: Offsets & { consumerGroupId: string }): Promise<void>
commit(): Promise<void>
abort(): Promise<void>
isActive(): boolean
}
export type ConsumerGroup = {
groupId: string
generationId: number
memberId: string
coordinator: Broker
}
export type MemberDescription = {
clientHost: string
clientId: string
memberId: string
memberAssignment: Buffer
memberMetadata: Buffer
}
// See https://github.com/apache/kafka/blob/2.4.0/clients/src/main/java/org/apache/kafka/common/ConsumerGroupState.java#L25
export type ConsumerGroupState =
| 'Unknown'
| 'PreparingRebalance'
| 'CompletingRebalance'
| 'Stable'
| 'Dead'
| 'Empty'
export type GroupDescription = {
groupId: string
members: MemberDescription[]
protocol: string
protocolType: string
state: ConsumerGroupState
}
export type GroupDescriptions = {
groups: GroupDescription[]
}
export type TopicPartitions = { topic: string; partitions: number[] }
export type TopicPartition = {
topic: string
partition: number
}
export type TopicPartitionOffset = TopicPartition & {
offset: string
}
export type TopicPartitionOffsetAndMetadata = TopicPartitionOffset & {
metadata?: string | null
}
export type Batch = {
topic: string
partition: number
highWatermark: string
messages: KafkaMessage[]
isEmpty(): boolean
firstOffset(): string | null
lastOffset(): string
offsetLag(): string
offsetLagLow(): string
}
export type GroupOverview = {
groupId: string
protocolType: string
}
export type DeleteGroupsResult = {
groupId: string
errorCode?: number
error?: KafkaJSProtocolError
}
export type ConsumerEvents = {
HEARTBEAT: 'consumer.heartbeat'
COMMIT_OFFSETS: 'consumer.commit_offsets'
GROUP_JOIN: 'consumer.group_join'
FETCH_START: 'consumer.fetch_start'
FETCH: 'consumer.fetch'
START_BATCH_PROCESS: 'consumer.start_batch_process'
END_BATCH_PROCESS: 'consumer.end_batch_process'
CONNECT: 'consumer.connect'
DISCONNECT: 'consumer.disconnect'
STOP: 'consumer.stop'
CRASH: 'consumer.crash'
REBALANCING: 'consumer.rebalancing'
RECEIVED_UNSUBSCRIBED_TOPICS: 'consumer.received_unsubscribed_topics'
REQUEST: 'consumer.network.request'
REQUEST_TIMEOUT: 'consumer.network.request_timeout'
REQUEST_QUEUE_SIZE: 'consumer.network.request_queue_size'
}
export type ConsumerHeartbeatEvent = InstrumentationEvent<{
groupId: string
memberId: string
groupGenerationId: number
}>
export type ConsumerCommitOffsetsEvent = InstrumentationEvent<{
groupId: string
memberId: string
groupGenerationId: number
topics: TopicOffsets[]
}>
export interface IMemberAssignment {
[key: string]: number[]
}
export type ConsumerGroupJoinEvent = InstrumentationEvent<{
duration: number
groupId: string
isLeader: boolean
leaderId: string
groupProtocol: string
memberId: string
memberAssignment: IMemberAssignment
}>
export type ConsumerFetchStartEvent = InstrumentationEvent<{ nodeId: number }>
export type ConsumerFetchEvent = InstrumentationEvent<{
numberOfBatches: number
duration: number
nodeId: number
}>
interface IBatchProcessEvent {
topic: string
partition: number
highWatermark: string
offsetLag: string
offsetLagLow: string
batchSize: number
firstOffset: string
lastOffset: string
}
export type ConsumerStartBatchProcessEvent = InstrumentationEvent<IBatchProcessEvent>
export type ConsumerEndBatchProcessEvent = InstrumentationEvent<
IBatchProcessEvent & { duration: number }
>
export type ConsumerCrashEvent = InstrumentationEvent<{
error: Error
groupId: string
restart: boolean
}>
export type ConsumerRebalancingEvent = InstrumentationEvent<{
groupId: string
memberId: string
}>
export type ConsumerReceivedUnsubcribedTopicsEvent = InstrumentationEvent<{
groupId: string
generationId: number
memberId: string
assignedTopics: string[]
topicsSubscribed: string[]
topicsNotSubscribed: string[]
}>
export interface OffsetsByTopicPartition {
topics: TopicOffsets[]
}
export interface EachMessagePayload {
topic: string
partition: number
message: KafkaMessage
heartbeat(): Promise<void>
pause(): () => void
}
export interface EachBatchPayload {
batch: Batch
resolveOffset(offset: string): void
heartbeat(): Promise<void>
pause(): () => void
commitOffsetsIfNecessary(offsets?: Offsets): Promise<void>
uncommittedOffsets(): OffsetsByTopicPartition
isRunning(): boolean
isStale(): boolean
}