ServerKafka

  
class ServerKafka extends Server {
  constructor(options: { postfixId?: string; client?: KafkaConfig; consumer?: ConsumerConfig; run?: Omit<ConsumerRunConfig, "eachBatch" | "eachMessage">; ... 6 more ...; producerOnlyMode?: boolean; })
  transportId: Transport.KAFKA
  protected logger: Logger
  protected client: Kafka | null
  protected consumer: Consumer | null
  protected producer: Producer | null
  protected parser: KafkaParser | null
  protected brokers: string[] | BrokersFunction
  protected clientId: string
  protected groupId: string
  protected options: Required<KafkaOptions>['options']
  listen(callback: (err?: unknown, ...optionalParams: unknown[]) => void): Promise<void>
  close(): Promise<void>
  start(callback: () => void): Promise<void>
  protected registerConsumerEventListeners()
  protected registerProducerEventListeners()
  createClient<T = any>(): T
  bindEvents(consumer: Consumer)
  getMessageHandler()
  getPublisher(replyTopic: string, replyPartition: string, correlationId: string): (data: any) => Promise<RecordMetadata[]>
  handleMessage(payload: EachMessagePayload)
  unwrap<T>(): T
  on<EventKey extends string | number | symbol = string | number | symbol, EventCallback = any>(event: EventKey, callback: EventCallback)
  sendMessage(message: OutgoingResponse, replyTopic: string, replyPartition: string, correlationId: string): Promise<RecordMetadata[]>
  assignIsDisposedHeader(outgoingResponse: OutgoingResponse, outgoingMessage: Message)
  assignErrorHeader(outgoingResponse: OutgoingResponse, outgoingMessage: Message)
  assignCorrelationIdHeader(correlationId: string, outgoingMessage: Message)
  assignReplyPartition(replyPartition: string, outgoingMessage: Message)
  handleEvent(pattern: string, packet: ReadPacket<any>, context: KafkaContext): Promise<any>
  protected initializeSerializer(options: { postfixId?: string; client?: KafkaConfig; consumer?: ConsumerConfig; run?: Omit<ConsumerRunConfig, "eachBatch" | "eachMessage">; ... 6 more ...; producerOnlyMode?: boolean; })
  protected initializeDeserializer(options: { postfixId?: string; client?: KafkaConfig; consumer?: ConsumerConfig; run?: Omit<ConsumerRunConfig, "eachBatch" | "eachMessage">; ... 6 more ...; producerOnlyMode?: boolean; })

