Skip to main content

Crate kafka_client

Crate kafka_client 

Source
Expand description

Kafka Rust Client

A pure Rust Kafka client library based on Tokio async runtime. Supports SASL authentication (PLAIN, SCRAM-SHA-256, SCRAM-SHA-512, GSSAPI/Kerberos) and TLS encryption.

§Quick Start

use kafka_client::Client;

// Create client — connects to cluster, discovers all brokers
let client = Client::builder(vec!["localhost:9092".into()])
    .with_plaintext()
    .build()
    .await?;

// Producer — send messages
let producer = client.producer_default().await;
producer.send(ProducerRecord::new("my-topic", b"hello".into())).await?;

// Consumer — read messages
let mut consumer = client.consumer_default();
consumer.subscribe(vec!["my-topic".into()]).await?;
let records = consumer.poll().await?;

client.close().await?;

§Advanced Configuration

// Custom producer config
let producer = client.producer(
    ProducerConfig::new().with_acks(-1).with_retries(3)
).await;

// Consumer with group coordination  
let mut consumer = client.consumer(
    ConsumerConfig::new("my-group").with_earliest()
);

Re-exports§

pub use transport::SecurityProtocol;
pub use transport::TlsConfig;
pub use kafka_client_protocol as protocol;

Modules§

admin
Admin client — cluster management and inspection.
connection
Connection layer — TCP/TLS connection management with Kafka protocol
transport

Structs§

Client
Unified Kafka client.
ClientBuilder
Builder for constructing a Client.
ClientConfig
Declarative configuration for creating a Client.
Consumer
ConsumerConfig
Kafka consumer configuration.
ConsumerRecord
ConsumerStream
A streaming wrapper that yields individual ConsumerRecord values.
GroupHandle
Header
Message header
KafkaErrorCode
Kafka 协议错误码,对应 Kafka 协议规范中定义的错误码。
KerberosCredentials
Kerberos credentials model (distinct from SASL username/password).
MetadataCache
Metadata cache with TTL-based expiry and O(1) partition leader lookup.
OffsetHandle
PartitionRouter
Partition router (cloneable for concurrent access)
Producer
High-level Kafka Producer.
ProducerConfig
ProducerRecord
Producer record
RecordMetadata
Send metadata
SaslCredentials
SASL credentials.

Enums§

AutoOffsetReset
KafkaError
KerberosError
Errors returned by Kerberos / GSS-API operations.
PartitionAssignmentStrategy
PartitionRouting
Partition routing strategy
SaslMechanismType
SASL mechanism type.

Constants§

NAME
Library name
VERSION
Library version

Traits§

GssContext
Kerberos GSS-API (krb5 mechanism) authentication context.

Functions§

builder
Convenience builder function — equivalent to Client::builder(...).

Type Aliases§

Result