mlua-rdkafka

Crates.iomlua-rdkafka
lib.rsmlua-rdkafka
version0.1.4
sourcesrc
created_at2024-01-14 17:38:14.725391
updated_at2024-10-29 13:24:57.676442
descriptionLua bindings for rdkafka.
homepagehttps://on-prem.net
repositoryhttps://gitlab.com/megalithic-llc/mlua-rdkafka.git
max_upload_size
id1099592
size33,470
David Rauschenbach (drauschenbach)

documentation

README

mlua-rdkafka

Lua bindings for the Rust based rdkafka.

License Arch Lua

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
Commit count: 48

cargo fmt