Lua bindings for Apache Kafka librdkafka library
apt install librdkafka-dev
brew install librdkafka
see https://github.com/edenhill/librdkafka
build with cmake or run luarocks install kafka
- producer(app_conf)
- consumer(app_conf)
- produce(topic, payload)
- poll(timeout_ms)
- flush(timeout_ms)
- delivery_failures() -- count of delivery failures since the last call (resets to 0)
- close()
local settings = {["bootstrap.servers"] = "localhost:9092"} local producer = require("kafka").producer(settings) for i = 1, 100 do print("send message " .. i) producer:produce("hello1", "Hello World! " .. i) producer:produce("hello2", i .. " Hello World!") end producer:poll(5000) producer:close()
- subscribe(...) // topics
- poll(timeout_ms)
- close()
local settings = {["bootstrap.servers"] = "localhost:9092", ["group.id"] = "1", ["auto.offset.reset"] = "earliest"} local consumer = require("kafka").consumer(settings) consumer:subscribe("hello1", "hello2") while true do local message = consumer:poll(1000) if message then print(string.format("recv message topic %s, partition %d, payload %s, key %s, offset %d", message.topic, message.partition, message.payload, message.key, message.offset)) end end
lua-kafka is released under the MIT License. See the LICENSE file for more information.
You can contact me by email: [email protected].