UNPKG

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