UNPKG

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