UNPKG

30.1 kBTypeScriptView Raw
1/**
2 * Do NOT add NestJS logic to this interface. It is meant to ONLY represent the types for the kafkajs package.
3 *
4 * @see https://github.com/tulios/kafkajs/blob/master/types/index.d.ts
5 */
6/// <reference types="node" />
7/// <reference types="node" />
8/// <reference types="node" />
9import * as net from 'net';
10import * as tls from 'tls';
11declare type Without<T, U> = {
12 [P in Exclude<keyof T, keyof U>]?: never;
13};
14declare type XOR<T, U> = T | U extends object ? (Without<T, U> & U) | (Without<U, T> & T) : T | U;
15export 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}
22export declare type BrokersFunction = () => string[] | Promise<string[]>;
23export 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}
38export interface ISocketFactoryArgs {
39 host: string;
40 port: number;
41 ssl: tls.ConnectionOptions;
42 onConnect: () => void;
43}
44export declare type ISocketFactory = (args: ISocketFactoryArgs) => net.Socket;
45export interface OauthbearerProviderResponse {
46 value: string;
47}
48declare 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};
71export declare type SASLMechanism = keyof SASLMechanismOptionsMap;
72declare type SASLMechanismOptions<T> = T extends SASLMechanism ? {
73 mechanism: T;
74} & SASLMechanismOptionsMap[T] : never;
75export declare type SASLOptions = SASLMechanismOptions<SASLMechanism>;
76export 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}
86export interface Message {
87 key?: Buffer | string | null;
88 value: Buffer | string | null;
89 partition?: number;
90 headers?: IHeaders;
91 timestamp?: string;
92}
93export interface PartitionerArgs {
94 topic: string;
95 partitionMetadata: PartitionMetadata[];
96 message: Message;
97}
98export declare type ICustomPartitioner = () => (args: PartitionerArgs) => number;
99export declare type DefaultPartitioner = ICustomPartitioner;
100export declare type JavaCompatiblePartitioner = ICustomPartitioner;
101export declare let Partitioners: {
102 DefaultPartitioner: DefaultPartitioner;
103 JavaCompatiblePartitioner: JavaCompatiblePartitioner;
104};
105export declare type PartitionMetadata = {
106 partitionErrorCode: number;
107 partitionId: number;
108 leader: number;
109 replicas: number[];
110 isr: number[];
111 offlineReplicas?: number[];
112};
113export interface IHeaders {
114 [key: string]: Buffer | string | undefined;
115}
116export 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}
135export declare type PartitionAssigner = (config: {
136 cluster: Cluster;
137}) => Assigner;
138export interface CoordinatorMetadata {
139 errorCode: number;
140 coordinator: {
141 nodeId: number;
142 host: string;
143 port: number;
144 };
145}
146export 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};
187export declare type Assignment = {
188 [topic: string]: number[];
189};
190export declare type GroupMember = {
191 memberId: string;
192 memberMetadata: Buffer;
193};
194export declare type GroupMemberAssignment = {
195 memberId: string;
196 memberAssignment: Buffer;
197};
198export declare type GroupState = {
199 name: string;
200 metadata: Buffer;
201};
202export 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};
213export interface RetryOptions {
214 maxRetryTime?: number;
215 initialRetryTime?: number;
216 factor?: number;
217 multiplier?: number;
218 retries?: number;
219}
220export interface AdminConfig {
221 retry?: RetryOptions;
222}
223export interface ITopicConfig {
224 topic: string;
225 numPartitions?: number;
226 replicationFactor?: number;
227 replicaAssignment?: object[];
228 configEntries?: object[];
229}
230export interface ITopicPartitionConfig {
231 topic: string;
232 count: number;
233 assignments?: Array<Array<number>>;
234}
235export interface ITopicMetadata {
236 name: string;
237 partitions: PartitionMetadata[];
238}
239/**
240 * @deprecated
241 * Use ConfigResourceTypes or AclResourceTypes
242 */
243export 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}
252export 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}
261export declare enum ConfigResourceTypes {
262 UNKNOWN = 0,
263 TOPIC = 2,
264 BROKER = 4,
265 BROKER_LOGGER = 8
266}
267export declare enum AclPermissionTypes {
268 UNKNOWN = 0,
269 ANY = 1,
270 DENY = 2,
271 ALLOW = 3
272}
273export 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}
288export declare enum ResourcePatternTypes {
289 UNKNOWN = 0,
290 ANY = 1,
291 MATCH = 2,
292 LITERAL = 3,
293 PREFIXED = 4
294}
295export interface ResourceConfigQuery {
296 type: ResourceTypes | ConfigResourceTypes;
297 name: string;
298 configNames?: string[];
299}
300export interface ConfigEntries {
301 configName: string;
302 configValue: string;
303 isDefault: boolean;
304 isSensitive: boolean;
305 readOnly: boolean;
306 configSynonyms: ConfigSynonyms[];
307}
308export interface ConfigSynonyms {
309 configName: string;
310 configValue: string;
311 configSource: number;
312}
313export 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}
323export interface IResourceConfig {
324 type: ResourceTypes | ConfigResourceTypes;
325 name: string;
326 configEntries: {
327 name: string;
328 value: string;
329 }[];
330}
331declare type ValueOf<T> = T[keyof T];
332export 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};
339export interface InstrumentationEvent<T> {
340 id: string;
341 type: string;
342 timestamp: number;
343 payload: T;
344}
345export declare type RemoveInstrumentationEventListener<T> = () => void;
346export declare type ConnectEvent = InstrumentationEvent<null>;
347export declare type DisconnectEvent = InstrumentationEvent<null>;
348export 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}>;
361export 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}>;
372export declare type RequestQueueSizeEvent = InstrumentationEvent<{
373 broker: string;
374 clientId: string;
375 queueSize: number;
376}>;
377export interface SeekEntry {
378 partition: number;
379 offset: string;
380}
381export interface Acl {
382 principal: string;
383 host: string;
384 operation: AclOperationTypes;
385 permissionType: AclPermissionTypes;
386}
387export interface AclResource {
388 resourceType: AclResourceTypes;
389 resourceName: string;
390 resourcePatternType: ResourcePatternTypes;
391}
392export declare type AclEntry = Acl & AclResource;
393export declare type DescribeAclResource = AclResource & {
394 acl: Acl[];
395};
396export interface DescribeAclResponse {
397 throttleTime: number;
398 errorCode: number;
399 errorMessage?: string;
400 resources: DescribeAclResource[];
401}
402export interface AclFilter {
403 resourceType: AclResourceTypes;
404 resourceName?: string;
405 resourcePatternType: ResourcePatternTypes;
406 principal?: string;
407 host?: string;
408 operation: AclOperationTypes;
409 permissionType: AclPermissionTypes;
410}
411export 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}
422export interface DeleteAclFilterResponses {
423 errorCode: number;
424 errorMessage?: string;
425 matchingAcls: MatchingAcl[];
426}
427export interface DeleteAclResponse {
428 throttleTime: number;
429 filterResponses: DeleteAclFilterResponses[];
430}
431export 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};
514export declare let PartitionAssigners: {
515 roundRobin: PartitionAssigner;
516};
517export interface ISerializer<T> {
518 encode(value: T): Buffer;
519 decode(buffer: Buffer): T | null;
520}
521export declare type MemberMetadata = {
522 version: number;
523 topics: string[];
524 userData: Buffer;
525};
526export declare type MemberAssignment = {
527 version: number;
528 assignment: Assignment;
529 userData: Buffer;
530};
531export declare let AssignerProtocol: {
532 MemberMetadata: ISerializer<MemberMetadata>;
533 MemberAssignment: ISerializer<MemberAssignment>;
534};
535export declare enum logLevel {
536 NOTHING = 0,
537 ERROR = 1,
538 WARN = 2,
539 INFO = 4,
540 DEBUG = 5
541}
542export interface LogEntry {
543 namespace: string;
544 level: logLevel;
545 label: string;
546 log: LoggerEntryContent;
547}
548export interface LoggerEntryContent {
549 readonly timestamp: Date;
550 readonly message: string;
551 [key: string]: any;
552}
553export declare type logCreator = (logLevel: logLevel) => (entry: LogEntry) => void;
554export 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};
560export 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};
613export 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};
622export interface ProducerRecord {
623 topic: string;
624 messages: Message[];
625 acks?: number;
626 timeout?: number;
627 compression?: CompressionTypes;
628}
629export 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};
639export interface TopicMessages {
640 topic: string;
641 messages: Message[];
642}
643export interface ProducerBatch {
644 acks?: number;
645 timeout?: number;
646 compression?: CompressionTypes;
647 topicMessages?: TopicMessages[];
648}
649export interface PartitionOffset {
650 partition: number;
651 offset: string;
652}
653export interface TopicOffsets {
654 topic: string;
655 partitions: PartitionOffset[];
656}
657export interface Offsets {
658 topics: TopicOffsets[];
659}
660declare type Sender = {
661 send(record: ProducerRecord): Promise<RecordMetadata[]>;
662 sendBatch(batch: ProducerBatch): Promise<RecordMetadata[]>;
663};
664export 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};
671export 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};
680export 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};
688export declare type ConsumerGroup = {
689 groupId: string;
690 generationId: number;
691 memberId: string;
692 coordinator: Broker;
693};
694export declare type MemberDescription = {
695 clientHost: string;
696 clientId: string;
697 memberId: string;
698 memberAssignment: Buffer;
699 memberMetadata: Buffer;
700};
701export declare type ConsumerGroupState = 'Unknown' | 'PreparingRebalance' | 'CompletingRebalance' | 'Stable' | 'Dead' | 'Empty';
702export declare type GroupDescription = {
703 groupId: string;
704 members: MemberDescription[];
705 protocol: string;
706 protocolType: string;
707 state: ConsumerGroupState;
708};
709export declare type GroupDescriptions = {
710 groups: GroupDescription[];
711};
712export declare type TopicPartitions = {
713 topic: string;
714 partitions: number[];
715};
716export declare type TopicPartitionOffsetAndMetadata = {
717 topic: string;
718 partition: number;
719 offset: string;
720 metadata?: string | null;
721};
722export declare type TopicPartitionOffsetAndMedata = TopicPartitionOffsetAndMetadata;
723export 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};
734export declare type GroupOverview = {
735 groupId: string;
736 protocolType: string;
737};
738export declare type DeleteGroupsResult = {
739 groupId: string;
740 errorCode?: number;
741 error?: KafkaJSProtocolError;
742};
743export 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};
760export declare type ConsumerHeartbeatEvent = InstrumentationEvent<{
761 groupId: string;
762 memberId: string;
763 groupGenerationId: number;
764}>;
765export 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}>;
777export interface IMemberAssignment {
778 [key: string]: number[];
779}
780export 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}>;
789export declare type ConsumerFetchEvent = InstrumentationEvent<{
790 numberOfBatches: number;
791 duration: number;
792}>;
793interface 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}
803export declare type ConsumerStartBatchProcessEvent = InstrumentationEvent<IBatchProcessEvent>;
804export declare type ConsumerEndBatchProcessEvent = InstrumentationEvent<IBatchProcessEvent & {
805 duration: number;
806}>;
807export declare type ConsumerCrashEvent = InstrumentationEvent<{
808 error: Error;
809 groupId: string;
810 restart: boolean;
811}>;
812export declare type ConsumerReceivedUnsubcribedTopicsEvent = InstrumentationEvent<{
813 groupId: string;
814 generationId: number;
815 memberId: string;
816 assignedTopics: string[];
817 topicsSubscribed: string[];
818 topicsNotSubscribed: string[];
819}>;
820export interface OffsetsByTopicPartition {
821 topics: TopicOffsets[];
822}
823export interface EachMessagePayload {
824 topic: string;
825 partition: number;
826 message: KafkaMessage;
827}
828export 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 * Type alias to keep compatibility with @types/kafkajs
839 * @see https://github.com/DefinitelyTyped/DefinitelyTyped/blob/712ad9d59ccca6a3cc92f347fea0d1c7b02f5eeb/types/kafkajs/index.d.ts#L321-L325
840 */
841export declare type ConsumerEachMessagePayload = EachMessagePayload;
842/**
843 * Type alias to keep compatibility with @types/kafkajs
844 * @see https://github.com/DefinitelyTyped/DefinitelyTyped/blob/712ad9d59ccca6a3cc92f347fea0d1c7b02f5eeb/types/kafkajs/index.d.ts#L327-L336
845 */
846export declare type ConsumerEachBatchPayload = EachBatchPayload;
847export 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};
856export declare type ConsumerSubscribeTopic = {
857 topic: string | RegExp;
858 fromBeginning?: boolean;
859};
860export 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};
886export declare enum CompressionTypes {
887 None = 0,
888 GZIP = 1,
889 Snappy = 2,
890 LZ4 = 3,
891 ZSTD = 4
892}
893export declare let CompressionCodecs: {
894 [CompressionTypes.GZIP]: () => any;
895 [CompressionTypes.Snappy]: () => any;
896 [CompressionTypes.LZ4]: () => any;
897 [CompressionTypes.ZSTD]: () => any;
898};
899export 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}
906export declare class KafkaJSNonRetriableError extends KafkaJSError {
907 constructor(e: Error | string);
908}
909export declare class KafkaJSProtocolError extends KafkaJSError {
910 readonly code: number;
911 readonly type: string;
912 constructor(e: Error | string);
913}
914export declare class KafkaJSOffsetOutOfRange extends KafkaJSProtocolError {
915 readonly topic: string;
916 readonly partition: number;
917 constructor(e: Error | string, metadata?: KafkaJSOffsetOutOfRangeMetadata);
918}
919export 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}
926export declare class KafkaJSConnectionError extends KafkaJSError {
927 readonly broker: string;
928 constructor(e: Error | string, metadata?: KafkaJSConnectionErrorMetadata);
929}
930export 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}
938export declare class KafkaJSMetadataNotLoaded extends KafkaJSError {
939 constructor();
940}
941export declare class KafkaJSTopicMetadataNotLoaded extends KafkaJSMetadataNotLoaded {
942 readonly topic: string;
943 constructor(e: Error | string, metadata?: KafkaJSTopicMetadataNotLoadedMetadata);
944}
945export declare class KafkaJSStaleTopicMetadataAssignment extends KafkaJSError {
946 readonly topic: string;
947 readonly unknownPartitions: number;
948 constructor(e: Error | string, metadata?: KafkaJSStaleTopicMetadataAssignmentMetadata);
949}
950export declare class KafkaJSServerDoesNotSupportApiKey extends KafkaJSNonRetriableError {
951 readonly apiKey: number;
952 readonly apiName: string;
953 constructor(e: Error | string, metadata?: KafkaJSServerDoesNotSupportApiKeyMetadata);
954}
955export declare class KafkaJSBrokerNotFound extends KafkaJSError {
956 constructor();
957}
958export declare class KafkaJSPartialMessageError extends KafkaJSError {
959 constructor();
960}
961export declare class KafkaJSSASLAuthenticationError extends KafkaJSError {
962 constructor();
963}
964export declare class KafkaJSGroupCoordinatorNotFound extends KafkaJSError {
965 constructor();
966}
967export declare class KafkaJSNotImplemented extends KafkaJSError {
968 constructor();
969}
970export declare class KafkaJSTimeout extends KafkaJSError {
971 constructor();
972}
973export declare class KafkaJSLockTimeout extends KafkaJSError {
974 constructor();
975}
976export declare class KafkaJSUnsupportedMagicByteInMessageSet extends KafkaJSError {
977 constructor();
978}
979export declare class KafkaJSDeleteGroupsError extends KafkaJSError {
980 readonly groups: DeleteGroupsResult[];
981 constructor(e: Error | string, groups?: KafkaJSDeleteGroupsErrorGroups[]);
982}
983export declare class KafkaJSDeleteTopicRecordsError extends KafkaJSError {
984 constructor(metadata: KafkaJSDeleteTopicRecordsErrorTopic);
985}
986export interface KafkaJSDeleteGroupsErrorGroups {
987 groupId: string;
988 errorCode: number;
989 error: KafkaJSError;
990}
991export interface KafkaJSDeleteTopicRecordsErrorTopic {
992 topic: string;
993 partitions: KafkaJSDeleteTopicRecordsErrorPartition[];
994}
995export interface KafkaJSDeleteTopicRecordsErrorPartition {
996 partition: number;
997 offset: string;
998 error: KafkaJSError;
999}
1000export interface KafkaJSErrorMetadata {
1001 retriable?: boolean;
1002 topic?: string;
1003 partitionId?: number;
1004 metadata?: PartitionMetadata;
1005}
1006export interface KafkaJSOffsetOutOfRangeMetadata {
1007 topic: string;
1008 partition: number;
1009}
1010export interface KafkaJSNumberOfRetriesExceededMetadata {
1011 retryCount: number;
1012 retryTime: number;
1013}
1014export interface KafkaJSConnectionErrorMetadata {
1015 broker?: string;
1016 code?: string;
1017}
1018export interface KafkaJSRequestTimeoutErrorMetadata {
1019 broker: string;
1020 clientId: string;
1021 correlationId: number;
1022 createdAt: number;
1023 sentAt: number;
1024 pendingDuration: number;
1025}
1026export interface KafkaJSTopicMetadataNotLoadedMetadata {
1027 topic: string;
1028}
1029export interface KafkaJSStaleTopicMetadataAssignmentMetadata {
1030 topic: string;
1031 unknownPartitions: PartitionMetadata[];
1032}
1033export interface KafkaJSServerDoesNotSupportApiKeyMetadata {
1034 apiKey: number;
1035 apiName: string;
1036}
1037export {};