Skip to main content
Deno 2 is finally here 🎉️
Learn more

kafkagosaur

deno module deno doc CI codecov

Kafkagosaur is a Kafka client for Deno built using WebAssembly. The project binds to the kafka-go library.

Supported features

  • Writer
  • Reader
  • SASL
  • TLS
  • TCP
  • UDP
  • Deno streams

Examples

For comprehensive examples on how to use kafkagosaur, head over to the provided examples.

KafkaWriter

To write a message, make use of the KafkaWriter object on the KafkaGoSaur instance:

const kafkaGoSaur = new KafkaGoSaur();
const writer = await kafkaGoSaur.writer({
  broker: "localhost:9092",
  topic: "test-0",
});

const enc = new TextEncoder();
const msgs = [{ value: enc.encode("value") }];

await writer.writeMessages(msgs);

KafkaReader

To read a message, make use of the KafkaReader object on the KafkaGoSaur instance:

const kafkaGoSaur = new KafkaGoSaur();
const reader = await kafkaGoSaur.reader({
  brokers: ["localhost:9092"],
  topic: "test-0",
});

const readMsg = await reader.readMessage();

Provided examples

To run the provided examples, ensure you have docker up and running. Then start the kafka broker using

make docker

To run the writer example

deno run --allow-read --allow-net --unstable examples/writer.ts

To run the reader example

deno run --allow-read --allow-net --unstable examples/reader.ts

Documentation

While the documentation is a work in progress, please see the documentation of the kafka-go project on how to use kafkagosaur. Kafkagosaur tries to follow the API of kafka-go closely.

Development

To build the WebAssembly module, first run

make build-wasm

To run the tests, ensure first you have docker up and running. Then start the kafka broker using

make docker-up

Then run

make test

Performance benchmarks

The Deno benchmarks are located in bench and can be run via

deno run --allow-read --allow-net --allow-env --unstable bench/reader.ts
deno run --allow-read --allow-net --allow-env --unstable bench/writer.ts

Results

bench
kafkagosaur1 kafka-go2
writeMessages3 3977 ± 244 4678 ± 207
readMessage 1963 ± 190 2784 ± 374

Environment

Contributing

Kafkgagosaur is in early stage of development. Nevertheless your contributions are highly valued and welcomed! Feel free to ask for new features, report bugs, or submit your code.

Footnotes

  1. Using the DialBackend.Node.

  2. Using a single goroutine.

  3. Batching 10.000 messages.