resty-skynet-rpc - Lua skynet rpc driver for the ngx_lua based on the cosocket API
- Name
- Status
- Description
- Synopsis
- Methods
- Check List for Issues
- Limitations
- Installation
- TODO
- Community
- Bugs and Patches
- Author
- Copyright and License
- See Also
This library is on dev.
This Lua library is a skynet rpc driver for the ngx_lua nginx module:
https://github.com/openresty/lua-nginx-module/#readme
This Lua library takes advantage of ngx_lua's cosocket API, which ensures 100% nonblocking behavior.
Note that at least ngx_lua 0.5.14 or OpenResty 1.2.1.14 is required.
# you do not need the following line if you are using
# the OpenResty bundle:
lua_package_path "/path/to/lua-resty-redis/lib/?.lua;;";
server {
location /test {
content_by_lua_block {
local rpc = require "resty.skynet_rpc"
local r= rpc.new()
r:set_timeout(1000)
r:connect("127.0.0.1",2528)
local v = r:call("SIMPLEDB","GET","a")
ngx.say(v)
r:set_keepalive(5000)
}
}
syntax: r, err = rpc:new()
Creates a rpc object. In case of failures, returns nil
and a string describing the error.
syntax: ok, err = r:connect(host, port, options_table?)
Attempts to connect to the remote host and port that the skynet server is listened by the skynet server .
Before actually resolving the host name and connecting to the remote backend, this method will always look up the connection pool for matched idle connections created by previous calls of this method.
syntax: r:set_timeout(time)
Sets the timeout (in ms) protection for subsequent operations, including the connect
method.
syntax: ok, err = r:set_keepalive(max_idle_timeout, pool_size)
Puts the current connection immediately into the ngx_lua cosocket connection pool.
You can specify the max idle timeout (in ms) when the connection is in the pool and the maximal size of the pool every nginx worker process.
In case of success, returns 1
. In case of errors, returns nil
with a string describing the error.
Only call this method in the place you would have called the close
method instead. Calling this method will immediately turn the current redis object into the closed
state. Any subsequent operations other than connect()
on the current object will return the closed
error.
syntax: ok, err = r:close()
Closes the current rpc connection and returns the status.
In case of success, returns 1
. In case of errors, returns nil
with a string describing the error.
syntax: r:call(service_name,method,...)
service_name:skynet service name
method:skynet service method fro rpc
...:paras for the skynet service method,cannot be point and function,it cannot be serialize
1.install skynet first: https://github.com/cloudwu/skynet
2.configue skynet cluster:https://github.com/cloudwu/skynet/wiki/Cluster
3.cd lualib-src && make cluster.so
4.copy resty/skynet_rpc.lua and cluster.so to openresty lib
yaoxinming
- the ngx_lua module: https://github.com/openresty/lua-nginx-module/#readme
- the lua-resty-mysql library