Skip to content

Latest commit

 

History

History
54 lines (36 loc) · 1.15 KB

README.md

File metadata and controls

54 lines (36 loc) · 1.15 KB

@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