ts-reactivekafka
Typesafe & reactive Kafka Subjects made with Typescript, KafkaJS and RxJS.
Quickstart
npm i ts-reactivekafka
single consumer
;; ;
consumer group with dynamic import
; ;
The Code
The code follows a Singleton Pattern* in which an optional consumer and producer instance are made available given the respective consumer and producer configurations and given a general Kafka config. The consumer or producer instance is only instantiated when their respective configs are well-defined.
The only public methods for both instances are:
- getSubject() which returns the RxJs Subject (a multicasted observable)
- disconnect() which disconnects the Kafka consumer/producer and completes the subject
The subjects are typed as follows:
Since, in Typescript, no basic JSON type exists yet the value is typed as any. Otherwise value could have been typed as JSON | string
.
Reactive Operators
RxJs offers a vast range operators in which developers can construct fast & flexible functionally reactive programming constructs. A good overview of the operators can be found here:
Optimized module thanks to Vercel Ncc
Vercel's ncc provides NPM developers with the ultimate NPM module compilation toolkit:
- Publish minimal packages to npm
- Only ship relevant app code to serverless environments
- Don't waste time configuring bundlers
- Generally faster bootup time and less I/O overhead
- Compiled language-like experience (e.g.: go)
Sponsored by Charp
This package is used in production and maintained by the developers of Charp.