1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | import * as net from 'net';
|
10 | import * as tls from 'tls';
|
11 | declare type Without<T, U> = {
|
12 | [P in Exclude<keyof T, keyof U>]?: never;
|
13 | };
|
14 | declare type XOR<T, U> = T | U extends object ? (Without<T, U> & U) | (Without<U, T> & T) : T | U;
|
15 | export declare class Kafka {
|
16 | constructor(config: KafkaConfig);
|
17 | producer(config?: ProducerConfig): Producer;
|
18 | consumer(config?: ConsumerConfig): Consumer;
|
19 | admin(config?: AdminConfig): Admin;
|
20 | logger(): Logger;
|
21 | }
|
22 | export declare type BrokersFunction = () => string[] | Promise<string[]>;
|
23 | export interface KafkaConfig {
|
24 | brokers: string[] | BrokersFunction;
|
25 | ssl?: tls.ConnectionOptions | boolean;
|
26 | sasl?: SASLOptions;
|
27 | clientId?: string;
|
28 | connectionTimeout?: number;
|
29 | authenticationTimeout?: number;
|
30 | reauthenticationThreshold?: number;
|
31 | requestTimeout?: number;
|
32 | enforceRequestTimeout?: boolean;
|
33 | retry?: RetryOptions;
|
34 | socketFactory?: ISocketFactory;
|
35 | logLevel?: logLevel;
|
36 | logCreator?: logCreator;
|
37 | }
|
38 | export interface ISocketFactoryArgs {
|
39 | host: string;
|
40 | port: number;
|
41 | ssl: tls.ConnectionOptions;
|
42 | onConnect: () => void;
|
43 | }
|
44 | export declare type ISocketFactory = (args: ISocketFactoryArgs) => net.Socket;
|
45 | export interface OauthbearerProviderResponse {
|
46 | value: string;
|
47 | }
|
48 | declare type SASLMechanismOptionsMap = {
|
49 | plain: {
|
50 | username: string;
|
51 | password: string;
|
52 | };
|
53 | 'scram-sha-256': {
|
54 | username: string;
|
55 | password: string;
|
56 | };
|
57 | 'scram-sha-512': {
|
58 | username: string;
|
59 | password: string;
|
60 | };
|
61 | aws: {
|
62 | authorizationIdentity: string;
|
63 | accessKeyId: string;
|
64 | secretAccessKey: string;
|
65 | sessionToken?: string;
|
66 | };
|
67 | oauthbearer: {
|
68 | oauthBearerProvider: () => Promise<OauthbearerProviderResponse>;
|
69 | };
|
70 | };
|
71 | export declare type SASLMechanism = keyof SASLMechanismOptionsMap;
|
72 | declare type SASLMechanismOptions<T> = T extends SASLMechanism ? {
|
73 | mechanism: T;
|
74 | } & SASLMechanismOptionsMap[T] : never;
|
75 | export declare type SASLOptions = SASLMechanismOptions<SASLMechanism>;
|
76 | export interface ProducerConfig {
|
77 | createPartitioner?: ICustomPartitioner;
|
78 | retry?: RetryOptions;
|
79 | metadataMaxAge?: number;
|
80 | allowAutoTopicCreation?: boolean;
|
81 | idempotent?: boolean;
|
82 | transactionalId?: string;
|
83 | transactionTimeout?: number;
|
84 | maxInFlightRequests?: number;
|
85 | }
|
86 | export interface Message {
|
87 | key?: Buffer | string | null;
|
88 | value: Buffer | string | null;
|
89 | partition?: number;
|
90 | headers?: IHeaders;
|
91 | timestamp?: string;
|
92 | }
|
93 | export interface PartitionerArgs {
|
94 | topic: string;
|
95 | partitionMetadata: PartitionMetadata[];
|
96 | message: Message;
|
97 | }
|
98 | export declare type ICustomPartitioner = () => (args: PartitionerArgs) => number;
|
99 | export declare type DefaultPartitioner = ICustomPartitioner;
|
100 | export declare type JavaCompatiblePartitioner = ICustomPartitioner;
|
101 | export declare let Partitioners: {
|
102 | DefaultPartitioner: DefaultPartitioner;
|
103 | JavaCompatiblePartitioner: JavaCompatiblePartitioner;
|
104 | };
|
105 | export declare type PartitionMetadata = {
|
106 | partitionErrorCode: number;
|
107 | partitionId: number;
|
108 | leader: number;
|
109 | replicas: number[];
|
110 | isr: number[];
|
111 | offlineReplicas?: number[];
|
112 | };
|
113 | export interface IHeaders {
|
114 | [key: string]: Buffer | string | undefined;
|
115 | }
|
116 | export interface ConsumerConfig {
|
117 | groupId: string;
|
118 | partitionAssigners?: PartitionAssigner[];
|
119 | metadataMaxAge?: number;
|
120 | sessionTimeout?: number;
|
121 | rebalanceTimeout?: number;
|
122 | heartbeatInterval?: number;
|
123 | maxBytesPerPartition?: number;
|
124 | minBytes?: number;
|
125 | maxBytes?: number;
|
126 | maxWaitTimeInMs?: number;
|
127 | retry?: RetryOptions & {
|
128 | restartOnFailure?: (err: Error) => Promise<boolean>;
|
129 | };
|
130 | allowAutoTopicCreation?: boolean;
|
131 | maxInFlightRequests?: number;
|
132 | readUncommitted?: boolean;
|
133 | rackId?: string;
|
134 | }
|
135 | export declare type PartitionAssigner = (config: {
|
136 | cluster: Cluster;
|
137 | }) => Assigner;
|
138 | export interface CoordinatorMetadata {
|
139 | errorCode: number;
|
140 | coordinator: {
|
141 | nodeId: number;
|
142 | host: string;
|
143 | port: number;
|
144 | };
|
145 | }
|
146 | export declare type Cluster = {
|
147 | isConnected(): boolean;
|
148 | connect(): Promise<void>;
|
149 | disconnect(): Promise<void>;
|
150 | refreshMetadata(): Promise<void>;
|
151 | refreshMetadataIfNecessary(): Promise<void>;
|
152 | addTargetTopic(topic: string): Promise<void>;
|
153 | findBroker(node: {
|
154 | nodeId: string;
|
155 | }): Promise<Broker>;
|
156 | findControllerBroker(): Promise<Broker>;
|
157 | findTopicPartitionMetadata(topic: string): PartitionMetadata[];
|
158 | findLeaderForPartitions(topic: string, partitions: number[]): {
|
159 | [leader: string]: number[];
|
160 | };
|
161 | findGroupCoordinator(group: {
|
162 | groupId: string;
|
163 | }): Promise<Broker>;
|
164 | findGroupCoordinatorMetadata(group: {
|
165 | groupId: string;
|
166 | }): Promise<CoordinatorMetadata>;
|
167 | defaultOffset(config: {
|
168 | fromBeginning: boolean;
|
169 | }): number;
|
170 | fetchTopicsOffset(topics: Array<{
|
171 | topic: string;
|
172 | partitions: Array<{
|
173 | partition: number;
|
174 | }>;
|
175 | } & XOR<{
|
176 | fromBeginning: boolean;
|
177 | }, {
|
178 | fromTimestamp: number;
|
179 | }>>): Promise<{
|
180 | topic: string;
|
181 | partitions: Array<{
|
182 | partition: number;
|
183 | offset: string;
|
184 | }>;
|
185 | }>;
|
186 | };
|
187 | export declare type Assignment = {
|
188 | [topic: string]: number[];
|
189 | };
|
190 | export declare type GroupMember = {
|
191 | memberId: string;
|
192 | memberMetadata: Buffer;
|
193 | };
|
194 | export declare type GroupMemberAssignment = {
|
195 | memberId: string;
|
196 | memberAssignment: Buffer;
|
197 | };
|
198 | export declare type GroupState = {
|
199 | name: string;
|
200 | metadata: Buffer;
|
201 | };
|
202 | export declare type Assigner = {
|
203 | name: string;
|
204 | version: number;
|
205 | assign(group: {
|
206 | members: GroupMember[];
|
207 | topics: string[];
|
208 | }): Promise<GroupMemberAssignment[]>;
|
209 | protocol(subscription: {
|
210 | topics: string[];
|
211 | }): GroupState;
|
212 | };
|
213 | export interface RetryOptions {
|
214 | maxRetryTime?: number;
|
215 | initialRetryTime?: number;
|
216 | factor?: number;
|
217 | multiplier?: number;
|
218 | retries?: number;
|
219 | }
|
220 | export interface AdminConfig {
|
221 | retry?: RetryOptions;
|
222 | }
|
223 | export interface ITopicConfig {
|
224 | topic: string;
|
225 | numPartitions?: number;
|
226 | replicationFactor?: number;
|
227 | replicaAssignment?: object[];
|
228 | configEntries?: object[];
|
229 | }
|
230 | export interface ITopicPartitionConfig {
|
231 | topic: string;
|
232 | count: number;
|
233 | assignments?: Array<Array<number>>;
|
234 | }
|
235 | export interface ITopicMetadata {
|
236 | name: string;
|
237 | partitions: PartitionMetadata[];
|
238 | }
|
239 |
|
240 |
|
241 |
|
242 |
|
243 | export declare enum ResourceTypes {
|
244 | UNKNOWN = 0,
|
245 | ANY = 1,
|
246 | TOPIC = 2,
|
247 | GROUP = 3,
|
248 | CLUSTER = 4,
|
249 | TRANSACTIONAL_ID = 5,
|
250 | DELEGATION_TOKEN = 6
|
251 | }
|
252 | export declare enum AclResourceTypes {
|
253 | UNKNOWN = 0,
|
254 | ANY = 1,
|
255 | TOPIC = 2,
|
256 | GROUP = 3,
|
257 | CLUSTER = 4,
|
258 | TRANSACTIONAL_ID = 5,
|
259 | DELEGATION_TOKEN = 6
|
260 | }
|
261 | export declare enum ConfigResourceTypes {
|
262 | UNKNOWN = 0,
|
263 | TOPIC = 2,
|
264 | BROKER = 4,
|
265 | BROKER_LOGGER = 8
|
266 | }
|
267 | export declare enum AclPermissionTypes {
|
268 | UNKNOWN = 0,
|
269 | ANY = 1,
|
270 | DENY = 2,
|
271 | ALLOW = 3
|
272 | }
|
273 | export declare enum AclOperationTypes {
|
274 | UNKNOWN = 0,
|
275 | ANY = 1,
|
276 | ALL = 2,
|
277 | READ = 3,
|
278 | WRITE = 4,
|
279 | CREATE = 5,
|
280 | DELETE = 6,
|
281 | ALTER = 7,
|
282 | DESCRIBE = 8,
|
283 | CLUSTER_ACTION = 9,
|
284 | DESCRIBE_CONFIGS = 10,
|
285 | ALTER_CONFIGS = 11,
|
286 | IDEMPOTENT_WRITE = 12
|
287 | }
|
288 | export declare enum ResourcePatternTypes {
|
289 | UNKNOWN = 0,
|
290 | ANY = 1,
|
291 | MATCH = 2,
|
292 | LITERAL = 3,
|
293 | PREFIXED = 4
|
294 | }
|
295 | export interface ResourceConfigQuery {
|
296 | type: ResourceTypes | ConfigResourceTypes;
|
297 | name: string;
|
298 | configNames?: string[];
|
299 | }
|
300 | export interface ConfigEntries {
|
301 | configName: string;
|
302 | configValue: string;
|
303 | isDefault: boolean;
|
304 | isSensitive: boolean;
|
305 | readOnly: boolean;
|
306 | configSynonyms: ConfigSynonyms[];
|
307 | }
|
308 | export interface ConfigSynonyms {
|
309 | configName: string;
|
310 | configValue: string;
|
311 | configSource: number;
|
312 | }
|
313 | export interface DescribeConfigResponse {
|
314 | resources: {
|
315 | configEntries: ConfigEntries[];
|
316 | errorCode: number;
|
317 | errorMessage: string;
|
318 | resourceName: string;
|
319 | resourceType: ResourceTypes | ConfigResourceTypes;
|
320 | }[];
|
321 | throttleTime: number;
|
322 | }
|
323 | export interface IResourceConfig {
|
324 | type: ResourceTypes | ConfigResourceTypes;
|
325 | name: string;
|
326 | configEntries: {
|
327 | name: string;
|
328 | value: string;
|
329 | }[];
|
330 | }
|
331 | declare type ValueOf<T> = T[keyof T];
|
332 | export declare type AdminEvents = {
|
333 | CONNECT: 'admin.connect';
|
334 | DISCONNECT: 'admin.disconnect';
|
335 | REQUEST: 'admin.network.request';
|
336 | REQUEST_TIMEOUT: 'admin.network.request_timeout';
|
337 | REQUEST_QUEUE_SIZE: 'admin.network.request_queue_size';
|
338 | };
|
339 | export interface InstrumentationEvent<T> {
|
340 | id: string;
|
341 | type: string;
|
342 | timestamp: number;
|
343 | payload: T;
|
344 | }
|
345 | export declare type RemoveInstrumentationEventListener<T> = () => void;
|
346 | export declare type ConnectEvent = InstrumentationEvent<null>;
|
347 | export declare type DisconnectEvent = InstrumentationEvent<null>;
|
348 | export declare type RequestEvent = InstrumentationEvent<{
|
349 | apiKey: number;
|
350 | apiName: string;
|
351 | apiVersion: number;
|
352 | broker: string;
|
353 | clientId: string;
|
354 | correlationId: number;
|
355 | createdAt: number;
|
356 | duration: number;
|
357 | pendingDuration: number;
|
358 | sentAt: number;
|
359 | size: number;
|
360 | }>;
|
361 | export declare type RequestTimeoutEvent = InstrumentationEvent<{
|
362 | apiKey: number;
|
363 | apiName: string;
|
364 | apiVersion: number;
|
365 | broker: string;
|
366 | clientId: string;
|
367 | correlationId: number;
|
368 | createdAt: number;
|
369 | pendingDuration: number;
|
370 | sentAt: number;
|
371 | }>;
|
372 | export declare type RequestQueueSizeEvent = InstrumentationEvent<{
|
373 | broker: string;
|
374 | clientId: string;
|
375 | queueSize: number;
|
376 | }>;
|
377 | export interface SeekEntry {
|
378 | partition: number;
|
379 | offset: string;
|
380 | }
|
381 | export interface Acl {
|
382 | principal: string;
|
383 | host: string;
|
384 | operation: AclOperationTypes;
|
385 | permissionType: AclPermissionTypes;
|
386 | }
|
387 | export interface AclResource {
|
388 | resourceType: AclResourceTypes;
|
389 | resourceName: string;
|
390 | resourcePatternType: ResourcePatternTypes;
|
391 | }
|
392 | export declare type AclEntry = Acl & AclResource;
|
393 | export declare type DescribeAclResource = AclResource & {
|
394 | acl: Acl[];
|
395 | };
|
396 | export interface DescribeAclResponse {
|
397 | throttleTime: number;
|
398 | errorCode: number;
|
399 | errorMessage?: string;
|
400 | resources: DescribeAclResource[];
|
401 | }
|
402 | export interface AclFilter {
|
403 | resourceType: AclResourceTypes;
|
404 | resourceName?: string;
|
405 | resourcePatternType: ResourcePatternTypes;
|
406 | principal?: string;
|
407 | host?: string;
|
408 | operation: AclOperationTypes;
|
409 | permissionType: AclPermissionTypes;
|
410 | }
|
411 | export interface MatchingAcl {
|
412 | errorCode: number;
|
413 | errorMessage?: string;
|
414 | resourceType: AclResourceTypes;
|
415 | resourceName: string;
|
416 | resourcePatternType: ResourcePatternTypes;
|
417 | principal: string;
|
418 | host: string;
|
419 | operation: AclOperationTypes;
|
420 | permissionType: AclPermissionTypes;
|
421 | }
|
422 | export interface DeleteAclFilterResponses {
|
423 | errorCode: number;
|
424 | errorMessage?: string;
|
425 | matchingAcls: MatchingAcl[];
|
426 | }
|
427 | export interface DeleteAclResponse {
|
428 | throttleTime: number;
|
429 | filterResponses: DeleteAclFilterResponses[];
|
430 | }
|
431 | export declare type Admin = {
|
432 | connect(): Promise<void>;
|
433 | disconnect(): Promise<void>;
|
434 | listTopics(): Promise<string[]>;
|
435 | createTopics(options: {
|
436 | validateOnly?: boolean;
|
437 | waitForLeaders?: boolean;
|
438 | timeout?: number;
|
439 | topics: ITopicConfig[];
|
440 | }): Promise<boolean>;
|
441 | deleteTopics(options: {
|
442 | topics: string[];
|
443 | timeout?: number;
|
444 | }): Promise<void>;
|
445 | createPartitions(options: {
|
446 | validateOnly?: boolean;
|
447 | timeout?: number;
|
448 | topicPartitions: ITopicPartitionConfig[];
|
449 | }): Promise<boolean>;
|
450 | fetchTopicMetadata(options?: {
|
451 | topics: string[];
|
452 | }): Promise<{
|
453 | topics: Array<ITopicMetadata>;
|
454 | }>;
|
455 | fetchOffsets(options: {
|
456 | groupId: string;
|
457 | topic: string;
|
458 | resolveOffsets?: boolean;
|
459 | }): Promise<Array<SeekEntry & {
|
460 | metadata: string | null;
|
461 | }>>;
|
462 | fetchTopicOffsets(topic: string): Promise<Array<SeekEntry & {
|
463 | high: string;
|
464 | low: string;
|
465 | }>>;
|
466 | fetchTopicOffsetsByTimestamp(topic: string, timestamp?: number): Promise<Array<SeekEntry>>;
|
467 | describeCluster(): Promise<{
|
468 | brokers: Array<{
|
469 | nodeId: number;
|
470 | host: string;
|
471 | port: number;
|
472 | }>;
|
473 | controller: number | null;
|
474 | clusterId: string;
|
475 | }>;
|
476 | setOffsets(options: {
|
477 | groupId: string;
|
478 | topic: string;
|
479 | partitions: SeekEntry[];
|
480 | }): Promise<void>;
|
481 | resetOffsets(options: {
|
482 | groupId: string;
|
483 | topic: string;
|
484 | earliest: boolean;
|
485 | }): Promise<void>;
|
486 | describeConfigs(configs: {
|
487 | resources: ResourceConfigQuery[];
|
488 | includeSynonyms: boolean;
|
489 | }): Promise<DescribeConfigResponse>;
|
490 | alterConfigs(configs: {
|
491 | validateOnly: boolean;
|
492 | resources: IResourceConfig[];
|
493 | }): Promise<any>;
|
494 | listGroups(): Promise<{
|
495 | groups: GroupOverview[];
|
496 | }>;
|
497 | deleteGroups(groupIds: string[]): Promise<DeleteGroupsResult[]>;
|
498 | describeGroups(groupIds: string[]): Promise<GroupDescriptions>;
|
499 | describeAcls(options: AclFilter): Promise<DescribeAclResponse>;
|
500 | deleteAcls(options: {
|
501 | filters: AclFilter[];
|
502 | }): Promise<DeleteAclResponse>;
|
503 | createAcls(options: {
|
504 | acl: AclEntry[];
|
505 | }): Promise<boolean>;
|
506 | deleteTopicRecords(options: {
|
507 | topic: string;
|
508 | partitions: SeekEntry[];
|
509 | }): Promise<void>;
|
510 | logger(): Logger;
|
511 | on(eventName: ValueOf<AdminEvents>, listener: (...args: any[]) => void): RemoveInstrumentationEventListener<typeof eventName>;
|
512 | events: AdminEvents;
|
513 | };
|
514 | export declare let PartitionAssigners: {
|
515 | roundRobin: PartitionAssigner;
|
516 | };
|
517 | export interface ISerializer<T> {
|
518 | encode(value: T): Buffer;
|
519 | decode(buffer: Buffer): T | null;
|
520 | }
|
521 | export declare type MemberMetadata = {
|
522 | version: number;
|
523 | topics: string[];
|
524 | userData: Buffer;
|
525 | };
|
526 | export declare type MemberAssignment = {
|
527 | version: number;
|
528 | assignment: Assignment;
|
529 | userData: Buffer;
|
530 | };
|
531 | export declare let AssignerProtocol: {
|
532 | MemberMetadata: ISerializer<MemberMetadata>;
|
533 | MemberAssignment: ISerializer<MemberAssignment>;
|
534 | };
|
535 | export declare enum logLevel {
|
536 | NOTHING = 0,
|
537 | ERROR = 1,
|
538 | WARN = 2,
|
539 | INFO = 4,
|
540 | DEBUG = 5
|
541 | }
|
542 | export interface LogEntry {
|
543 | namespace: string;
|
544 | level: logLevel;
|
545 | label: string;
|
546 | log: LoggerEntryContent;
|
547 | }
|
548 | export interface LoggerEntryContent {
|
549 | readonly timestamp: Date;
|
550 | readonly message: string;
|
551 | [key: string]: any;
|
552 | }
|
553 | export declare type logCreator = (logLevel: logLevel) => (entry: LogEntry) => void;
|
554 | export declare type Logger = {
|
555 | info: (message: string, extra?: object) => void;
|
556 | error: (message: string, extra?: object) => void;
|
557 | warn: (message: string, extra?: object) => void;
|
558 | debug: (message: string, extra?: object) => void;
|
559 | };
|
560 | export declare type Broker = {
|
561 | isConnected(): boolean;
|
562 | connect(): Promise<void>;
|
563 | disconnect(): Promise<void>;
|
564 | apiVersions(): Promise<{
|
565 | [apiKey: number]: {
|
566 | minVersion: number;
|
567 | maxVersion: number;
|
568 | };
|
569 | }>;
|
570 | metadata(topics: string[]): Promise<{
|
571 | brokers: Array<{
|
572 | nodeId: number;
|
573 | host: string;
|
574 | port: number;
|
575 | rack?: string;
|
576 | }>;
|
577 | topicMetadata: Array<{
|
578 | topicErrorCode: number;
|
579 | topic: number;
|
580 | partitionMetadata: PartitionMetadata[];
|
581 | }>;
|
582 | }>;
|
583 | offsetCommit(request: {
|
584 | groupId: string;
|
585 | groupGenerationId: number;
|
586 | memberId: string;
|
587 | retentionTime?: number;
|
588 | topics: Array<{
|
589 | topic: string;
|
590 | partitions: Array<{
|
591 | partition: number;
|
592 | offset: string;
|
593 | }>;
|
594 | }>;
|
595 | }): Promise<any>;
|
596 | fetch(request: {
|
597 | replicaId?: number;
|
598 | isolationLevel?: number;
|
599 | maxWaitTime?: number;
|
600 | minBytes?: number;
|
601 | maxBytes?: number;
|
602 | topics: Array<{
|
603 | topic: string;
|
604 | partitions: Array<{
|
605 | partition: number;
|
606 | fetchOffset: string;
|
607 | maxBytes: number;
|
608 | }>;
|
609 | }>;
|
610 | rackId?: string;
|
611 | }): Promise<any>;
|
612 | };
|
613 | export declare type KafkaMessage = {
|
614 | key: Buffer;
|
615 | value: Buffer | null;
|
616 | timestamp: string;
|
617 | size: number;
|
618 | attributes: number;
|
619 | offset: string;
|
620 | headers?: IHeaders;
|
621 | };
|
622 | export interface ProducerRecord {
|
623 | topic: string;
|
624 | messages: Message[];
|
625 | acks?: number;
|
626 | timeout?: number;
|
627 | compression?: CompressionTypes;
|
628 | }
|
629 | export declare type RecordMetadata = {
|
630 | topicName: string;
|
631 | partition: number;
|
632 | errorCode: number;
|
633 | offset?: string;
|
634 | timestamp?: string;
|
635 | baseOffset?: string;
|
636 | logAppendTime?: string;
|
637 | logStartOffset?: string;
|
638 | };
|
639 | export interface TopicMessages {
|
640 | topic: string;
|
641 | messages: Message[];
|
642 | }
|
643 | export interface ProducerBatch {
|
644 | acks?: number;
|
645 | timeout?: number;
|
646 | compression?: CompressionTypes;
|
647 | topicMessages?: TopicMessages[];
|
648 | }
|
649 | export interface PartitionOffset {
|
650 | partition: number;
|
651 | offset: string;
|
652 | }
|
653 | export interface TopicOffsets {
|
654 | topic: string;
|
655 | partitions: PartitionOffset[];
|
656 | }
|
657 | export interface Offsets {
|
658 | topics: TopicOffsets[];
|
659 | }
|
660 | declare type Sender = {
|
661 | send(record: ProducerRecord): Promise<RecordMetadata[]>;
|
662 | sendBatch(batch: ProducerBatch): Promise<RecordMetadata[]>;
|
663 | };
|
664 | export declare type ProducerEvents = {
|
665 | CONNECT: 'producer.connect';
|
666 | DISCONNECT: 'producer.disconnect';
|
667 | REQUEST: 'producer.network.request';
|
668 | REQUEST_TIMEOUT: 'producer.network.request_timeout';
|
669 | REQUEST_QUEUE_SIZE: 'producer.network.request_queue_size';
|
670 | };
|
671 | export declare type Producer = Sender & {
|
672 | connect(): Promise<void>;
|
673 | disconnect(): Promise<void>;
|
674 | isIdempotent(): boolean;
|
675 | events: ProducerEvents;
|
676 | on(eventName: ValueOf<ProducerEvents>, listener: (...args: any[]) => void): RemoveInstrumentationEventListener<typeof eventName>;
|
677 | transaction(): Promise<Transaction>;
|
678 | logger(): Logger;
|
679 | };
|
680 | export declare type Transaction = Sender & {
|
681 | sendOffsets(offsets: Offsets & {
|
682 | consumerGroupId: string;
|
683 | }): Promise<void>;
|
684 | commit(): Promise<void>;
|
685 | abort(): Promise<void>;
|
686 | isActive(): boolean;
|
687 | };
|
688 | export declare type ConsumerGroup = {
|
689 | groupId: string;
|
690 | generationId: number;
|
691 | memberId: string;
|
692 | coordinator: Broker;
|
693 | };
|
694 | export declare type MemberDescription = {
|
695 | clientHost: string;
|
696 | clientId: string;
|
697 | memberId: string;
|
698 | memberAssignment: Buffer;
|
699 | memberMetadata: Buffer;
|
700 | };
|
701 | export declare type ConsumerGroupState = 'Unknown' | 'PreparingRebalance' | 'CompletingRebalance' | 'Stable' | 'Dead' | 'Empty';
|
702 | export declare type GroupDescription = {
|
703 | groupId: string;
|
704 | members: MemberDescription[];
|
705 | protocol: string;
|
706 | protocolType: string;
|
707 | state: ConsumerGroupState;
|
708 | };
|
709 | export declare type GroupDescriptions = {
|
710 | groups: GroupDescription[];
|
711 | };
|
712 | export declare type TopicPartitions = {
|
713 | topic: string;
|
714 | partitions: number[];
|
715 | };
|
716 | export declare type TopicPartitionOffsetAndMetadata = {
|
717 | topic: string;
|
718 | partition: number;
|
719 | offset: string;
|
720 | metadata?: string | null;
|
721 | };
|
722 | export declare type TopicPartitionOffsetAndMedata = TopicPartitionOffsetAndMetadata;
|
723 | export declare type Batch = {
|
724 | topic: string;
|
725 | partition: number;
|
726 | highWatermark: string;
|
727 | messages: KafkaMessage[];
|
728 | isEmpty(): boolean;
|
729 | firstOffset(): string | null;
|
730 | lastOffset(): string;
|
731 | offsetLag(): string;
|
732 | offsetLagLow(): string;
|
733 | };
|
734 | export declare type GroupOverview = {
|
735 | groupId: string;
|
736 | protocolType: string;
|
737 | };
|
738 | export declare type DeleteGroupsResult = {
|
739 | groupId: string;
|
740 | errorCode?: number;
|
741 | error?: KafkaJSProtocolError;
|
742 | };
|
743 | export declare type ConsumerEvents = {
|
744 | HEARTBEAT: 'consumer.heartbeat';
|
745 | COMMIT_OFFSETS: 'consumer.commit_offsets';
|
746 | GROUP_JOIN: 'consumer.group_join';
|
747 | FETCH_START: 'consumer.fetch_start';
|
748 | FETCH: 'consumer.fetch';
|
749 | START_BATCH_PROCESS: 'consumer.start_batch_process';
|
750 | END_BATCH_PROCESS: 'consumer.end_batch_process';
|
751 | CONNECT: 'consumer.connect';
|
752 | DISCONNECT: 'consumer.disconnect';
|
753 | STOP: 'consumer.stop';
|
754 | CRASH: 'consumer.crash';
|
755 | RECEIVED_UNSUBSCRIBED_TOPICS: 'consumer.received_unsubscribed_topics';
|
756 | REQUEST: 'consumer.network.request';
|
757 | REQUEST_TIMEOUT: 'consumer.network.request_timeout';
|
758 | REQUEST_QUEUE_SIZE: 'consumer.network.request_queue_size';
|
759 | };
|
760 | export declare type ConsumerHeartbeatEvent = InstrumentationEvent<{
|
761 | groupId: string;
|
762 | memberId: string;
|
763 | groupGenerationId: number;
|
764 | }>;
|
765 | export declare type ConsumerCommitOffsetsEvent = InstrumentationEvent<{
|
766 | groupId: string;
|
767 | memberId: string;
|
768 | groupGenerationId: number;
|
769 | topics: {
|
770 | topic: string;
|
771 | partitions: {
|
772 | offset: string;
|
773 | partition: string;
|
774 | }[];
|
775 | }[];
|
776 | }>;
|
777 | export interface IMemberAssignment {
|
778 | [key: string]: number[];
|
779 | }
|
780 | export declare type ConsumerGroupJoinEvent = InstrumentationEvent<{
|
781 | duration: number;
|
782 | groupId: string;
|
783 | isLeader: boolean;
|
784 | leaderId: string;
|
785 | groupProtocol: string;
|
786 | memberId: string;
|
787 | memberAssignment: IMemberAssignment;
|
788 | }>;
|
789 | export declare type ConsumerFetchEvent = InstrumentationEvent<{
|
790 | numberOfBatches: number;
|
791 | duration: number;
|
792 | }>;
|
793 | interface IBatchProcessEvent {
|
794 | topic: string;
|
795 | partition: number;
|
796 | highWatermark: string;
|
797 | offsetLag: string;
|
798 | offsetLagLow: string;
|
799 | batchSize: number;
|
800 | firstOffset: string;
|
801 | lastOffset: string;
|
802 | }
|
803 | export declare type ConsumerStartBatchProcessEvent = InstrumentationEvent<IBatchProcessEvent>;
|
804 | export declare type ConsumerEndBatchProcessEvent = InstrumentationEvent<IBatchProcessEvent & {
|
805 | duration: number;
|
806 | }>;
|
807 | export declare type ConsumerCrashEvent = InstrumentationEvent<{
|
808 | error: Error;
|
809 | groupId: string;
|
810 | restart: boolean;
|
811 | }>;
|
812 | export declare type ConsumerReceivedUnsubcribedTopicsEvent = InstrumentationEvent<{
|
813 | groupId: string;
|
814 | generationId: number;
|
815 | memberId: string;
|
816 | assignedTopics: string[];
|
817 | topicsSubscribed: string[];
|
818 | topicsNotSubscribed: string[];
|
819 | }>;
|
820 | export interface OffsetsByTopicPartition {
|
821 | topics: TopicOffsets[];
|
822 | }
|
823 | export interface EachMessagePayload {
|
824 | topic: string;
|
825 | partition: number;
|
826 | message: KafkaMessage;
|
827 | }
|
828 | export interface EachBatchPayload {
|
829 | batch: Batch;
|
830 | resolveOffset(offset: string): void;
|
831 | heartbeat(): Promise<void>;
|
832 | commitOffsetsIfNecessary(offsets?: Offsets): Promise<void>;
|
833 | uncommittedOffsets(): OffsetsByTopicPartition;
|
834 | isRunning(): boolean;
|
835 | isStale(): boolean;
|
836 | }
|
837 |
|
838 |
|
839 |
|
840 |
|
841 | export declare type ConsumerEachMessagePayload = EachMessagePayload;
|
842 |
|
843 |
|
844 |
|
845 |
|
846 | export declare type ConsumerEachBatchPayload = EachBatchPayload;
|
847 | export declare type ConsumerRunConfig = {
|
848 | autoCommit?: boolean;
|
849 | autoCommitInterval?: number | null;
|
850 | autoCommitThreshold?: number | null;
|
851 | eachBatchAutoResolve?: boolean;
|
852 | partitionsConsumedConcurrently?: number;
|
853 | eachBatch?: (payload: EachBatchPayload) => Promise<void>;
|
854 | eachMessage?: (payload: EachMessagePayload) => Promise<void>;
|
855 | };
|
856 | export declare type ConsumerSubscribeTopic = {
|
857 | topic: string | RegExp;
|
858 | fromBeginning?: boolean;
|
859 | };
|
860 | export declare type Consumer = {
|
861 | connect(): Promise<void>;
|
862 | disconnect(): Promise<void>;
|
863 | subscribe(topic: ConsumerSubscribeTopic): Promise<void>;
|
864 | stop(): Promise<void>;
|
865 | run(config?: ConsumerRunConfig): Promise<void>;
|
866 | commitOffsets(topicPartitions: Array<TopicPartitionOffsetAndMetadata>): Promise<void>;
|
867 | seek(topicPartition: {
|
868 | topic: string;
|
869 | partition: number;
|
870 | offset: string;
|
871 | }): void;
|
872 | describeGroup(): Promise<GroupDescription>;
|
873 | pause(topics: Array<{
|
874 | topic: string;
|
875 | partitions?: number[];
|
876 | }>): void;
|
877 | paused(): TopicPartitions[];
|
878 | resume(topics: Array<{
|
879 | topic: string;
|
880 | partitions?: number[];
|
881 | }>): void;
|
882 | on(eventName: ValueOf<ConsumerEvents>, listener: (...args: any[]) => void): RemoveInstrumentationEventListener<typeof eventName>;
|
883 | logger(): Logger;
|
884 | events: ConsumerEvents;
|
885 | };
|
886 | export declare enum CompressionTypes {
|
887 | None = 0,
|
888 | GZIP = 1,
|
889 | Snappy = 2,
|
890 | LZ4 = 3,
|
891 | ZSTD = 4
|
892 | }
|
893 | export declare let CompressionCodecs: {
|
894 | [CompressionTypes.GZIP]: () => any;
|
895 | [CompressionTypes.Snappy]: () => any;
|
896 | [CompressionTypes.LZ4]: () => any;
|
897 | [CompressionTypes.ZSTD]: () => any;
|
898 | };
|
899 | export declare class KafkaJSError extends Error {
|
900 | readonly message: Error['message'];
|
901 | readonly name: string;
|
902 | readonly retriable: boolean;
|
903 | readonly helpUrl?: string;
|
904 | constructor(e: Error | string, metadata?: KafkaJSErrorMetadata);
|
905 | }
|
906 | export declare class KafkaJSNonRetriableError extends KafkaJSError {
|
907 | constructor(e: Error | string);
|
908 | }
|
909 | export declare class KafkaJSProtocolError extends KafkaJSError {
|
910 | readonly code: number;
|
911 | readonly type: string;
|
912 | constructor(e: Error | string);
|
913 | }
|
914 | export declare class KafkaJSOffsetOutOfRange extends KafkaJSProtocolError {
|
915 | readonly topic: string;
|
916 | readonly partition: number;
|
917 | constructor(e: Error | string, metadata?: KafkaJSOffsetOutOfRangeMetadata);
|
918 | }
|
919 | export declare class KafkaJSNumberOfRetriesExceeded extends KafkaJSNonRetriableError {
|
920 | readonly stack: string;
|
921 | readonly originalError: Error;
|
922 | readonly retryCount: number;
|
923 | readonly retryTime: number;
|
924 | constructor(e: Error | string, metadata?: KafkaJSNumberOfRetriesExceededMetadata);
|
925 | }
|
926 | export declare class KafkaJSConnectionError extends KafkaJSError {
|
927 | readonly broker: string;
|
928 | constructor(e: Error | string, metadata?: KafkaJSConnectionErrorMetadata);
|
929 | }
|
930 | export declare class KafkaJSRequestTimeoutError extends KafkaJSError {
|
931 | readonly broker: string;
|
932 | readonly correlationId: number;
|
933 | readonly createdAt: number;
|
934 | readonly sentAt: number;
|
935 | readonly pendingDuration: number;
|
936 | constructor(e: Error | string, metadata?: KafkaJSRequestTimeoutErrorMetadata);
|
937 | }
|
938 | export declare class KafkaJSMetadataNotLoaded extends KafkaJSError {
|
939 | constructor();
|
940 | }
|
941 | export declare class KafkaJSTopicMetadataNotLoaded extends KafkaJSMetadataNotLoaded {
|
942 | readonly topic: string;
|
943 | constructor(e: Error | string, metadata?: KafkaJSTopicMetadataNotLoadedMetadata);
|
944 | }
|
945 | export declare class KafkaJSStaleTopicMetadataAssignment extends KafkaJSError {
|
946 | readonly topic: string;
|
947 | readonly unknownPartitions: number;
|
948 | constructor(e: Error | string, metadata?: KafkaJSStaleTopicMetadataAssignmentMetadata);
|
949 | }
|
950 | export declare class KafkaJSServerDoesNotSupportApiKey extends KafkaJSNonRetriableError {
|
951 | readonly apiKey: number;
|
952 | readonly apiName: string;
|
953 | constructor(e: Error | string, metadata?: KafkaJSServerDoesNotSupportApiKeyMetadata);
|
954 | }
|
955 | export declare class KafkaJSBrokerNotFound extends KafkaJSError {
|
956 | constructor();
|
957 | }
|
958 | export declare class KafkaJSPartialMessageError extends KafkaJSError {
|
959 | constructor();
|
960 | }
|
961 | export declare class KafkaJSSASLAuthenticationError extends KafkaJSError {
|
962 | constructor();
|
963 | }
|
964 | export declare class KafkaJSGroupCoordinatorNotFound extends KafkaJSError {
|
965 | constructor();
|
966 | }
|
967 | export declare class KafkaJSNotImplemented extends KafkaJSError {
|
968 | constructor();
|
969 | }
|
970 | export declare class KafkaJSTimeout extends KafkaJSError {
|
971 | constructor();
|
972 | }
|
973 | export declare class KafkaJSLockTimeout extends KafkaJSError {
|
974 | constructor();
|
975 | }
|
976 | export declare class KafkaJSUnsupportedMagicByteInMessageSet extends KafkaJSError {
|
977 | constructor();
|
978 | }
|
979 | export declare class KafkaJSDeleteGroupsError extends KafkaJSError {
|
980 | readonly groups: DeleteGroupsResult[];
|
981 | constructor(e: Error | string, groups?: KafkaJSDeleteGroupsErrorGroups[]);
|
982 | }
|
983 | export declare class KafkaJSDeleteTopicRecordsError extends KafkaJSError {
|
984 | constructor(metadata: KafkaJSDeleteTopicRecordsErrorTopic);
|
985 | }
|
986 | export interface KafkaJSDeleteGroupsErrorGroups {
|
987 | groupId: string;
|
988 | errorCode: number;
|
989 | error: KafkaJSError;
|
990 | }
|
991 | export interface KafkaJSDeleteTopicRecordsErrorTopic {
|
992 | topic: string;
|
993 | partitions: KafkaJSDeleteTopicRecordsErrorPartition[];
|
994 | }
|
995 | export interface KafkaJSDeleteTopicRecordsErrorPartition {
|
996 | partition: number;
|
997 | offset: string;
|
998 | error: KafkaJSError;
|
999 | }
|
1000 | export interface KafkaJSErrorMetadata {
|
1001 | retriable?: boolean;
|
1002 | topic?: string;
|
1003 | partitionId?: number;
|
1004 | metadata?: PartitionMetadata;
|
1005 | }
|
1006 | export interface KafkaJSOffsetOutOfRangeMetadata {
|
1007 | topic: string;
|
1008 | partition: number;
|
1009 | }
|
1010 | export interface KafkaJSNumberOfRetriesExceededMetadata {
|
1011 | retryCount: number;
|
1012 | retryTime: number;
|
1013 | }
|
1014 | export interface KafkaJSConnectionErrorMetadata {
|
1015 | broker?: string;
|
1016 | code?: string;
|
1017 | }
|
1018 | export interface KafkaJSRequestTimeoutErrorMetadata {
|
1019 | broker: string;
|
1020 | clientId: string;
|
1021 | correlationId: number;
|
1022 | createdAt: number;
|
1023 | sentAt: number;
|
1024 | pendingDuration: number;
|
1025 | }
|
1026 | export interface KafkaJSTopicMetadataNotLoadedMetadata {
|
1027 | topic: string;
|
1028 | }
|
1029 | export interface KafkaJSStaleTopicMetadataAssignmentMetadata {
|
1030 | topic: string;
|
1031 | unknownPartitions: PartitionMetadata[];
|
1032 | }
|
1033 | export interface KafkaJSServerDoesNotSupportApiKeyMetadata {
|
1034 | apiKey: number;
|
1035 | apiName: string;
|
1036 | }
|
1037 | export {};
|