Skip to main content

API Reference

The exported surface of @nest-native/kafka. Everything below is imported from the package root.

Module

ExportKindNotes
KafkaModuleclassforRoot(options), forRootAsync(options), forFeature([HandlerClass]) — see Module.
KafkaModuleOptionsinterfaceOptions for forRoot.
KafkaModuleAsyncOptionsinterfaceOptions for forRootAsync.
KafkaConcurrencyOptionsinterfaceconcurrency and maxInFlight, shared by module / consumer / handler.

Consumer Decorators

ExportKindNotes
KafkaConsumerdecoratorClass-level: @KafkaConsumer(topic?, options?).
KafkaHandlerdecoratorMethod-level: @KafkaHandler(topic?, options?).
KafkaConsumerOptionsinterfacegroupId plus concurrency options.
KafkaHandlerOptionsinterfacebatch plus concurrency options.

See Consumers.

Parameter Decorators

ExportKindNotes
KafkaMessagedecoratorWhole payload, or one property with @KafkaMessage('prop').
KafkaHeadersdecoratorAll headers, or one with @KafkaHeaders('key').
KafkaCtxdecoratorThe raw KafkaContext.
KafkaBatchdecoratorThe raw KafkaConsumerBatch (batch handlers).
KafkaContextclassTransport context: getTopic(), getPartition(), getMessage(), getHeaders().
KafkaBatchContextclassBatch transport context.
KafkaMessageHeadersinterfaceThe header map shape.

See Parameter Decorators.

Producer

ExportKindNotes
KafkaProducerServiceclasssend, sendBatch, transactional.
InjectKafkaProducerdecoratorInject the raw KafkaDriverProducer.
KafkaTransactioninterfaceThe transaction handle passed to transactional.
KafkaSendRecordinterfaceA single send payload.
KafkaSendBatchinterfaceA sendBatch payload.
KafkaTransactionOffsetsinterfaceThe sendOffsets argument (Confluent shape).

See Producer and Transactions.

Error Mapping

ExportKindNotes
KafkaErrorMappertype(error, context) => KafkaErrorBehavior.
KafkaErrorBehaviortype'commit' | 'retry'.
defaultKafkaErrorMapperconstCommits 4xx client errors, retries the rest.
KafkaErrorContexttypeKafkaContext | KafkaBatchContext.

See Error Mapping.

Driver

ExportKindNotes
createConfluentDriverconstThe default driver factory; lazily loads the Confluent client.
KafkaClientDriverinterfaceThe driver contract.
KafkaDriverProducerinterfaceThe producer the driver exposes.
KafkaDriverConsumerinterfaceThe consumer the driver exposes.
KafkaDriverFactorytypedriverFactory option shape.

The driver is an advanced seam. Most applications never touch it directly.

Testing

ExportKindNotes
KafkaTestModuleclassIn-memory transport: forRoot, forRootAsync.
InMemoryKafkaBrokerclassThe loopback broker: emit, idle, getSent, getSentTo.
KAFKA_TEST_BROKERsymbolInjection token for the broker.
InjectKafkaTestBrokerdecoratorInject the broker.
createMockKafkaProducerfunctionRecording producer mock.
createMockTransactionfunctionRecording transaction mock.

See Testing. Import the testing utilities from the @nest-native/kafka/testing entrypoint — they are kept out of the package root so test scaffolding never enters a consumer's production import surface.