(金慶的專欄 2017.1)
jinq0123/grpc_cb 是 Google gRpc 的C++庫(kù)。 它依賴于 grpc, 采用回調(diào)接口,簡(jiǎn)化了使用,用來(lái)代替 grpc++ 庫(kù)。
使用簡(jiǎn)介如下。
用 proto 文件定義服務(wù):
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; });
先實(shí)現(xiàn)服務(wù)類
GetFeature()不必立即應(yīng)答,可復(fù)制保存replier后直接返回, 待應(yīng)答內(nèi)容準(zhǔn)備完成后,再調(diào)用Reply().開啟服務(wù)
GetFeature()
Reply()
Powered by: C++博客 Copyright © 金慶