• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

gityf/ngx_lua_thrift: thrift lua for nginx.

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

gityf/ngx_lua_thrift

开源软件地址(OpenSource Url):

https://github.com/gityf/ngx_lua_thrift

开源编程语言(OpenSource Language):

Lua 77.7%

开源软件介绍(OpenSource Introduction):

ngx_lua_thrift Apache2.0 License

to access thrift by lua.

protocol

    Support protocol: binary,compact and JSON.
    binary: TBinaryProtocol.lua
    compact: TCompactProtocol.lua
    JSON:TJsonProtocol.lua
    Support transport: RawSocket,Buffered,Framed and Http.

socket

    socket: ngx.socket.tcp()

Steps of installing

    1. download https://openresty.org/download/openresty-x.y.z.a.tar.gz .
    2. install openresty.
    3. To copy all files in lualib to directory openresty/lualib/
    4. To cpoy all conf file to directory openresty/nginx/conf/
    5. compile source in directory openresty/lualib/libthrift/c
        cd /usr/local/openresty/lualib/libthrift/c ; make
    6. Start openresty nginx server.

demo of lua thrift client

require "rpc_RpcService"
require "TFramedTransport"
require "TBinaryProtocol"
require "TJsonProtocol"
require "TCompactProtocol"
require "TSocket"
_M = {}
function _M.demoFunc()
    local socket = TSocket:new{
        host='127.0.0.1',
        port=8090
    }
    -- to select protocol of thrift.
    --local protocol = TBinaryProtocol:new{
    -- local protocol = TCompactProtocol:new{
        --trans = socket
    --}
    local protocol = TJSONProtocolFactory:getProtocol(socket)
    --local protocol = TCompactProtocolFactory:getProtocol(socket)
    client = RpcServiceClient:new{
        protocol = protocol
    }
    -- to test different type of struct.
    local argStruct = ArgStruct:new{
      argByte = 53,
      argString = "str 测试字符串\"\t\n\r\'\b\fvalue",
      argI16 = 54,
      argI32 = 12.3,
      argI64 = 43.32,
      argDouble = 11.22,
      argBool = true
    }

    -- Open the socket using ngx_socket
    socket:open()
    pmap = {}
    pmap.name = "namess"
    pmap.pass = "vpass"
    -- map[int]string
    pistrmap = {}
    pistrmap[10] = "val10"
    pistrmap[20] = "val20"
    -- str set define is map[string]bool
    paramSets = {}
    paramSets["ele1"] = true
    paramSets["ele2"] = true
    paramSets["ele3"] = true
    -- int set define is map[int]bool
    intSets = {}
    intSets[11] = true
    intSets[22] = true
    intSets[33] = true

    -- to do a thrift rpc call and store response into variable ret.
    ret = client:funCall(argStruct, 53, 54, 12, 34, 11.22, "login", pmap,
        pistrmap,
        paramSets,
        intSets,
        {"l1.","l2."}, false);
    res = ""
    for k,v in pairs(ret)
    do
        print(k, v)
        res = res .. k .."." .. v .. "<br>"
    end
    return res
end
return _M

nginx conf

server {
        listen 8000;

        location = /v1/lua_thrift{
            access_log logs/access.log main;
            add_header 'Content-Type' 'text/html';
            content_by_lua '
                local cln = require "test_cln"
                ngx.say(cln.demoFunc());
            ';
        }
}

Testing

To access web url http://127.0.0.1:8000/v1/lua_thrift and get result.
          1.return 1 by FunCall.
          2.return 2 by FunCall.



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap