@message-queue-toolkit/kafka
Version:
Kafka adapter for message-queue-toolkit
41 lines (40 loc) • 2.45 kB
TypeScript
import { type CommonLogger, type ErrorReporter } from '@lokalise/node-core';
import type { MakeRequired, MayOmit } from '@lokalise/universal-ts-utils/node';
import { type HandlerSpy, type HandlerSpyParams, type MessageMetricsManager, type MessageProcessingResult, type PublicHandlerSpy } from '@message-queue-toolkit/core';
import type { BaseOptions, Message } from '@platformatic/kafka';
import type { KafkaConfig, KafkaDependencies, SupportedMessageValues, TopicConfig } from './types.ts';
export type BaseKafkaOptions = {
kafka: KafkaConfig;
messageTypeField?: string;
messageIdField?: string;
/**
* The field in the message headers that contains the request ID.
* This is used to correlate logs and transactions with the request.
* Defaults to 'x-request-id'.
*/
headerRequestIdField?: string;
handlerSpy?: HandlerSpy<object> | HandlerSpyParams | boolean;
logMessages?: boolean;
} & Omit<BaseOptions, keyof KafkaConfig>;
type ProcessedMessage<TopicsConfig extends TopicConfig[]> = MayOmit<Pick<Message<string, SupportedMessageValues<TopicsConfig>, string, string>, 'topic' | 'value' | 'timestamp'>, 'timestamp'>;
export declare abstract class AbstractKafkaService<TopicsConfig extends TopicConfig[], KafkaOptions extends BaseKafkaOptions> {
protected readonly errorReporter: ErrorReporter;
protected readonly logger: CommonLogger;
protected readonly messageMetricsManager?: MessageMetricsManager<SupportedMessageValues<TopicsConfig>>;
protected readonly options: MakeRequired<KafkaOptions, 'messageIdField'>;
protected readonly _handlerSpy?: HandlerSpy<SupportedMessageValues<TopicsConfig>>;
constructor(dependencies: KafkaDependencies, options: KafkaOptions);
abstract init(): Promise<void>;
abstract close(): Promise<void>;
get handlerSpy(): PublicHandlerSpy<SupportedMessageValues<TopicsConfig>>;
protected resolveMessageType(message: SupportedMessageValues<TopicsConfig>): string | undefined;
protected resolveMessageId(message: SupportedMessageValues<TopicsConfig>): string | undefined;
protected resolveHeaderRequestIdField(): string;
protected handleMessageProcessed(params: {
message: ProcessedMessage<TopicsConfig>;
processingResult: MessageProcessingResult;
messageProcessingStartTimestamp: number;
}): void;
protected handlerError(error: unknown, context?: Record<string, unknown>): void;
}
export {};