grpc-lua 示例

grpc-lua 示例

(金庆的专栏 2018.4)

grpc-lua (https://github.com/jinq0123/grpc-lua) 是 grpc 的 lua 绑定库,
应用了 luapbintf , 不需要生成代码,直接读取 proto 文件。

如:

    -- Sync request.
    local request = { name = "world" }
    local response = assert(stub:sync_request("SayHello", request))
    print("Greeter received: " .. response.message)

完整的示例代码见 examples 目录。

服务器和客户端都支持同步和异步调用。

将 examples/conan_install.bat.example 去除 .example 后缀,然后运行,
将安装所有的依赖库. 须先安装 conan 包管理工具 (http://docs.conan.io/en/latest/installation.html)。
还需要设置 git 代理,因为 grpc 的子库需要翻墙。

conan_install.bat 实际上是下载依赖库代码并编译。结果在用户目录 .conan/data/。
在其中搜索 lua-cpp.exe, lua-cpp.dll, luapbintf.dll, grpc_lua.dll 并复制到 examples/helloworld/ 目录下。

然后在 helloworld 目录下分别运行 run_server.bat 和 run_client.bat 测试。

已编译测试可行的完整包可下载:
grpc-lua 代码及示例Windows执行程序:https://download.csdn.net/download/jq0123/10346554
grpc-lua 示例 CentOS 7.4 执行程序打包:https://download.csdn.net/download/jq0123/10346003

CentOS 7.4 实测:

[jinqing@localhost helloworld]$ ls
greeter_client.lua   grpc_lua.so       lua-cpp         run_server.bat
greeter_server.lua   helloworld.proto  luapbintf.so
greeter_service.lua  liblua-cpp.so     run_client.bat
[jinqing@localhost helloworld]$ ./lua-cpp greeter_server.lua
Server listening on 0.0.0.0:50051
Got hello from world
Got hello from world

[jinqing@localhost helloworld]$ ./lua-cpp greeter_client.lua
Greeter received: Hello world
Async greeter received: Hello world
[jinqing@localhost helloworld]$

[jinqing@localhost route_guide]$ ./lua-cpp route_guide_server.lua
RecordRoute reader end.
RouteChat reader end.

[jinqing@localhost route_guide]$ ./lua-cpp route_guide_client.lua
-------------- Sync get feature --------------
Found feature: {
...
评论 21
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值