lua-resty-nsq
基于 cosocket API 的 ngx_lua Lua nsq 客户端驱动
$ opm get rainingmaster/lua-resty-nsq
名称
lua-resty-nsq - 基于 cosocket API 的 ngx_lua Lua nsq 客户端驱动
状态
[!构建状态](https://www.travis-ci.org/rainingmaster/lua-resty-nsq)
此库正在开发中。
描述
此 Lua 库是 ngx_lua nginx 模块的 NSQ 客户端驱动程序
此 Lua 库利用了 ngx_lua 的 cosocket API,确保了 100% 的非阻塞行为。
概要
lua_package_path "/path/to/lua-resty-nsq/lib/?.lua;;";
server {
location /test {
content_by_lua_block {
local config = {
read_timeout = 3,
heartbeat = 1,
}
local producer = require "resty.nsq.producer"
local consumer = require "resty.nsq.consumer"
local cons = consumer:new()
local prod = producer:new()
local ok, err = cons:connect("127.0.0.1", 4150, config)
if not ok then
ngx.say("failed to connect: ", err)
return
end
local ok, err = prod:connect("127.0.0.1", 4150)
if not ok then
ngx.say("failed to connect: ", err)
return
end
ok, err = prod:pub("new_topic", "hellow world!")
if not ok then
ngx.say("failed to pub: ", err)
return
end
ok, err = prod:close()
if not ok then
ngx.say("failed to close: ", err)
return
end
ok, err = cons:sub("new_topic", "new_channel")
if not ok then
ngx.say("failed to sub: ", err)
return
end
local function read(c)
c:rdy(10)
local ret = cons:message()
ngx.say("sub success: ", require("cjson").encode(ret))
end
local co = ngx.thread.spawn(read, cons) -- read message in new thread
ngx.thread.wait(co)
ok, err = cons:close()
if not ok then
ngx.say("failed to close: ", err)
return
end
}
}
}
模块
resty.nsq.producer
方法
new
pub
resty.nsq.consumer
方法
new
安装
export LUA_LIB_DIR=/path/to/lualib && make install
待办事项
版权和许可证
此模块根据 BSD 许可证授权。
版权所有 (C) 2018-2018,rainingmaster。
保留所有权利。
在满足以下条件的情况下,允许以源代码和二进制形式重新分发和使用,无论是否修改。
源代码的重新分发必须保留上述版权声明、此条件列表和以下免责声明。
二进制形式的重新分发必须在随分发提供的文档和/或其他材料中复制上述版权声明、此条件列表和以下免责声明。
本软件由版权所有者和贡献者“按原样”提供,并且不提供任何明示或暗示的保证,包括但不限于适销性和特定用途适用性的暗示保证。在任何情况下,版权所有者或贡献者均不对任何直接、间接、偶然、特殊、惩罚性或后果性损害(包括但不限于替代商品或服务的采购;使用、数据或利润损失;或业务中断)负责,无论这些损害是如何造成的以及基于何种责任理论,无论是合同、严格责任或侵权行为(包括疏忽或其他原因),即使已被告知此类损害的可能性。
另请参阅
ngx_lua 模块:https://github.com/openresty/lua-nginx-module/#readme
nsq 有线协议规范:https://nsq.io/clients/tcp_protocol_spec.html
作者
rainingmaster
许可证
2bsd
版本
-
基于 cosocket API 的 Lua nsq 客户端驱动 2020-04-03 02:15:07