5 个版本
0.0.5 | 2024 年 7 月 6 日 |
---|---|
0.0.4 | 2023 年 9 月 16 日 |
0.0.3 | 2023 年 7 月 23 日 |
0.0.2 | 2023 年 5 月 28 日 |
0.0.1 | 2023 年 5 月 27 日 |
#1890 在 网络编程
每月 126 次下载
48KB
1K SLoC
crab_kafka
将 <TCP|UDP> + TLS 流量转发到 kafka。
基于 tokio 和 rust rdkafka
基本用法
强烈建议使用替代分配器,如 MiMalloc
use std::collections::HashMap;
use mimalloc::MiMalloc;
use crab_kafka::{forwarder::ForwarderBuilder,Receiver,PartitionStrategies,CheckpointStrategies,TransformStrategies};
#[global_allocator]
static GLOBAL: MiMalloc = MiMalloc;
#[tokio::main]
async fn main() -> Result<(),String> {
ForwarderBuilder::default()
.receiver(Receiver::new_tcp_stream("127.0.0.1".to_owned(), "8888".to_owned(), 2000))
.checkpoint(CheckpointStrategies::OpenDoors)
.partition(PartitionStrategies::new_sticky_round_robin())
.transform(TransformStrategies::NoTransform)
.kafka_settings(HashMap::from([("bootstrap.servers".to_owned(),"broker:29091".to_owned())]))
.topic("test_topic".to_owned())
.cache_size(1000)
.stats_interval(10)
.build()
.unwrap()
.await
}
示例
依赖关系
~25–40MB
~623K SLoC