Expand description
Connection management and request dispatch for Apache Kafka in Rust.
This crate provides the first I/O-doing layer of Crabka. It wraps
crabka-protocol’s typed request/response messages in a tokio-based
TCP client that:
- Opens one connection per broker, multiplexing requests via correlation ID.
- Negotiates API versions on connect.
- Manages a
BrokerPoolkeyed on broker id with lazy connect. - Resolves bootstrap addresses on builder.
§Quick start
use crabka_client_core::Client;
use crabka_protocol::owned::api_versions_request::ApiVersionsRequest;
let client = Client::builder()
.bootstrap("localhost:9092")
.client_id("my-app")
.build()
.await?;
let resp = client.send(ApiVersionsRequest::default()).await?;
println!("broker supports {} APIs", resp.api_keys.len());
client.close();§Scope and boundaries
This crate is the shared transport and request-dispatch layer. It provides bootstrap resolution, API-version negotiation, broker-id connection pooling, typed request/response dispatch, low-level fetch helpers, and client-side TLS/SASL negotiation. Higher-level semantics — batching, idempotence, consumer-group heartbeats, commits, admin retries, and transactions — live in the producer, consumer, and admin crates built on top of this one.
TLS / SASL: a client-side security surface lives in security and
sasl — set ConnectionOptions::security (or the Client
builder’s .security(...)) to negotiate TLS then SASL before the
API-versions bootstrap. None (the default) is plaintext.
§Cargo features
mock— exposesMockBrokerbeyond#[cfg(test)]for downstream testing.
Re-exports§
pub use sasl::OutboundSaslError;pub use sasl::SaslCredentials;pub use sasl::outbound_sasl;pub use security::ClientSecurity;pub use security::TlsConnectorConfig;
Modules§
- sasl
- Transport-agnostic outbound SASL handshake for the client.
- security
- Client-side TLS/SASL security surface for
crate::Client.
Structs§
- ApiVersion
Table - Broker
Handle - A handle to a specific broker within a
Client’s pool. - Broker
Info - Information about a single Kafka broker, as reported by a
MetadataResponse. - Broker
Pool - Pool of
Arc<Connection>keyed by broker id. Connections are opened lazily on first use and cached thereafter. - Client
- A Kafka client backed by a
BrokerPool. - Connection
- A connection to a single Kafka broker.
- Connection
Options - Connect-time + per-request configuration knobs.
- Epoch
EndOffset - One leader-epoch end-offset answer for a partition.
- Fetched
Record - One record decoded from a single-partition fetch.
Enums§
- Client
Error - Errors returned by
Client,Connection, and the broker pool.
Traits§
- Client
Duplex - Trait alias for the duplex stream types
Connection::from_streamaccepts (TcpStream,tokio_rustls::client::TlsStream, etc.). Boxed so callers can hand in heterogeneous stream types via one path. - Protocol
Request - Implemented by every generated Request struct in
crabka-protocol.
Functions§
- fetch_
partition - Fetch up to
partition_max_bytesfrom(topic, partition)starting atfetch_offset, decoding every v2RecordBatchintoFetchedRecords. - fetch_
partition_ with_ isolation - Like
fetch_partition, but lets the caller set the KafkaFetch.isolation_level(0=READ_UNCOMMITTED,1=READ_COMMITTED). - offset_
for_ leader_ epoch - Send a single-partition
OffsetForLeaderEpochrequest.current_leader_epochis the epoch the caller believes the partition is in (for fencing);leader_epochis the epoch the caller wants the end offset of.