Thrift安装与使用
来源:互联网 发布:更改windows桌面路径 编辑:程序博客网 时间:2024/04/26 04:12
centos jdk6 php5.3以上 python2.6 thrift0.9.0
让thrift支持java php python,所以要安装java php python(linux系统默认自带python)
java: 安装JDK 和 ant (thrift安装时会检查 java javac ant等命令,ant命令要编译java的开发库)
安装thrift
yum install automake libtool flex bison pkgconfig gcc-c++ \ boost-devel libevent-devel zlib-devel python-devel./configure --with-java --with-php --with-python
makemake install安装客户端开发库,在thrift的lib目录下,可以通过查看README来进行安装
Java Library: /usr/local/lib/libthrift-0.9.0.jar
Protocol Extension: /usr/local/lib/libthrift-0.9.0.so
PHP Script Library: /usr/lib/php/
Protocol Extension: /usr/lib64/php/modules/thrift_protocol.so
Protocol Extension Configuration: /etc/php.d/thrift_protocol.ini
Python Script Library: /usr/lib64/python2.6/site-packages/thrift
Protocol Extension: /usr/lib64/python2.6/site-packages/thrift/protocol/fastbinary.so
示例:python作为server端,php作为客户端
namespace php hellostruct User {1: string firstname2: string lastname}exception UserException {1: i32 error_code,2: string error_msg}service UserManager {void ping(),string get_user(1:string firstname,2:string lastname) throws(1:UserException e),oneway void clear_list()}
thrift -r --gen php hello.thriftthrift -r --gen py hello.thriftserver.py
#!/usr/bin/env pythonimport syssys.path.append('./gen-py')from hello import UserManagerfrom hello.ttypes import *from thrift.transport import TSocketfrom thrift.transport import TTransportfrom thrift.protocol import TBinaryProtocolfrom thrift.server import TServerclass UserManagerHandler:def __init__(self):passdef ping(self):print 'Welcome To Thrift...'def get_user(self, firstname, lastname):if firstname == '':raise UserException(1, 'firstname is empty')if lastname == '':raise UserException(2, 'lastname is empty')return lastname+' '+firstname+'!'if __name__ == '__main__':handler = UserManagerHandler()processor = UserManager.Processor(handler)transport = TSocket.TServerSocket(port=9090)tfactory = TTransport.TBufferedTransportFactory()pfactory = TBinaryProtocol.TBinaryProtocolFactory()server = TServer.TSimpleServer(processor, transport, tfactory, pfactory)print 'Starting the server...'server.serve()client.py
#!/usr/bin/env php<?php$GLOBALS['THRIFT_ROOT'] = '/usr/lib/php';require_once $GLOBALS['THRIFT_ROOT'].'/Thrift/Transport/TTransport.php';require_once $GLOBALS['THRIFT_ROOT'].'/Thrift/Transport/TSocket.php';require_once $GLOBALS['THRIFT_ROOT'].'/Thrift/Protocol/TProtocol.php';require_once $GLOBALS['THRIFT_ROOT'].'/Thrift/Protocol/TBinaryProtocol.php';require_once $GLOBALS['THRIFT_ROOT'].'/Thrift/Transport/TBufferedTransport.php';require_once $GLOBALS['THRIFT_ROOT'].'/Thrift/Type/TMessageType.php';require_once $GLOBALS['THRIFT_ROOT'].'/Thrift/Factory/TStringFuncFactory.php';require_once $GLOBALS['THRIFT_ROOT'].'/Thrift/StringFunc/TStringFunc.php';require_once $GLOBALS['THRIFT_ROOT'].'/Thrift/StringFunc/Core.php';require_once $GLOBALS['THRIFT_ROOT'].'/Thrift/Type/TType.php';require_once $GLOBALS['THRIFT_ROOT'].'/Thrift/Exception/TException.php';require_once $GLOBALS['THRIFT_ROOT'].'/Thrift/Exception/TTransportException.php';require_once $GLOBALS['THRIFT_ROOT'].'/Thrift/Exception/TProtocolException.php';require_once './gen-php/hello/UserManager.php';require_once './gen-php/hello/Types.php';use Thrift\Protocol\TBinaryProtocol as TBinaryProtocol;use Thrift\Transport\TSocket as TSocket;use Thrift\Transport\TSocketPool as TSocketPool;use Thrift\Transport\TFramedTransport as TFramedTransport;use Thrift\Transport\TBufferedTransport as TBufferedTransport;use hello\UserManagerClient as UserManagerClient;try {$socket = new TSocket('localhost', 9090);$transport = new TBufferedTransport($socket, 1024, 1024);$protocol = new TBinaryProtocol($transport);$client = new UserManagerClient($protocol);$transport->open();$client->ping();printf("%s\n", $client->get_user('World', 'Hello'));$transport->close();} catch (UserException $e) {echo $e->error_msg;}
- Thrift安装与使用
- Thrift 安装与配置
- Thrift安装使用教程
- Thrift安装与常见错误
- Thrift安装与常见错误
- Thrift 之 安装与测试
- Cassandra + Thrift 安装使用笔记
- ubuntu下安装使用Thrift
- thrift的安装和使用
- Thrift 原理与使用实例
- Thrift 原理与使用实例
- Thrift使用入门(1) - Thrift概述及其安装
- Thrift使用入门(1) - Thrift概述及其安装
- 【学习笔记】thrift下载与安装
- Ubuntu下thrift的安装与测试
- 安装hbase与thrift完成后报错
- Thrift的安装和简单使用
- Thrift的安装和简单使用
- C++ 容器:顺序性容器、关联式容器和容器适配器
- 华为2013.6.3号机试题
- NYOJ 721 纸牌游戏 简单题
- linux显卡驱动之fb_ops
- 浅谈C++面向对象的软件开发
- Thrift安装与使用
- java关于重载带来的难题—方法匹配
- xp与Squeeze debian 双系统启动菜单的更改
- session.flush()的使用
- 在eclipse启动tomcat时遇到超时45秒的问题
- mongoDB 系统选择部分小结
- 指针类型转换
- forward和redirect路径问题
- 网站开发工具