Coder Social home page Coder Social logo

lua-resty-thrift's Introduction

Name

lua-resty-thrift - Lua thrift client driver for the ngx_lua based on the cosocket API

Synopsis

nginx.conf:

   server {
       location /test{
            content_by_lua '
                local GenericObjectPool = require "resty.thrift.GenericObjectPool"
                local TestServiceClient = require "resty.thrift.thrift-idl.lua_test_TestService"
                local ngx = ngx
                local client = GenericObjectPool:connection(TestServiceClient,'127.0.0.1',9090)
                local res = client:say('thrift')
                GenericObjectPool:returnConnection(client)
                ngx.say(res)
            ';
       }
   
   }
   

thrift:

   namespace java com.test.thrift
   namespace lua lua_test

   service TestService {
      string say(1:string request)
   }
1. 将本项目lib目录下的resty目录拷贝到openresty的安装目录
   :> cp lib/resty /${openresty.path}/lualib/
2. create thrift lua client (thrift 0.9.3) 
   用thrift命令生成thrift客户端
   :> thrift gen -lua tets.thrift
3. 将生成的文件拷贝openresty安装目录下的lualib/resty/thrift/thrift-idl/目录
   :>cp gen-lua/*_Service.lua /${openresty.path}/lualib/resty/thrift/thrift-idl/
4. :> cp gen-lua/*_ttypes.lua /${openresty.path}/lualib/resty/thrift/thrift-idl/
5. Replace *_Service.lua *_Service.lua `require`
   由于thrift生成的文件都是全局变量,而openresty建议使用的是local变量,因此需要把生成的文件变量改掉。
   *_ttypes.lua:
   local Thrift = require 'resty.thrift.thrift-lua.Thrift' -- local 方式引入变量
   local TType = Thrift[1] -- TType 变量被存放在Thrift数组里,下面变量同理
   local TMessageType = Thrift[2]
   local __TObject = Thrift[3]
   local TException = Thrift[4]
   local TApplicationException = Thrift[5]
   local __TClient = Thrift[6]
   
   *_Service.lua:
   local Thrift = require 'resty.thrift.thrift-lua.Thrift'
   local TType = Thrift[1]
   local TMessageType = Thrift[2]
   local __TObject = Thrift[3]
   local TException = Thrift[4]
   local TApplicationException = Thrift[5]
   local __TClient = Thrift[6]
6. 拷贝本项目下的所有so包到/usr/local/lib/ 如果该目录不在系统加载so包的默认设置里,可以手动一下,或者将so包放到/usr/lib/里
   :> cp lua-resty-thrift/lib/*.so /usr/local/lib/
7. 添加so包后需要让so包被加载
   :> ldconfig	   

lua-resty-thrift's People

Stargazers

Wilhelm Liao avatar firecrystal8 avatar leo avatar  avatar  avatar Vu Tran avatar Yu Gan avatar Jiahao(Jayce) Guo avatar Child Wang World avatar Zlac avatar  avatar ollcp avatar TIm avatar jie avatar JaredYeah avatar Mason Lee avatar hurricane avatar rain avatar  avatar mapdb avatar Yanmin avatar lilianglin avatar Hardy avatar xiajun avatar

Watchers

James Cloos avatar Fuxin Huang avatar Rye Yao avatar xiajun avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.