开源软件名称(OpenSource Name):doujiang24/lua-resty-kafka开源软件地址(OpenSource Url):https://github.com/doujiang24/lua-resty-kafka开源编程语言(OpenSource Language):Lua 60.2%开源软件介绍(OpenSource Introduction):Namelua-resty-kafka - Lua kafka client driver for the ngx_lua based on the cosocket API Table of Contents
StatusThis library is still under early development and is still experimental. DescriptionThis Lua library is a Kafka client driver for the ngx_lua nginx module: http://wiki.nginx.org/HttpLuaModule This Lua library takes advantage of ngx_lua's cosocket API, which ensures 100% nonblocking behavior. Note that at least ngx_lua 0.9.3 or openresty 1.4.3.7 is required, and unfortunately only LuaJIT supported ( Note for Synopsis lua_package_path "/path/to/lua-resty-kafka/lib/?.lua;;";
server {
location /test {
content_by_lua '
local cjson = require "cjson"
local client = require "resty.kafka.client"
local producer = require "resty.kafka.producer"
local broker_list = {
{
host = "127.0.0.1",
port = 9092,
-- optional auth
sasl_config = {
mechanism = "PLAIN",
user = "USERNAME",
password = "PASSWORD",
},
},
}
local key = "key"
local message = "halo world"
-- usually we do not use this library directly
local cli = client:new(broker_list)
local brokers, partitions = cli:fetch_metadata("test")
if not brokers then
ngx.say("fetch_metadata failed, err:", partitions)
end
ngx.say("brokers: ", cjson.encode(brokers), "; partitions: ", cjson.encode(partitions))
-- sync producer_type
local p = producer:new(broker_list)
local offset, err = p:send("test", key, message)
if not offset then
ngx.say("send err:", err)
return
end
ngx.say("send success, offset: ", tonumber(offset))
-- this is async producer_type and bp will be reused in the whole nginx worker
local bp = producer:new(broker_list, { producer_type = "async" })
local ok, err = bp:send("test", key, message)
if not ok then
ngx.say("send err:", err)
return
end
ngx.say("send success, ok:", ok)
';
}
} Modulesresty.kafka.clientTo load this module, just do this local client = require "resty.kafka.client" Methodsnew
The [
{
"host": "127.0.0.1",
"port": 9092,
// optional auth
"sasl_config": {
"mechanism": "PLAIN",
"user": "USERNAME",
"password": "PASSWORD"
}
}
] An optional client config
fetch_metadata
In case of success, return the all brokers and partitions of the refresh
This will refresh the metadata of all topics which have been fetched by choose_api_version
This helps the client to select the correct version of the When Tip: The version selection strategy is to choose the maximum version within the allowed range. resty.kafka.producerTo load this module, just do this local producer = require "resty.kafka.producer" Methodsnew
It's recommend to use async producer_type.
An optional options table can be specified. The following options are as follows:
producer config, most like in http://kafka.apache.org/documentation.html#producerconfigs
buffer config ( only work
Not support compression now. The third optional send
offset
flush
Always return resty.kafka.basic-consumerTo load this module, just do this local bconsumer = require "resty.kafka.basic-consumer" This module is a minimalist implementation of a consumer, providing the In a single call, only the information of a single partition in a single topic can be fetched, and batch fetching is not supported for now. The basic consumer does not support the consumer group related API, so you need to fetch the message after getting the offset through the Methodsnew
The [
{
"host": "127.0.0.1",
"port": 9092,
// optional auth
"sasl_config": {
"mechanism": "PLAIN",
"user": "USERNAME",
"password": "PASSWORD"
}
}
] An optional client config
list_offset
The parameter timestamp can be a UNIX timestamp or a constant defined in In case of success, return the offset of the specified case.
In case of errors, returns fetch
In case of success, return the following The
ErrorsWhen you call the modules provided in this library, you may get some errors. Depending on the source, they can be divided into the following categories.
InstallationYou need to configure the lua_package_path directive to add the path of your lua-resty-kafka source tree to ngx_lua's LUA_PATH search path, as in # nginx.conf
http {
lua_package_path "/path/to/lua-resty-kafka/lib/?.lua;;";
...
} Ensure that the system account running your Nginx ''worker'' proceses have
enough permission to read the TODO
AuthorDejiang Zhu (doujiang24) doujiang24@gmail.com. Copyright and LicenseThis module is licensed under the BSD license. Copyright (C) 2014-2020, by Dejiang Zhu (doujiang24) doujiang24@gmail.com. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. See Also
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论