grpc-lua 예
3351 단어 기타
(김경의 칼럼 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: {
...
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Github 프로필 Badge로 꾸미기앞으로 열심히 할 예정이니 많은 관심 부탁드립니다 😍😍 나의 머리로는 이해할 수 없는 코드들을 보며 머리가 꺠지려 할 때에, 학교 친구들의 github가 눈에 들어왔습니다. 인터넷에 나온 거로 많이 해 봤고 탬플릿도...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.