Skip to main content

crabka_client_core/
lib.rs

1//! Connection management and request dispatch for Apache Kafka in Rust.
2//!
3//! This crate provides the first I/O-doing layer of Crabka. It wraps
4//! `crabka-protocol`'s typed request/response messages in a `tokio`-based
5//! TCP client that:
6//!
7//! - Opens one connection per broker, multiplexing requests via
8//!   correlation ID.
9//! - Negotiates API versions on connect.
10//! - Manages a [`BrokerPool`] keyed on broker id with lazy connect.
11//! - Resolves bootstrap addresses on builder.
12//!
13//! ## Quick start
14//!
15//! ```no_run
16//! use crabka_client_core::Client;
17//! use crabka_protocol::owned::api_versions_request::ApiVersionsRequest;
18//!
19//! # async fn run() -> Result<(), Box<dyn std::error::Error>> {
20//! let client = Client::builder()
21//!     .bootstrap("localhost:9092")
22//!     .client_id("my-app")
23//!     .build()
24//!     .await?;
25//!
26//! let resp = client.send(ApiVersionsRequest::default()).await?;
27//! println!("broker supports {} APIs", resp.api_keys.len());
28//!
29//! client.close();
30//! # Ok(())
31//! # }
32//! ```
33//!
34//! ## Scope and boundaries
35//!
36//! This crate is the shared transport and request-dispatch layer. It provides
37//! bootstrap resolution, API-version negotiation, broker-id connection pooling,
38//! typed request/response dispatch, low-level fetch helpers, and client-side
39//! TLS/SASL negotiation. Higher-level semantics — batching, idempotence,
40//! consumer-group heartbeats, commits, admin retries, and transactions — live in
41//! the producer, consumer, and admin crates built on top of this one.
42//!
43//! TLS / SASL: a client-side security surface lives in [`security`] and
44//! [`sasl`] — set [`ConnectionOptions::security`] (or the `Client`
45//! builder's `.security(...)`) to negotiate TLS then SASL before the
46//! API-versions bootstrap. `None` (the default) is plaintext.
47//!
48//! ## Cargo features
49//!
50//! - `mock` — exposes `MockBroker` beyond `#[cfg(test)]` for downstream
51//!   testing.
52
53mod bootstrap;
54mod client;
55mod connection;
56mod error;
57mod fetch;
58mod offset_for_leader_epoch;
59mod pool;
60mod request;
61pub mod sasl;
62pub mod security;
63mod transport;
64mod version;
65
66#[cfg(any(test, feature = "mock"))]
67mod mock;
68
69pub use client::{BrokerHandle, Client};
70pub use connection::{ClientDuplex, Connection, ConnectionOptions};
71pub use error::ClientError;
72pub use fetch::{FetchedRecord, fetch_partition, fetch_partition_with_isolation};
73pub use offset_for_leader_epoch::{EpochEndOffset, offset_for_leader_epoch};
74pub use pool::{BrokerInfo, BrokerPool};
75pub use request::ProtocolRequest;
76pub use sasl::{OutboundSaslError, SaslCredentials, outbound_sasl};
77pub use security::{ClientSecurity, TlsConnectorConfig};
78pub use version::ApiVersionTable;
79
80#[cfg(any(test, feature = "mock"))]
81pub use mock::MockBroker;