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()
localsocket=TSocket:new{
host='127.0.0.1',
port=8090
}
-- to select protocol of thrift.--local protocol = TBinaryProtocol:new{-- local protocol = TCompactProtocol:new{--trans = socket--}localprotocol=TJSONProtocolFactory:getProtocol(socket)
--local protocol = TCompactProtocolFactory:getProtocol(socket)client=RpcServiceClient:new{
protocol=protocol
}
-- to test different type of struct.localargStruct=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_socketsocket:open()
pmap= {}
pmap.name="namess"pmap.pass="vpass"pistrmap= {}
pistrmap[10] ="val10"pistrmap[20] ="val20"-- 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,
{"ele1", "ele2", "ele3"},
{11,22,33},
{"l1.","l2."}, false);
res=""fork,vinpairs(ret)
doprint(k, v)
res=res..k.."." ..v.."<br>"endreturnresendreturn_M