# Configuration
Configuration is split by client type:
- `ProducerConfig` for direct producer setup.
- `ConsumerConfig` for direct consumer and share-consumer setup.
- `AdminConfig` for admin operations.
- `KafkaClient` for shared bootstrap servers and topic-scoped builders.
- `TlsConfig` and `SaslConfig` for security settings.
The builder-style `KafkaClient` facade is convenient for application code. The
direct config types expose the same lower-level knobs when you need explicit
control.
## Bootstrap Servers
Use one bootstrap server for local development:
```rust,no_run
use kafkit_client::{KafkaProducer, ProducerConfig};
#[tokio::main]
async fn main() -> kafkit_client::Result<()> {
let producer = KafkaProducer::connect(ProducerConfig::new("localhost:9092")).await?;
producer.shutdown().await?;
Ok(())
}
```
For production, pass more than one bootstrap server:
```rust,no_run
use kafkit_client::KafkaClient;
#[tokio::main]
async fn main() -> kafkit_client::Result<()> {
let producer = KafkaClient::new("broker-a:9092")
.with_bootstrap_servers(["broker-a:9092", "broker-b:9092", "broker-c:9092"])
.topic("orders")
.producer()
.connect()
.await?;
producer.shutdown().await?;
Ok(())
}
```
## Producer Settings
Common producer options include:
- `with_client_id(...)`
- `with_acks(...)`
- `with_enable_idempotence(...)`
- `with_compression(...)`
- `with_batch_size(...)`
- `with_linger(...)`
- `with_delivery_timeout(...)`
- `with_request_timeout(...)`
- `with_retry_backoff(...)`
- `with_max_retries(...)`
- `with_transactional_id(...)`
Transactional and idempotent producers require `acks = -1`; the client returns
an error if those settings conflict.
## Consumer Settings
Common consumer options include:
- `with_client_id(...)`
- `with_auto_offset_reset(...)`
- `with_isolation_level(...)`
- `with_enable_auto_commit(...)`
- `with_auto_commit_interval(...)`
- `with_fetch_max_wait(...)`
- `with_fetch_min_bytes(...)`
- `with_fetch_max_bytes(...)`
- `with_partition_max_bytes(...)`
- `with_instance_id(...)`
- `with_rack_id(...)`
Consumers use the modern Kafka group protocol. Classic consumer group fallback
settings are not provided.
## Security Settings
TLS can be configured either through `TlsConfig` or through convenience methods
on each config type:
```rust,no_run
use kafkit_client::{KafkaAdmin, AdminConfig, TlsConfig};
#[tokio::main]
async fn main() -> kafkit_client::Result<()> {
let admin = KafkaAdmin::connect(
AdminConfig::new("kafka.example.com:9093").with_tls(
TlsConfig::new()
.with_ca_cert_path("/etc/ssl/certs/kafka-ca.pem")
.with_server_name("kafka.example.com"),
),
)
.await?;
let cluster = admin.describe_cluster().await?;
println!("cluster id: {}", cluster.cluster_id);
Ok(())
}
```
SASL helpers are available on producer, consumer, admin, and ergonomic builders:
- `with_sasl_plain(username, password)`
- `with_sasl_scram_sha_256(username, password)`
- `with_sasl_scram_sha_512(username, password)`