CentOS 6.6 Thrift 环境搭建

本文介绍了在CentOS 6.6上搭建Thrift环境的详细步骤,包括安装Thrift库,生成服务端代码,实现服务器逻辑,编译和链接服务器及客户端代码。此外,还特别提到了使用TNonblockingServer进行高性能服务的场景。
摘要由CSDN通过智能技术生成
在做一个多台机器远程调用的东西,用到了thrift,使用C++语言。

yum update
yum -y install automake libtool flex bison pkgconfig gcc-c++ boost-devel libevent-devel zlib-devel python-devel ruby-devel crypto-utils openssl openssl-devel
#下载thrift
git clone https://git-wip-us.apache.org/repos/asf/thrift.git

cd thrift./bootstrap.sh

./configure --with-lua=no
./configure --with-boost=/usr/include/  这里猜想是因为boost安装在/usr/include里

make

sudo make install
运行编译好的时有可能找不到相关的库,因此将相关的库(即.so文件,默认在/usr/local/lib中)处理
cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
echo "/usr/local/lib" >> /etc/ld.so.conf
#  ldconfig


下面是在网上找的资料,主要参考点是其中的如何编写一个客户端服务器模式的小程序,以及如何编译运行
网址是 http://wiki.apache.org/thrift/ThriftUsageC++

getting started

The first thing you need to know is that the C++ code generated by Thrift compiles only on Unix based systems, although some success has been reported using Cygwin on Win32 in ThriftInstallationWin32.

Requirements

Make sure that your system meets the requirements as noted in ThriftRequirements

  • Thrift library files
  • Thrift header files.

Installing the Thrift library

Installing the Thrift library is trivial to link with the generated code.

  1. Download a snapshot of Thrift and extract if you haven't done so already - Direct Link

  2. Navigate to lib/cpp using the terminal of your choice

  3. Run  make to compile

  4. Run  make install to install the library. Your user needs root permissions.

Generating the server code

In this example we use an imaginary file called your_thrift_file.thrift:

#!/usr/local/bin/thrift --gen cpp

namespace cpp Test

service Something {
  i32 ping()
}

Now run:

thrift --gen cpp your_thrift_file.thrift

Exploring the generated code - The Server

The generated code should be under the gen-cpp directory. You will see a number of generated C++ and header files along with an automatically generated server skeleton code (in bold).

  • Something.cpp
  • Something.h
  • Something_server.skeleton.cpp

  • your_thrift_file_constants.cpp
  • your_thrift_file_constants.h
  • your_thrift_file_types.cpp
  • your_thrift_file_types.h

Implementing the Server

Copy the generated server skeleton to a file named Something_server.cpp and keep the original:

cp Something_server.skeleton.cpp Something_server.cpp

When this server is run in console it prints "ping" on the console window each time the function is called from a client.

Here's the autogenerated skeleton file to illustrate how to write a server: Something_server.cpp

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值