API
#github.com/xulang-org/packages/kafka
Xu 0.8.8 API
import: kafka #github.com/xulang-org/packages/kafka
counts: 29 fns, 17 methods, 3 types, 0 consts, 0 ifaces
Apache Kafka High-Performance Distributed Event Streaming Driver for Xu Features Pure native Kafka Wire Protocol implementation (TCP socket + Big-Endian framing). IEEE CRC32 message verification via standard library #hash/crc32. High-throughput Produce & Fetch operations with partition targeting. Heartbeat probe via ApiVersions & Metadata APIs. Connection pooling via reusable TCP socket channels. Full compatibility with Apache Kafka 2.x, 3.x, and 4.x (KRaft & ZooKeeper modes).
github.com/xulang-org/packages · 0.1.1 · Install and use
open
pub fn open(broker string) Client
Purpose
Apache Kafka High-Performance Distributed Event Streaming Driver for Xu Features Pure native Kafka Wire Protocol implementation (TCP socket + Big-Endian framing). IEEE CRC32 message verification via standard library #hash/crc32. High-throughput Produce & Fetch operations with partition targeting. Heartbeat probe via ApiVersions & Metadata APIs. Connection pooling via reusable TCP socket channels. Full compatibility with Apache Kafka 2.x, 3.x, and 4.x (KRaft & ZooKeeper modes). Throws on failure.
Parameters
broker string- broker (string)
Returns
Client — a value of this type
open_client
pub fn open_client(broker string, client_id string) Client
Purpose
Open client. Throws on failure.
Parameters
broker string- broker (string)
client_id string- client_id (string)
Returns
Client — a value of this type
open_pool_client
pub fn open_pool_client(broker string, client_id string, max_idle int) Pool
Purpose
Open pool client.
Parameters
broker string- broker (string)
client_id string- client_id (string)
max_idle int- max_idle (int)
Returns
Pool — a value of this type
struct Client
pub struct Client {
pub fd int
pub broker string
pub client_id string
pub next_correlation_id int
}
Purpose
Public struct `Client`.
Parameters
fd int- file descriptor
broker string- field (string)
client_id string- field (string)
next_correlation_id int- field (int)
(&mut Client) write_exact
pub fn (c &mut Client) write_exact(data string) int
Purpose
Method on `&mut Client`: write exact. Throws on failure.
Parameters
c &mut Client- receiver &mut Client (exclusive borrow)
data string- data (string)
Returns
int — a value of this type
(&mut Client) read_exact
pub fn (c &mut Client) read_exact(n int) string
Purpose
Method on `&mut Client`: read exact. Throws on failure.
Parameters
c &mut Client- receiver &mut Client (exclusive borrow)
n int- count, length, or limit (int)
Returns
string — result string
(&mut Client) round_trip
pub fn (c &mut Client) round_trip(req_bytes string) string
Purpose
Method on `&mut Client`: round trip. Throws on failure.
Parameters
c &mut Client- receiver &mut Client (exclusive borrow)
req_bytes string- req_bytes (string)
Returns
string — result string
connect
pub fn connect(broker string, client_id string) Client
Purpose
connect; returns Client. Throws on failure.
Parameters
broker string- broker (string)
client_id string- client_id (string)
Returns
Client — a value of this type
(&mut Client) ping
pub fn (c &mut Client) ping() bool
Purpose
Call `ping` on `&mut Client`.
Parameters
c &mut Client- receiver &mut Client (exclusive borrow)
Returns
bool — true or false
(&mut Client) metadata
pub fn (c &mut Client) metadata(topic string) bool
Purpose
Call `metadata` on `&mut Client`.
Parameters
c &mut Client- receiver &mut Client (exclusive borrow)
topic string- topic (string)
Returns
bool — true or false
(&mut Client) produce
pub fn (c &mut Client) produce(topic string, partition int, message string) int
Purpose
Call `produce` on `&mut Client`.
Parameters
c &mut Client- receiver &mut Client (exclusive borrow)
topic string- topic (string)
partition int- partition (int)
message string- message (string)
Returns
int — a value of this type
(&mut Client) produce_key_value
pub fn (c &mut Client) produce_key_value(topic string, partition int, key string, val string) int
Purpose
Method on `&mut Client`: produce key value. Throws on failure.
Parameters
c &mut Client- receiver &mut Client (exclusive borrow)
topic string- topic (string)
partition int- partition (int)
key string- key (string)
val string- value (string)
Returns
int — a value of this type
(&mut Client) fetch
pub fn (c &mut Client) fetch(topic string, partition int, offset int) []string
Purpose
Call `fetch` on `&mut Client`. Throws on failure.
Parameters
c &mut Client- receiver &mut Client (exclusive borrow)
topic string- topic (string)
partition int- partition (int)
offset int- offset (int)
Returns
[]string — slice result
(&mut Client) close
pub fn (c &mut Client) close()
Purpose
Method on `&mut Client`: close the resource.
Parameters
c &mut Client- receiver &mut Client (exclusive borrow)
struct Pool
pub struct Pool {
pub broker string
pub client_id string
pub idle chan int
pub max_idle int
}
Purpose
Connection Pool for Apache Kafka. Manages reusable TCP socket connections via a scalar channel.
Parameters
broker string- field (string)
client_id string- field (string)
idle chan int- field (channel; type chan int)
max_idle int- field (int)
new_pool
pub fn new_pool(broker string, client_id string, max_idle int) Pool
Purpose
Construct pool.
Parameters
broker string- broker (string)
client_id string- client_id (string)
max_idle int- max_idle (int)
Returns
Pool — a value of this type
open_pool
pub fn open_pool(broker string, client_id string, max_idle int) Pool
Purpose
Open pool.
Parameters
broker string- broker (string)
client_id string- client_id (string)
max_idle int- max_idle (int)
Returns
Pool — a value of this type
(&Pool) get
pub fn (p &Pool) get() Client
Purpose
Call `get` on `&Pool`. Throws on failure.
Parameters
p &Pool- receiver &Pool (borrow)
Returns
Client — a value of this type
(&Pool) ping
pub fn (p &Pool) ping() bool
Purpose
Call `ping` on `&Pool`.
Parameters
p &Pool- receiver &Pool (borrow)
Returns
bool — true or false
(&Pool) produce
pub fn (p &Pool) produce(topic string, partition int, message string) int
Purpose
Call `produce` on `&Pool`. Throws on failure.
Parameters
p &Pool- receiver &Pool (borrow)
topic string- topic (string)
partition int- partition (int)
message string- message (string)
Returns
int — a value of this type
(&Pool) produce_key_value
pub fn (p &Pool) produce_key_value(topic string, partition int, key string, val string) int
Purpose
Method on `&Pool`: produce key value. Throws on failure.
Parameters
p &Pool- receiver &Pool (borrow)
topic string- topic (string)
partition int- partition (int)
key string- key (string)
val string- value (string)
Returns
int — a value of this type
(&Pool) fetch
pub fn (p &Pool) fetch(topic string, partition int, offset int) []string
Purpose
Call `fetch` on `&Pool`. Throws on failure.
Parameters
p &Pool- receiver &Pool (borrow)
topic string- topic (string)
partition int- partition (int)
offset int- offset (int)
Returns
[]string — slice result
(&Pool) put_conn
pub fn (p &Pool) put_conn(fd int)
Purpose
Method on `&Pool`: put connection.
Parameters
p &Pool- receiver &Pool (borrow)
fd int- file descriptor (int)
(&Pool) put
pub fn (p &Pool) put(c Client)
Purpose
Call `put` on `&Pool`.
Parameters
p &Pool- receiver &Pool (borrow)
c Client- byte or character code (Client)
(&Pool) close
Purpose
Method on `&Pool`: close the resource.
Parameters
p &Pool- receiver &Pool (borrow)
encode_i8
pub fn encode_i8(v int) string
Purpose
Big-Endian encoders for Kafka protocol primitives
Parameters
v int- value (int)
Returns
string — result string
encode_i16
pub fn encode_i16(v int) string
Purpose
Encode.
Parameters
v int- value (int)
Returns
string — result string
encode_i32
pub fn encode_i32(v int) string
Purpose
Encode.
Parameters
v int- value (int)
Returns
string — result string
encode_i64
pub fn encode_i64(v int) string
Purpose
Encode.
Parameters
v int- value (int)
Returns
string — result string
encode_string
pub fn encode_string(s string) string
Purpose
Encode.
Parameters
s string- source string (string)
Returns
string — result string
encode_null_string
pub fn encode_null_string() string
Purpose
Encode.
Parameters
none
Returns
string — result string
encode_bytes
pub fn encode_bytes(b string) string
Purpose
Encode.
Parameters
b string- b (string)
Returns
string — result string
encode_null_bytes
pub fn encode_null_bytes() string
Purpose
Encode.
Parameters
none
Returns
string — result string
encode_zigzag_i32
pub fn encode_zigzag_i32(n int) string
Purpose
Zigzag + Varint encoder for Kafka Record v2
Parameters
n int- count, length, or limit (int)
Returns
string — result string
encode_zigzag_i64
pub fn encode_zigzag_i64(n int) string
Purpose
Encode.
Parameters
n int- count, length, or limit (int)
Returns
string — result string
struct VarintResult
pub struct VarintResult {
pub value int
pub bytes_read int
}
Purpose
Public struct `VarintResult`.
Parameters
value int- field (int)
bytes_read int- field (int)
decode_varint
pub fn decode_varint(s &string, off int) VarintResult
Purpose
Decode.
Parameters
s &string- source string (borrowed; caller keeps it; type &string)
off int- offset (int)
Returns
VarintResult — a value of this type
decode_zigzag
pub fn decode_zigzag(s &string, off int) VarintResult
Purpose
Decode.
Parameters
s &string- source string (borrowed; caller keeps it; type &string)
off int- offset (int)
Returns
VarintResult — a value of this type
decode_i16
pub fn decode_i16(s &string, off int) int
Purpose
Big-Endian decoders
Parameters
s &string- source string (borrowed; caller keeps it; type &string)
off int- offset (int)
Returns
int — a value of this type
decode_i32
pub fn decode_i32(s &string, off int) int
Purpose
Decode.
Parameters
s &string- source string (borrowed; caller keeps it; type &string)
off int- offset (int)
Returns
int — a value of this type
decode_i64
pub fn decode_i64(s &string, off int) int
Purpose
Decode.
Parameters
s &string- source string (borrowed; caller keeps it; type &string)
off int- offset (int)
Returns
int — a value of this type
build_request
pub fn build_request(api_key int, api_version int, correlation_id int, client_id string, body string) string
Purpose
Request Framer: [Length (INT32)] [Header (ApiKey, ApiVersion, CorrelationID, ClientID)] [Body]
Parameters
api_key int- api_key (int)
api_version int- api_version (int)
correlation_id int- correlation_id (int)
client_id string- client_id (string)
body string- body (string)
Returns
string — result string
build_record_batch
pub fn build_record_batch(key string, val string) string
Purpose
Build RecordBatch (Magic = 2) for Kafka 0.11+ / 2.x / 3.x / 4.x
Parameters
key string- key (string)
val string- value (string)
Returns
string — result string
build_produce_request
pub fn build_produce_request(correlation_id int, client_id string, topic string, partition int, key string, val string) string
Purpose
Produce Request (ApiKey 0, Version 3)
Parameters
correlation_id int- correlation_id (int)
client_id string- client_id (string)
topic string- topic (string)
partition int- partition (int)
key string- key (string)
val string- value (string)
Returns
string — result string
build_fetch_request
pub fn build_fetch_request(correlation_id int, client_id string, topic string, partition int, offset int) string
Purpose
Fetch Request (ApiKey 1, Version 4)
Parameters
correlation_id int- correlation_id (int)
client_id string- client_id (string)
topic string- topic (string)
partition int- partition (int)
offset int- offset (int)
Returns
string — result string
build_metadata_request
pub fn build_metadata_request(correlation_id int, client_id string, topic string) string
Purpose
Metadata Request (ApiKey 3, Version 0)
Parameters
correlation_id int- correlation_id (int)
client_id string- client_id (string)
topic string- topic (string)
Returns
string — result string
build_apiversions_request
pub fn build_apiversions_request(correlation_id int, client_id string) string
Purpose
ApiVersions Request (ApiKey 18, Version 0)
Parameters
correlation_id int- correlation_id (int)
client_id string- client_id (string)
Returns
string — result string
parse_produce_response
pub fn parse_produce_response(resp string) int
Purpose
Parse Produce Response v3 Throws on failure.
Parameters
resp string- resp (string)
Returns
int — a value of this type
parse_fetch_response
pub fn parse_fetch_response(resp string) []string
Purpose
Parse Fetch Response v4 Throws on failure.
Parameters
resp string- resp (string)
Returns
[]string — slice result