Skip to main content

Crate crabka_client_core

Crate crabka_client_core 

Source
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 BrokerPool keyed 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 — exposes MockBroker beyond #[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§

ApiVersionTable
BrokerHandle
A handle to a specific broker within a Client’s pool.
BrokerInfo
Information about a single Kafka broker, as reported by a MetadataResponse.
BrokerPool
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.
ConnectionOptions
Connect-time + per-request configuration knobs.
EpochEndOffset
One leader-epoch end-offset answer for a partition.
FetchedRecord
One record decoded from a single-partition fetch.

Enums§

ClientError
Errors returned by Client, Connection, and the broker pool.

Traits§

ClientDuplex
Trait alias for the duplex stream types Connection::from_stream accepts (TcpStream, tokio_rustls::client::TlsStream, etc.). Boxed so callers can hand in heterogeneous stream types via one path.
ProtocolRequest
Implemented by every generated Request struct in crabka-protocol.

Functions§

fetch_partition
Fetch up to partition_max_bytes from (topic, partition) starting at fetch_offset, decoding every v2 RecordBatch into FetchedRecords.
fetch_partition_with_isolation
Like fetch_partition, but lets the caller set the Kafka Fetch.isolation_level (0 = READ_UNCOMMITTED, 1 = READ_COMMITTED).
offset_for_leader_epoch
Send a single-partition OffsetForLeaderEpoch request. current_leader_epoch is the epoch the caller believes the partition is in (for fencing); leader_epoch is the epoch the caller wants the end offset of.