Skip to content

Examples

Complete, working examples to help you get started with kafkats.

Basic Examples

ExampleDescription
Simple ProducerSend messages to Kafka
Consumer GroupRead messages with a consumer group

Stream Processing

ExampleDescription
Stream ProcessingBasic stream transformations
Word CountClassic word count with aggregation

Running the Examples

  1. Start Kafka locally:
bash
docker run -d --name kafka \
  -p 9092:9092 \
  -e KAFKA_CFG_NODE_ID=0 \
  -e KAFKA_CFG_PROCESS_ROLES=controller,broker \
  -e KAFKA_CFG_LISTENERS=PLAINTEXT://:9092,CONTROLLER://:9093 \
  -e KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT \
  -e KAFKA_CFG_CONTROLLER_QUORUM_VOTERS=0@localhost:9093 \
  -e KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER \
  -e KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://localhost:9092 \
  bitnami/kafka:latest
  1. Install dependencies:
bash
pnpm add @kafkats/client @kafkats/flow
  1. Run the example:
bash
npx tsx example.ts

Released under the MIT License.