xinmingyao / resty-skynet-rpc

a rpc for openresty to skynet cluster

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Name

resty-skynet-rpc - Lua skynet rpc driver for the ngx_lua based on the cosocket API

Table of Contents

Status

This library is on dev.

Description

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.

Synopsis

    # 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)

          }
     }

Back to TOC

Methods

Back to TOC

new

syntax: r, err = rpc:new()

Creates a rpc object. In case of failures, returns nil and a string describing the error.

Back to TOC

connect

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.

Back to TOC

set_timeout

syntax: r:set_timeout(time)

Sets the timeout (in ms) protection for subsequent operations, including the connect method.

Back to TOC

set_keepalive

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.

Back to TOC

close

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.

Back to TOC

call

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

Back to TOC

Back to TOC

Installation

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

Back to TOC

TODO

Back to TOC

Community

Back to TOC

English Mailing List

Back to TOC

Chinese Mailing List

Back to TOC

Bugs and Patches

Back to TOC

Author

yaoxinming

Back to TOC

Copyright and License

Back to TOC

See Also

Back to TOC

About

a rpc for openresty to skynet cluster


Languages

Language:C 88.3%Language:Lua 11.3%Language:Makefile 0.4%