booblik
Wiki

dev/relay

Generated page

Model gemma-mtp, commit f508a4b65b3f, 2026-08-15, sources: 3. Edit the code or the hand-written documentation instead.

Diagram

Directional modes

The relay operates in one of two modes defined in Main.kt:83-86:

ModeDescriptionPosition Ownership
KAFKA_TO_BOOBLIKMoves data from Kafka to booblikManaged by Kafka via Consumer Groups (Directions.kt:46)
BOOBLIK_TO_KAFKAMoves data from booblik to KafkaManaged locally via FileOffsetStore (Directions.kt:93)

More: Directional modes

booblikToKafka

This mode consumes data from booblik and produces it to Kafka. Because the booblik broker does not remember reader positions, the relay uses a FileOffsetStore to manage state locally on the relay's volume (Directions.kt:93). To ensure at-least-once delivery, the producer is configured with acks=all (Directions.kt:102).

More: booblikToKafka

At-least-once delivery guarantees

The relay implements at-least-once delivery by ensuring the position is only updated after the destination has acknowledged the data. In kafkaToBooblik, consumer.commitSync() is called only after all records in a batch are sent to booblik (Directions.kt:71). In booblikToKafka, the checkpointing mechanism saves the position only after the kafka.flush() operation is complete (Directions.kt:119).

RelayStats

The monitoring surface is exposed via an HTTP server and provides real-time metrics through the Stats class (Main.kt:88). The RelayStats data class (Main.kt:129) includes:

  • relayed: Total count of relayed records.
  • batches: Total number of batches processed.
  • position: The last observed offset/position.
  • restarts: Number of times the relay loop has restarted due to failures.
  • lastFailure: The message of the last encountered exception.
  • lastRecord: A 120-character sample of the last record.

RelayConfig

The relay is configured via environment variables as defined in Main.kt:142-176. The following parameters are available:

ParameterEnvironment VariableDefault Value
nameRELAY_NAMErelay
directionRELAY_DIRECTIONKAFKA_TO_BOOBLIK
brokerHostBOOBLIK_HOST127.0.0.1
brokerPortBOOBLIK_PORT9092
booblikTopicBOOBLIK_TOPICmirrored
kafkaBootstrapKAFKA_BOOTSTRAPkafka:9092
kafkaTopicKAFKA_TOPICorders
kafkaGroupKAFKA_GROUPbooblik-relay
stateDirSTATE_DIR/var/lib/relay
httpPortHTTP_PORT8080

Key files

FileLinesWhat is there
…/relay/build.gradle.kts1-9Dependencies for Kafka, Ktor, and Booblik client.
…/relay/Directions.kt38-77Implementation of the kafkaToBooblik function.
…/relay/Directions.kt89-124Implementation of the booblikToKafka function.
…/relay/Main.kt47-81The main entry point and the execution loop.
…/relay/Main.kt88-127The Stats class for tracking relay metrics.
…/relay/Main.kt142-176The RelayConfig data class and environment loading logic.

Behaviour that surprise

  • The kafkaToBooblik function uses consumer.commitSync() (Directions.kt:71) to ensure that a crash between sending data and committing the offset results in a repeated batch rather than data loss.
  • The booblikToKafka function requires an explicit kafka.flush() (Directions.kt:119) before the checkpointing mechanism updates the local FileOffsetStore to maintain delivery guarantees.
  • The main function (Main.kt:47) uses a while(true) loop with a try-catch block to ensure that the relay automatically restarts if a connection to either Kafka or booblik is lost.

More

On this page