windows配置thrift开发环境
来源:互联网 发布:homer软件下载 编辑:程序博客网 时间:2024/05/17 06:14
1)安装thrift:到thrift官网下载exe文件,然后将文件重命名为thrift.exe,拷贝到c:\windows目录下,然后就可以在dos环境下使用了
4)编写接口实现代码 5)编写server代码 6)编写client 代码 8)运行server和client代码 8.2)启动client端 9)示例代码下载地址:http://download.csdn.net/detail/azhao_dn/5341602
如:thrift -gen Java D:\mywork\javaProject\thriftTest\test.thrift ,输出的Java文件默认输出到当前目录下,也可以使用-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)
- }
- 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;
- }
- }
- 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");
- }
- }
- 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.1)启动server端
- thrift server init
- thrift server start
- thrift server open port 1234
- thrift client init
- thrift client start
- thrift client connext server at 1234 port
- hello panguso 1
- thrift client close connextion
- thrift client end
0 0
- windows配置thrift开发环境
- windows配置thrift开发环境
- windows配置thrift开发环境
- windows配置thrift开发环境
- Thrift开发环境的配置
- Apache Thrift 配置环境
- Apache Thrift 配置环境
- windows下安装配置Thrift
- Windows下配置Thrift(C++)
- Perl - Windows开发环境配置.
- 配置perl开发环境(windows)
- 配置windows驱动开发环境
- windows phone7开发环境配置
- windows配置android开发环境
- windows配置Android开发环境
- Windows开发环境安装配置
- Windows 配置PHP7开发环境
- Windows配置python3开发环境
- HDU 3567 Eight II 预处理+bfs+hash
- 机器翻译
- form表单提交之前的非空验证
- CentOS7 USB 启动/安装出现 dracut-initqueue timeout问题
- [Codeforces343D] Water Tree 树链剖分
- windows配置thrift开发环境
- 深度学习之AlexNet模型
- 考试2 矩阵填充
- 2017.1.21
- l0-Norm, l1-Norm, l2-Norm, … , l-infinity Norm
- 详解Unity3D Shader开发之渲染管线
- Android中按返回键退出应用程序
- Eclipse安装FindBugs插件
- Android动态加载之ClassLoader详解