使用gRPC进行跨语言的rpc服务应用

使用gRPC进行跨语言的rpc服务应用

            gRPC是一个基于google protobuf工具的rpc框架,支持c,c++,ruby,python,php等很多开发语言,目标是减少rpc应用开发时的成本,提高效率,具体的性能上来说,比xml-rpc要好一些,因为网络传输字节和解析要少很多,在2010年,我们就使用protobuf进行网络数据传输,也基于此做了一些应用,而现在gRPC则是把网络层也实现了,今天就试试简单的gRPC安装和使用。

操作系统: debian 8 64bit

安装gRPC

` $ git clone -b $(curl -L http://grpc.io/release) https://github.com/grpc/grpc
 $ cd grpc
 $ git submodule update --init
 $ make
 $ [sudo] make install

  • 安装protobuf 3.1
`apt-get install autoconf automake libtool curl make g++ unzip

wget -c https://github.com/google/protobuf/releases/download/v3.1.0/protobuf-cpp-3.1.0.tar.gz

tar zxvf protobuf-cpp-3.1.0.tar.gz

cd protobuf-3.1.0/

./autogen.sh

./configure

make

make install

ldconfig

这样相关的gRPC包就编译成功了,测试一下

  • python python的gRPC是独立的,使用的是grpcio,所以需要pip install grpcio

然后

`cd examples/python/helloworld

python greeter_server.py &

python greeter_client.py

就会得到gRPC的回应啦.

QQ群:protobuf-gRPC学习群 298735073

上海老李,QQ:1354608370,FreeSWITCH QQ群: