windows配置thrift开发环境
1)安装thrift:到thrift官网下载exe文件,然后将文件重命名为thrift.exe,拷贝到c:\windows目录下(或者任何目录下),然后就可以在dos环境下使用了
c:\windows>thrift -gen java D:\mywork\javaProject\thriftTest\test.thrift ,输出的java文件默认输出到当前目录下c:\windows,也可以使用-o参数指定输出路径
2)下载相关依赖包
2.1)libthrift.jar ,下载地址:http://repo1.maven.org/maven2/org/apache/thrift/libthrift/0.9.0/
2.2)slf4j-api.jar
2.3)slf4j-simple.jar
3)编写thrift 接口文件
- namespace cpp zam.thrift.test
- namespace py thriftTest
- namespace java com.zam.thrift.test
- namespace php thriftTest
- service Hello {
- string helloString(1:string word)
- }
4)编写接口实现代码
- package com.zam.server;
- import org.apache.thrift.TException;
- import com.zam.thrift.test.Hello.Iface;
- public class HelloImpl implements Iface{
- private static int count = 0;
- @Override
- public String helloString(String word) throws TException {
- // TODO Auto-generated method stub
- count += 1;
- System.out.println("get " + word + " " +count); return "hello " + word + " " + count;
- }
- }
5)编写server代码
- package com.zam.server;
- import org.apache.thrift.protocol.TBinaryProtocol;
- import org.apache.thrift.protocol.TBinaryProtocol.Factory;
- import org.apache.thrift.server.TServer;
- import org.apache.thrift.server.TThreadPoolServer;
- import org.apache.thrift.server.TThreadPoolServer.Args;
- import org.apache.thrift.transport.TServerSocket;
- import org.apache.thrift.transport.TTransportException;
- import com.zam.thrift.test.Hello;
- import com.zam.thrift.test.Hello.Processor;
- public class Server {
- public void startServer() {
- try {
- System.out.println("thrift server open port 1234");
- TServerSocket serverTransport = new TServerSocket(1234);
- Hello.Processor process = new Processor(new HelloImpl());
- Factory portFactory = new TBinaryProtocol.Factory(true, true);
- Args args = new Args(serverTransport);
- args.processor(process);
- args.protocolFactory(portFactory);
- TServer server = new TThreadPoolServer(args);
- server.serve();
- }
- catch (TTransportException e) {
- e.printStackTrace();
- }
- }
- public static void main(String[] args) {
- System.out.println("thrift server init");
- Server server = new Server();
- System.out.println("thrift server start");
- server.startServer();
- System.out.println("thrift server end");
- }
- }
6)编写client 代码
- package com.zam.server;
- import org.apache.thrift.TException;
- import org.apache.thrift.protocol.TBinaryProtocol;
- import org.apache.thrift.protocol.TProtocol;
- import org.apache.thrift.transport.TSocket;
- import org.apache.thrift.transport.TTransport;
- import org.apache.thrift.transport.TTransportException;
- import com.zam.thrift.test.Hello;
- public class Client {
- public void startClient() {
- TTransport transport;
- try {
- System.out.println("thrift client connext server at 1234 port ");
- transport = new TSocket("localhost", 1234);
- TProtocol protocol = new TBinaryProtocol(transport);
- Hello.Client client = new Hello.Client(protocol);
- transport.open();
- System.out.println(client.helloString("panguso"));
- transport.close();
- System.out.println("thrift client close connextion");
- } catch (TTransportException e) {
- e.printStackTrace();
- } catch (TException e) {
- e.printStackTrace();
- }
- }
- public static void main(String[] args) {
- System.out.println("thrift client init ");
- Client client = new Client();
- System.out.println("thrift client start ");
- client.startClient();
- System.out.println("thrift client end ");
- }
- }
8)运行server和client代码
8.1)启动server端
- thrift server init
- thrift server start
- thrift server open port 1234
8.2)启动client端
- thrift client init
- thrift client start
- thrift client connext server at 1234 port
- hello panguso 1
- thrift client close connextion
- thrift client end
下载地址:http://download.csdn.net/download/liyonghui123/5742211
windows配置thrift开发环境的更多相关文章
- windows配置php开发环境
1.安装xampp. xampp集成了php.prel.mysql.apache等网站工具,安装超简单,本身也超级好用.点击下载xampp 2.讲xmapp中的php配置到环境变量 比如我的xampp ...
- 原创:超简单!windows配置NDK开发环境使用JNI
前段时间看android版的opencv的配置教程时,看到了它的NDK配置方法,感觉简单又不会出错!!! 1.下载NDK,设置NDK路径: 在windows的系统环境变量中添加NDK的路径,环境变量名 ...
- windows配置Lua开发环境
官网上下载的不靠谱,很多库不能用,你如 require "socket" 如果没有vc那些编译也麻烦,摸索了很久,直接下载安装文件安装即可: 安装这两个就行: 先安装C++2005 ...
- Windows下配置Java开发环境
学习Java第一步是配置本地开发环境,学习最基本的桌面开发,下面以win7为例配置Java开发环境,即:JDK+JRE+Eclipse,安装JDK的时候会默认安装JRE,根据提示安装就可以了. 首先去 ...
- 【Objective-C】Windows下Objective-C开发环境配置
[Objective-C]Windows下Objective-C开发环境配置 ftp://ftpmain.gnustep.org/pub/gnustep/binaries/windows/ 最近打 ...
- Windows下Eclipse+PyDev配置Python开发环境
1.简介 Eclipse是一款基于Java的可扩展开发平台.其官方下载中包括J2EE.Java.C/C++.Android等诸多版本.除此之外,Eclipse还可以通过安装插件的方式进行包括Pytho ...
- IIS服务器 远程发布(Web Deploy)配置 VS2010 开发环境 Windows Server 2008服务器系统
原文:IIS服务器 远程发布(Web Deploy)配置 VS2010 开发环境 Windows Server 2008服务器系统 asp.net 网站有三种常用的发布方式:分别是拷贝开发机上发布好的 ...
- windows下spark开发环境配置
http://www.cnblogs.com/davidwang456/p/5032766.html windows下spark开发环境配置 --本篇随笔由同事葛同学提供. windows下spark ...
- Windows上Ruby开发环境的配置
最近公司项目上有需要,需要开发一个puppet的自动化工具,这个工具需要操作存储设备上的各种资源,而鉴于puppet不是善于完成这个任务的首选语言,于是我们选择了puppet的“爹”,Ruby. 熟悉 ...
随机推荐
- C# iis 错误配置信息( CS0016: 未能写入输出文件 )
IIS发布时,编译器错误消息: CS0016: 未能写入输出文件 "c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.N ...
- Could not find the following Boost libraries: boost_python3
安装Boost.NumPy时报错: CMake Error at /usr/share/cmake/Modules/FindBoost.cmake:1794 (message): Unable to ...
- Install Shield 打包教程
我的是已经下载过打包工具InstallShield2013LimitedEdition,没有下载的只有下面那个灰色的的图标,不过没关系选中灰色的点确定直接跳到下载页面了.下载完成后再重新添加安装和部署 ...
- UCS2和UTF16有区别
UCS2是定长的,固定2个字节,所以不能支持扩展字符,而UTF16是变长的. UCS2是落伍的. msdn里有这样一段描述: UCS-2 is a predecessor of UTF-16. ...
- 今天使用bootstrap中的tagsinput控件,碰到个小问题
我直接使用时,后台一直报Uncaught Can't add objects when itemValue option is not set错误, 代码如下: <div> <inp ...
- Office 365 系列四 ------ 绑定公司域名
Office 365包含了企业邮箱服务(Exchange Online),我们如果要用微软的企业邮箱,那么我们必须绑定我们公司的自己域名,而不是用微软 提供的二级域名,其实微软的整个Exchange ...
- mssql分页存储过程
本文转自百度文库http://wenku.baidu.com/view/8f6ec149fe4733687e21aa72.html 必须有主键 原代码 Codeuse users go if exis ...
- 平板上的js和电脑上js的不同之处
一.事件 1.平板上没有:onmousedown,onmouseup,onmousemove等事件,由ontouchstart,ontouchmove,ontounchend替代 2.位置问题:平板上 ...
- HashMap的两种实现方式
本文主要简要分析了Java中和Redis中HashMap的实现,并且对比了两者的异同 1.Java的实现 下图表示了Java中一个HashMap的主要实现方式 因为大家对于Java中HashMap的实 ...
- SpringRMI远程方法调用
Spring为各种远程访问技术的集成提供了工具类. 该小段引用自 http://www.open-open.com/lib/view/open1408957290478.html Spring远程支持 ...