(金慶的專欄 2017.1)
jinq0123/grpc_cb 是 Google gRpc 的C++庫。 它依賴于 grpc, 采用回調接口,簡化了使用,用來代替 grpc++ 庫。
使用簡介如下。
用 proto 文件定義服務:
route_guide.pb.h
route_guide.pb.cc
route_guide.grpc_cb.pb.h
route_guide.grpc_cb.pb.cc
生成的命名空間RouteGuide將包含
RouteGuide
Stub
Service
ChannelSptr channel(new Channel("localhost:50051"));Stub stub(channel);Point point = MakePoint(0, 0);Feature feature;Status status = stub.BlockingGetFeature(point, &feature);
stub.AsyncGetFeature(point, [](const Feature& feature) { cout << feature.name() << endl; });
先實現服務類
GetFeature()不必立即應答,可復制保存replier后直接返回, 待應答內容準備完成后,再調用Reply().開啟服務
GetFeature()
Reply()
Powered by: C++博客 Copyright © 金慶