dev/publisher
Generated page
Model gemma-mtp, commit ef58254ca7be, 2026-08-16, sources: 2. Edit the code or the hand-written documentation instead.
Diagram
PublisherConfig
Configuration parameters for broker connection, topic names, and simulation intervals via environment variables, as defined in Main.kt:177-200.
| Variable | Environment Variable | Default Value |
|---|---|---|
brokerHost | BOOBLIK_HOST | 127.0.0.1 |
brokerPort | BOOBLIK_PORT | 9092 |
topic | BOOBLIK_TOPIC | events |
intervalMillis | PUBLISH_INTERVAL_MILLIS | 1000 |
users | PUBLISH_USERS | 9 |
httpPort | HTTP_PORT | 8080 |
tasksTopic | BOOBLIK_TASKS_TOPIC | null |
taskIntervalMillis | TASK_INTERVAL_MILLIS | 700 |
openConnection
The retry mechanism used to establish a connection to the broker, ensuring the publisher waits for the broker to be ready, implemented in Main.kt:76-86.
publishForever
The main event loop that simulates user activity by hashing user keys to specific partitions and sending JSON payloads, found in Main.kt:88-108.
publishTasks
A secondary loop that sends tasks to a specific topic using a fixed partition to simulate a work queue, located in Main.kt:111-126.
Stats
Real-time monitoring of sent messages, partition distribution, last offsets, and task counts, managed by the Stats class in Main.kt:131-165.
embeddedServer
The HTTP interface providing health checks and JSON-serialized statistics via Ktor, initialized in Main.kt:58-64.
Key files
| File | Lines | What is there |
|---|---|---|
…/publisher/build.gradle.kts | 1-7 | Dependencies for the client, Ktor server, and serialization. |
…/publisher/Main.kt | 35-66 | The main entry point that orchestrates the connection, producers, and the server. |
Behaviour that Surprises
- The
publishForeverfunction usestopic.partitionFor(key)to determine the partition before sending, which is a stable pure function of the key, unlike round-robin partitioners that might advance a counter (Main.kt:97-101). - The
publishTasksfunction explicitly usesPartitionId(0)to ensure all tasks go into a single partition, preventing the splitting that would occur if it used a keyed partitioner (Main.kt:120-122). - The
openConnectionfunction uses an infinitewhile(true)loop to retry connection attempts until the broker is reachable, preventing startup race conditions (Main.kt:78-84).