Files

76 lines
2.2 KiB
Markdown
Raw Permalink Normal View History

2026-06-28 20:33:48 -07:00
<p align="center"><img src=".github/hero.svg" alt="stream" width="880"></p>
2026-03-03 08:09:16 -08:00
# Hanzo Stream
2024-12-16 15:34:44 -06:00
2026-03-03 08:09:16 -08:00
Kafka wire protocol adapter for Hanzo PubSub (NATS JetStream). Accepts standard Kafka clients and translates requests to NATS underneath, allowing any Kafka producer/consumer to work against Hanzo infrastructure without code changes.
2024-12-16 15:34:44 -06:00
2026-03-03 08:09:16 -08:00
## Features
2024-12-24 12:17:21 -06:00
2026-03-03 08:09:16 -08:00
- Topic creation, produce, and consume via the Kafka binary protocol
- Cluster mode with Raft consensus and Serf membership
- Compression support
- Multiple log segments per partition
- Compatible with standard Kafka CLI tools and client libraries
2024-12-16 15:34:44 -06:00
2026-03-03 08:09:16 -08:00
## Quick Start
2024-12-16 15:34:44 -06:00
2026-03-03 08:09:16 -08:00
Start a single-node broker on port 9092:
2024-12-16 15:34:44 -06:00
2026-03-03 08:09:16 -08:00
```bash
go run main.go --bootstrap --node-id 1
```
2024-12-16 15:34:44 -06:00
2026-03-03 08:09:16 -08:00
Test with any Kafka client:
2024-12-24 12:17:21 -06:00
2026-03-03 08:09:16 -08:00
```bash
# Create topic
kafka-topics.sh --create --topic events --bootstrap-server localhost:9092
2024-12-16 15:34:44 -06:00
2026-03-03 08:09:16 -08:00
# Produce
kafka-console-producer.sh --bootstrap-server localhost:9092 --topic events
2024-12-16 15:34:44 -06:00
2026-03-03 08:09:16 -08:00
# Consume
kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic events --from-beginning
```
2024-12-16 15:34:44 -06:00
2026-03-03 08:09:16 -08:00
## Cluster Mode
2024-12-24 12:17:21 -06:00
2026-03-03 08:09:16 -08:00
Cluster mode uses Raft for distributed state and HashiCorp Serf for membership management.
2024-12-24 12:17:21 -06:00
2026-03-03 08:09:16 -08:00
```bash
# Bootstrap first node
2025-02-22 17:25:00 -06:00
go run main.go --bootstrap --node-id 1 --serf-addr 127.0.0.1:3331
2026-03-03 08:09:16 -08:00
# Join additional nodes
2025-02-22 17:25:00 -06:00
go run main.go --node-id 2 --broker-port 9093 --raft-addr localhost:2222 --serf-addr 127.0.0.1:3332 --serf-join "127.0.0.1:3331"
go run main.go --node-id 3 --broker-port 9094 --raft-addr localhost:2223 --serf-addr 127.0.0.1:3333 --serf-join "127.0.0.1:3331"
```
2026-03-03 08:09:16 -08:00
## Kubernetes
2024-12-29 11:35:14 -06:00
2026-03-03 08:09:16 -08:00
In Hanzo infrastructure, Stream runs as a deployment in the `hanzo` namespace and connects to NATS via `--pubsub-url nats://pubsub.hanzo.svc:4222`.
2024-12-29 11:35:14 -06:00
2026-03-03 08:09:16 -08:00
Two instances are typically deployed:
| Deployment | Service | Purpose |
|-----------|---------|---------|
| `insights-kafka` | `insights-kafka:9092` | Dedicated to Insights pipeline |
| `stream` | `stream:9092` | General purpose |
## Running Tests
Tests use Kafka CLI tools for end-to-end verification:
```bash
export KAFKA_BIN_DIR=/path/to/kafka_2.13-3.9.0/bin
go test -v ./...
2024-12-29 11:35:14 -06:00
```
2024-12-16 15:34:44 -06:00
2026-03-03 08:09:16 -08:00
## Credits
2024-12-24 12:17:21 -06:00
2026-03-03 08:09:16 -08:00
Based on [MonKafka](https://github.com/cefboud/monkafka) by cefboud. Cluster mode inspired by [Jocko](https://github.com/travisjeffery/jocko).
2024-12-16 15:34:44 -06:00
2026-03-03 08:09:16 -08:00
## License
MIT