在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
参考网址:https://github.com/doujiang24/lua-resty-kafka
一、例子content_by_lua ' -- 引入lua所有api local cjson = require "cjson" local producer = require "resty.kafka.producer"
-- 定义kafka broker地址,ip需要和kafka的host.name配置一致 local broker_list = { { host = "192.168.101.223", port = 9092 }, { host = "192.168.101.224", port = 9092 } } local key = "key" local message = "halo world" local error_handle = function (topic, partition_id, queue, index, err, retryable) ngx.log(ngx.ERR, "failed to send to kafka, topic: ", topic, "; partition_id: ", partition_id, "; retryable: ", retryable) end
local p = producer:new(broker_list, { producer_type = "async", max_retry = 1, batch_num = 1, error_handle = error_handle })
local ok, err = p:send("test", key, message) if not ok then ngx.say("send err:", err) return end ngx.say("send ok:", ok) p:flush() '; 二、语法New
{ host = "192.168.101.223", port = 9092 }, { host = "192.168.101.224", port = 9092 } }
!!!以下为缓冲区参数,只有
Send
|
请发表评论