grpc-lua 예

3351 단어 기타
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/conaninstall.bat.example 제거.example 접두사를 실행한 다음 모든 의존 라이브러리를 설치합니다.conan 패키지 관리 도구를 설치해야 합니다(http://docs.conan.io/en/latest/installation.html). grpc의 하위 라이브러리가 필요하기 때문에git 에이전트를 설정해야 합니다.
conan_install.bat는 실제적으로 라이브러리 코드를 다운로드하고 컴파일합니다.결과는 사용자 디렉터리에 있습니다.conan/data/. lua-cpp 검색exe, lua-cpp.dll, luapbintf.dll, grpc_lua.dll을 examples/helloworld/디렉터리에 복사합니다.
그리고 Hello World 디렉터리에서 각각 런 을 실행합니다server.bat와runclient.bat 테스트.
테스트 실행 가능한 전체 패키지를 컴파일하여 다운로드할 수 있습니다.grpc-lua 코드와 샘플 Windows 실행자:https://download.csdn.net/download/jq0123/10346554grpc-lua 샘플 CentOS 7.4 Express 패키지: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: {
...

좋은 웹페이지 즐겨찾기