【Thrift一】Thrift安装部署
Thrift安装部署
下载源码包
wget http://apache.fayea.com/thrift/0.9.3/thrift-0.9.3.tar.gz
安装g++
centos:yum install gcc gcc-c++
如果没有安装g++,无法编译
解压Thrift安装包
tar -xvf thrift-0.9.3.tar.gz
安装boost开发工具
进入thrift-0.9.3目录
运行命令:
yum install boost-devel.x86_64运行命令:
yum install boost-devel-static运行命令:
./configure --with-cpp --with-boost --with-python --without-csharp --with-java --without-erlang --without-perl --with-php --without-php_extension --without-ruby --without-haskell --without-go编译,命令:
make编译完成之后安装,命令:
make install出现
thrift命令提示表示Thrift安装成功

测试(python版)
- 创建RecSys.thrift文件
service RecSys {
string rec_data(1:string data)
}
- 创建server.py文件
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import sys
sys.path.append('gen-py')
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from thrift.server import TServer
from RecSys import RecSys
from RecSys.ttypes import *
class RecSysHandler(RecSys.Iface):
def rec_data(self, a):
print "Receive: %s" %(a)
return "ok"
if __name__ == "__main__":
# 实例化handler
handler = RecSysHandler()
# 设置processor
processor = RecSys.Processor(handler)
# 设置端口
transport = TSocket.TServerSocket('localhost', port=9900)
# 设置传输层
tfactory = TTransport.TBufferedTransportFactory()
# 设置传输协议
pfactory = TBinaryProtocol.TBinaryProtocolFactory()
server = TServer.TThreadedServer(processor, transport, tfactory, pfactory)
print 'Starting the server...'
server.serve()
print 'done'
- 创建client.py文件
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import sys
sys.path.append("gen-py") // 将第4步骤产生的目录加载进来
from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from RecSys import RecSys
# from demo.ttypes import *
try:
# Make Socket
# 建立socket, IP 和port要写对
transport = TSocket.TSocket('localhost', 9900)
# Buffering is critical. Raw sockets are very slow
# 选择传输层,这块要和服务器的设置一样
transport = TTransport.TBufferedTransport(transport)
# Wrap in a protocol
# 选择传输协议,这个也要和服务器保持一致,负责无法通信
protocol = TBinaryProtocol.TBinaryProtocol(transport)
client = RecSys.Client(protocol)
# Connect!
transport.open()
# Call server services
rst = client.rec_data("are you ok!")
print rst
# close transport
transport.close()
except Thrift.TException, ex:
print "%s" % (ex.message)
- 运行命令:
thrift --gen py RecSys.thrift运行完之后会在当前目录生成一个
gen-py的文件夹,里面有模块的名字之类的东西运行命令:
python server.py,启动服务端运行命令:
python client.py,启动客户端,并能收到服务端发出的信息
【Thrift一】Thrift安装部署的更多相关文章
- rpc框架之 thrift 学习 1 - 安装 及 hello world
thrift是一个facebook开源的高效RPC框架,其主要特点是跨语言及二进制高效传输(当然,除了二进制,也支持json等常用序列化机制),官网地址:http://thrift.apache.or ...
- thrift C++ Centos 安装
1.在官方下载thrift http://thrift.apache.org/download 这里下载thrift-0.11.0.tar.gz版本 2.如果想支持安装Cpp版本就需要先安装boost ...
- thrift多平台安装
thrift支持多语言的RPC,一直都想深入学习了解thrift,最近有空,就上网查了些资料,学习了一下,对它的使用有了一些了解.本篇是写thrift的安装,使用方法会另起一篇来写. 本文使用thri ...
- CentOS下SparkR安装部署:hadoop2.7.3+spark2.0.0+scale2.11.8+hive2.1.0
注:之前本人写了一篇SparkR的安装部署文章:SparkR安装部署及数据分析实例,当时SparkR项目还没正式入主Spark,需要自己下载SparkR安装包,但现在spark已经支持R接口,so更新 ...
- 日志采集框架Flume以及Flume的安装部署(一个分布式、可靠、和高可用的海量日志采集、聚合和传输的系统)
Flume支持众多的source和sink类型,详细手册可参考官方文档,更多source和sink组件 http://flume.apache.org/FlumeUserGuide.html Flum ...
- PRESTO安装部署和参数说明(一)
PRESTO部署和参数说明(一) 一,概要 在部署和使用presto的过程中,在此记录一下部署记录和使用记录以及需要注意的事项.本人使用的presto版本是0.214,3台redhat虚拟机.使用背景 ...
- Akka-CQRS(2)- 安装部署cassandra cluster,ubuntu-16.04.1-LTS and MacOS mojave
对于akka-cluster这样的分布式软件系统来说,选择配套的数据库类型也是比较讲究的,最好也是分布式的,如cassandra,能保证良好的HA特性.前面的例子里示范akka-persistence ...
- 一、tars简单介绍 二、tars 安装部署资料准备
1.github地址https://github.com/Tencent/Tars/ 2.tars是RPC开发框架,目前支持c++,java,nodejs,php 3.tars 在腾讯内部已经使用了快 ...
- Hive基础概念、安装部署与基本使用
1. Hive简介 1.1 什么是Hive Hives是基于Hadoop的一个数据仓库工具,可以将结构化的数据文件映射为一张数据库表,并提供类SQL查询功能. 1.2 为什么使用Hive ① 直接使用 ...
随机推荐
- Linux C -> symlink 和 readlink -> 符号链接
Linux C -> symlink 和 readlink -> 符号链接 -------------------------------------------------------- ...
- Android学习——SharedPreferences
接下来的几个博文,来介绍安卓中的数据存储方式,安卓中的数据存储主要有四种方式: 1.SharedPreferences 2.SQLite 3.Content Provider 4.File 这篇博文主 ...
- javascript面向对象的写法01
类和对象 其他面向对象的语言类的语法是内置的,自然而然的事.javascript中有对象,但没有类的语法,类的实现需要模拟出来. 只需要把对象想成一个容器,里面存放一些属性或方法,把类想象成一个对象的 ...
- SQL Server ->> 建立linked server到Azure SQL Server
EXEC master.dbo.sp_addlinkedserver @server = N'<nick_name_to_use>', @srvproduct=N'', @provider ...
- YAML 格式学习
目录 什么是YAML 一.注释和多文件 二.格式要求 三.数据结构 1.对象 2. 数组 3.常量 四.字符串 YAML的特殊字符 什么是YAML YAML是"YAML不是一种标记语言&qu ...
- verilog 三段式状态机的技巧
三段式代码多,但是有时钟同步,延时少,组合逻辑跟时序逻辑分开并行出错少. (1)同步状态转移 (2)当前状态判断接下来的状态 (3)动作输出 如果程序复杂可以不止三个always .always ...
- May 26th 2017 Week 21st Friday
One thorn of experience is worth a whole wilderness of warning. 一次痛彻心扉的经历,抵得上千百次的告诫. Several days ag ...
- 【转】vector中对象指针的排序
原文:http://blog.csdn.net/tanlijun37/article/details/1948493 vector中对象指针的排序,初步想法是1: 把对象指针存到vector,重载bo ...
- [USACO17JAN]Subsequence Reversal
嘟嘟嘟 这题刚开始是什么思路也没有,关键是不知道怎么解决序列反转的问题. 然后我就想到如果暴力反转一个序列的话,实际上就是不断交换数组中的两个数ai和aj,同时要满足交换的数不能交叉. 然后又看了一眼 ...
- c++ 单引号和双引号
c++中单引号表示一个字符,双引号表示字符串 python中单引号与双引号是一样的