Skip to content

hitmands/kafka-producer-stub

Repository files navigation

@hitmands/kafka-producer-stub

Simple Kafka stack to facilitate the local development of Consumers

Getting Started

docker run -tid \
  -e 'HKPS_BROKERS=localhost:9092' \
  -v $(pwd)/examples:/data \
  hitmands/kafka-producer-stub:latest

Environment

  • HKPS_ prefix is used to namespace variables
HKPS_BROKERS='localhost:9092'

Producing Messages

// messages-provider.mjs

const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

const messages = ["Hello World", "Hello Galaxy", "Hello Universe"];

export async function* messenger() {
  while (messages.length) {
    await sleep(1000);

    const message = Buffer.from(messages.shift());

    // optional
    const options = { partition: null, key: null, ts: Date.now() };

    yield { topic: "stub-topic", message, options };
  }
}

Using the docker-compose of this repo

curl -sSL https://raw.githubusercontent.com/hitmands/kafka-producer-stub/main/docker-compose.yml > docker-compose.yml
docker-compose up -d