5 releases
0.1.4 | Oct 29, 2024 |
---|---|
0.1.3 | Oct 19, 2024 |
0.1.2 | Jul 28, 2024 |
0.1.1 | Jan 20, 2024 |
0.1.0 | Jan 14, 2024 |
#16 in #lua-bindings
261 downloads per month
29KB
621 lines
mlua-rdkafka
Lua bindings for the Rust based rdkafka.
Installing
Add to your Rust project using one of MLua's features: [lua51, lua52, lua53, lua54, luajit, luajit52].
$ cargo add mlua-rdkafka --features luajit
Using
use mlua::Lua;
use mlua_rdkafka;
let lua = Lua::new();
mlua_rdkafka::preload(&lua).unwrap();
let script = r#"
local rdkafka = require('rdkafka')
local ClientConfig, OwnedHeaders, FutureRecord = rdkafka.ClientConfig, rdkafka.OwnedHeaders, rdkafka.FutureRecord
-- prepare client
local client_config = ClientConfig:new()
:set('group.id', 'mygroup')
:set('bootstrap.servers', 'mybroker0:9092')
local future_producer = client_config:create_future_producer()
-- prepare record
local headers = OwnedHeaders:new():insert('abc', '123')
local record = FutureRecord:new():headers(headers)
-- send synchronously
return future_producer:send(record, 1.0)
"#;
let (partition, offset): (i32, i64) = lua.load(script).eval().unwrap();
Integration Testing
$ KAFKA_BROKERS=127.0.0.1:9092 KAFKA_TOPIC=abc cargo test --features luajit
Dependencies
~16–24MB
~310K SLoC