kafkit-client 0.1.4

Kafka 4.0+ pure Rust client.
Documentation
# kafkit-client examples

These examples are real runnable programs for the `kafkit-client` crate.

## Order Workflow

`order_workflow` creates a topic if needed, produces several order events,
consumes them with a fresh consumer group, commits the consumed offsets, and
shuts the clients down cleanly.

Start Kafka 4.0+ locally, or use the repository compose setup:

```sh
docker compose -f examples/docker-compose.yml up kafka-1 kafka-2 kafka-3
```

Run the example from the repository root:

```sh
cargo run -p kafkit-client --example order_workflow
```

Environment variables:

- `KAFKIT_BOOTSTRAP_SERVERS`, default `localhost:9092`.
- `KAFKIT_TOPIC`, default `kafkit.orders`.
- `KAFKIT_GROUP_ID`, default is a unique group per run.

## WebSocket Broadcast

`websocket_broadcast` runs an HTTP/WebSocket server, creates a shared producer,
and starts a background Kafka consumer task. Inbound WebSocket messages are
produced to Kafka. The background consumer polls records, commits them,
serializes them as JSON, and broadcasts each record to every connected
WebSocket subscriber through a `tokio::sync::broadcast` channel.

Run the WebSocket server:

```sh
cargo run -p kafkit-client --example websocket_broadcast
```

Open the browser UI:

```text
http://127.0.0.1:8081
```

Or connect directly to the WebSocket endpoint:

```text
ws://127.0.0.1:8081/ws
```

Send JSON over the WebSocket to produce Kafka records:

```json
{
  "key": "browser-1",
  "value": "{\"source\":\"websocket\",\"status\":\"created\"}",
  "headers": {
    "source": "manual-client"
  }
}
```

Fields:

- `key`: optional record key.
- `value`: optional record value. Omit it or set it to `null` to produce a tombstone.
- `partition`: optional explicit partition.
- `headers`: optional string map of Kafka record headers.

You can also produce records from another terminal with the order workflow
example:

```sh
cargo run -p kafkit-client --example order_workflow
```

Environment variables:

- `KAFKIT_BOOTSTRAP_SERVERS`, default `localhost:9092`.
- `KAFKIT_TOPIC`, default `kafkit.orders`.
- `KAFKIT_GROUP_ID`, default `kafkit-websocket-broadcaster`.
- `KAFKIT_WS_BIND`, default `127.0.0.1:8081`.