Principle:Fede1024 Rust rdkafka Mock Client Configuration
| Knowledge Sources | |
|---|---|
| Domains | Testing, Configuration |
| Last Updated | 2026-02-07 19:00 GMT |
Overview
A technique for configuring real Kafka clients to connect to a mock cluster by using its dynamically-assigned bootstrap servers.
Description
Mock Client Configuration bridges mock clusters with real producer/consumer clients. The mock cluster provides a bootstrap_servers() method that returns a CSV string of localhost:port addresses for the mock brokers. By passing this string to ClientConfig::set("bootstrap.servers", ...) real Kafka clients (FutureProducer, StreamConsumer, etc.) can connect to the mock cluster transparently.
This allows testing production code paths without modification — the only change is the bootstrap servers configuration value.
Usage
Use after creating a MockCluster to configure clients for testing. Call bootstrap_servers() and pass the result to ClientConfig::set("bootstrap.servers", ...).
Theoretical Basis
Pseudo-code logic:
// Abstract algorithm
bootstrap = cluster.bootstrap_servers() // "localhost:12345,localhost:12346"
producer = ClientConfig::new()
.set("bootstrap.servers", &bootstrap)
.create::<FutureProducer>()
// producer talks to mock cluster, not real Kafka