Centos7.2 thrift-0.9.3 Installation Use (CPP server, go client)

Source: Internet
Author: User
Tags ocaml
This is a creation in Article, where the information may have evolved or changed.
    • What is thrift?
    • Dependency conditions
    • Thrift Installation
    • Thrift use
    • Summarize

What is thrift?

Thrift是一种接口描述语言和二进制通讯协议,[1]它被用来定义和创建跨语言的服务。[2]它被当作一个远程过程调用(RPC)框架来使用,是由Facebook为“大规模跨语言服务开发”而开发的。它通过一个代码生成引擎联合了一个软件栈,来创建不同程度的、无缝的跨平台高效服务,可以使用C#、C++(基于POSIX兼容系统)、Cappuccino、Cocoa、Delphi、Erlang、Go、Haskell、Java、Node.js、OCaml、Perl、PHP、Python、Ruby和Smalltalk。[wiki链接](https://zh.wikipedia.org/wiki/Thrift)

Dependency conditions

thrift核心代码使用C++写的,用了boost库。执行以下命令,安装相关依赖:
    yum install automake libtool flex bison pkgconfig gcc-c++ boost-devel libevent-devel zlib-devel python-devel ruby-devel

Thrift Installation

1. http://thrift.apache.org/download here to download is thrift-0.9.3.tar.gz
2. Select the appropriate language support as required when you do the following:

#tar -zxvf thrift-0.9.3.tar.gz #cd thrift-0.9.3#./configure --with-boost=/usr/local  --without-java --without-php#make; make install 
    1. In terminal input: Thrift–version to see if the installation was successful.

Thrift use

    1. Define a thrift file, Phone.thrift, with the following content:
enum PhoneType { HOME, WORK, MOBILE, OTHER}struct12string3type}
    1. Using the thrift command line, generate Java, Golang code
    thrift-r--gencppphone.thrift    thrift-r--gengophone.thrift
    1. Perform the following actions in the Gen-cpp directory
cp PhoneService_server.skeleton.cpp  PhoneService_server.cpp
    1. Modify the Get function in Phoneservice_server.cpp
  _returnconst std::string& uid) {    // Your implementation goes here    _return1024;    _return"13424562789";     _return.type = PhoneType::MOBILE;    printf("get\n");  }
    1. Writing makefile Files
= /usr/include/boost/= /usr/local= /usr/local= phone_types.cpp phone_constants.cpp PhoneService.cpp  PhoneService_server.cppserver: ${SRC}        g++-g-o-I-I-lthrift  

Run make, generate the Phoneserver executable, run the Phoneserver

./PhoneServer
    1. Preparing the Golang Client
#cd gen-go#mkdir src#mv phone src/phone#mv src/phone/phone_service-remote  src/phone_service-remote

Modify the/etc/profile file to increase the Golang project path

GOPATH=/usr/local/gopath:/home/denny/thrift-test/gen-go

Make environment variables effective

source /etc/profile

Compiling phone_service-remote

go build phone_service-remote

Run Phone_service-remote

./phone_service-remote

Output:

Phone({ID:1024 Number:13424562789 Type:MOBILE}) <nil>

This is the end of thrift's simple application.

Summarize

The study of thrift is not much, it is now felt that thrift is suitable for multi-language mixed programming, and the interaction between the system or the system depends on the RPC this time the usefulness should be quite large.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.