  // inherited from nest/packages/microservices/Server
  transportId?: Transport | symbol
  protected messageHandlers: Map<string, MessageHandler>
  protected logger: LoggerService
  protected serializer: ConsumerSerializer
  protected deserializer: ConsumerDeserializer
  protected _status$: ReplaySubject<Status>
  status: Observable<Status>
  abstract on<EventKey extends keyof EventsMap = keyof EventsMap, EventCallback extends EventsMap[EventKey] = EventsMap[EventKey]>(event: EventKey, callback: EventCallback): any
  abstract unwrap<T>(): T
  abstract listen(callback: (...optionalParams: unknown[]) => any): any
  abstract close(): any
  addHandler(pattern: any, callback: MessageHandler<any, any, any>, isEventHandler: boolean = false, extras: Record<string, any> = {})
  getHandlers(): Map<string, MessageHandler>
  getHandlerByPattern(pattern: string): MessageHandler | null
  send(stream$: Observable<any>, respond: (data: WritePacket<any>) => void | Promise<unknown>): Subscription
  handleEvent(pattern: string, packet: ReadPacket<any>, context: BaseRpcContext<unknown[]>): Promise<any>
  transformToObservable(resultOrDeferred: any)
  getOptionsProp<Options extends MicroserviceOptions['options'], Attribute extends keyof Options, DefaultValue extends Options[Attribute] = Options[Attribute]>(obj: Options, prop: Attribute, defaultValue: DefaultValue = undefined as DefaultValue)
  protected handleError(error: string)
  protected loadPackage<T = any>(name: string, ctx: string, loader?: Function): T
  protected initializeSerializer(options: { url?: string; maxSendMessageLength?: number; maxReceiveMessageLength?: number; maxMetadataSize?: number; keepalive?: { keepaliveTimeMs?: number; keepaliveTimeoutMs?: number; keepalivePermitWithoutCalls?: number; http2MaxPingsWithoutData?: number; http2MinTimeBetweenPingsMs?: number; http2MinPingIntervalWithoutData...)
  protected initializeDeserializer(options: { url?: string; maxSendMessageLength?: number; maxReceiveMessageLength?: number; maxMetadataSize?: number; keepalive?: { keepaliveTimeMs?: number; keepaliveTimeoutMs?: number; keepalivePermitWithoutCalls?: number; http2MaxPingsWithoutData?: number; http2MinTimeBetweenPingsMs?: number; http2MinPingIntervalWithoutData...)
  protected getRouteFromPattern(pattern: string): string
  protected normalizePattern(pattern: MsPattern): string
}

Constructor


constructor(options: { postfixId?: string; client?: KafkaConfig; consumer?: ConsumerConfig; run?: Omit<ConsumerRunConfig, "eachBatch" | "eachMessage">; ... 6 more ...; producerOnlyMode?: boolean; })

Parameters

Option Type Description
options object

Properties

Property Description
transportId: Transport.KAFKA Read-only.
protected logger: Logger
protected client: Kafka | null
protected consumer: Consumer | null
protected producer: Producer | null
protected parser: KafkaParser | null
protected brokers: string[] | BrokersFunction
protected clientId: string
protected groupId: string
protected options: Required<KafkaOptions>['options'] Read-only. Declared in constructor.

Methods

listen()


listen(callback: (err?: unknown, ...optionalParams: unknown[]) => void): Promise<void>

Parameters

Option Type Description
callback (err?: unknown, ...optionalParams: unknown[]) => void

Returns

Promise<void>

close()


close(): Promise<void>

Parameters

There are no parameters.

Returns

Promise<void>

start()


start(callback: () => void): Promise<void>

Parameters

Option Type Description
callback () => void

Returns

Promise<void>

registerConsumerEventListeners()


protected registerConsumerEventListeners()

Parameters

There are no parameters.

registerProducerEventListeners()


protected registerProducerEventListeners()

Parameters

There are no parameters.

createClient()


createClient<T = any>(): T

Parameters

There are no parameters.

Returns

T

bindEvents()


bindEvents(consumer: Consumer)

Parameters

Option Type Description
consumer Consumer

getMessageHandler()


getMessageHandler()

Parameters

There are no parameters.

getPublisher()


getPublisher(replyTopic: string, replyPartition: string, correlationId: string): (data: any) => Promise<RecordMetadata[]>

Parameters

Option Type Description
replyTopic string
replyPartition string
correlationId string

Returns

(data: any) => Promise<RecordMetadata[]>

handleMessage()


handleMessage(payload: EachMessagePayload)

Parameters

Option Type Description
payload EachMessagePayload

unwrap()


unwrap<T>(): T

Parameters

There are no parameters.

Returns

T

on()


on<EventKey extends string | number | symbol = string | number | symbol, EventCallback = any>(event: EventKey, callback: EventCallback)

Parameters

Option Type Description
event EventKey
callback EventCallback

sendMessage()


sendMessage(message: OutgoingResponse, replyTopic: string, replyPartition: string, correlationId: string): Promise<RecordMetadata[]>

Parameters

Option Type Description
message OutgoingResponse
replyTopic string
replyPartition string
correlationId string

Returns

Promise<RecordMetadata[]>

assignIsDisposedHeader()


assignIsDisposedHeader(outgoingResponse: OutgoingResponse, outgoingMessage: Message)

Parameters

Option Type Description
outgoingResponse OutgoingResponse
outgoingMessage Message

assignErrorHeader()


assignErrorHeader(outgoingResponse: OutgoingResponse, outgoingMessage: Message)

Parameters

Option Type Description
outgoingResponse OutgoingResponse
outgoingMessage Message

assignCorrelationIdHeader()


assignCorrelationIdHeader(correlationId: string, outgoingMessage: Message)

Parameters

Option Type Description
correlationId string
outgoingMessage Message

assignReplyPartition()


assignReplyPartition(replyPartition: string, outgoingMessage: Message)

Parameters

Option Type Description
replyPartition string
outgoingMessage Message

handleEvent()


handleEvent(pattern: string, packet: ReadPacket<any>, context: KafkaContext): Promise<any>

Parameters

Option Type Description
pattern string
packet ReadPacket
context KafkaContext

Returns

Promise<any>

initializeSerializer()


protected initializeSerializer(options: { postfixId?: string; client?: KafkaConfig; consumer?: ConsumerConfig; run?: Omit<ConsumerRunConfig, "eachBatch" | "eachMessage">; ... 6 more ...; producerOnlyMode?: boolean; })

Parameters

Option Type Description
options object

initializeDeserializer()


protected initializeDeserializer(options: { postfixId?: string; client?: KafkaConfig; consumer?: ConsumerConfig; run?: Omit<ConsumerRunConfig, "eachBatch" | "eachMessage">; ... 6 more ...; producerOnlyMode?: boolean; })

Parameters

Option Type Description
options object