thrift - helloworld

模板

新建文件命名为: helloThrift.thrift

namespace java com.ricisung.test.thrift
service HelloWordService  {
    string sayHello(1: i32 num, 2: string name);
}

生成代码



D:\develporDir\thrift\testhome>
D:\develporDir\thrift\testhome>thrift -gen java helloThrift.thrift

D:\develporDir\thrift\testhome>

##没有消息提示就是好消息

client

package com.ricisung.test.thrift;

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;

public class Client {

    public static void main(String[] args) throws TException {
        TTransport transport = new TSocket("localhost", 9090);
        transport.open();

        TProtocol protocol = new TBinaryProtocol(transport);

        HelloWordService.Client client = new HelloWordService.Client(protocol);
        long startTime = System.currentTimeMillis();

        for (int index = 0; index < 10000; index ++) {
            String response = client.sayHello(1111, "hello i am client");
            System.out.println(response);
        }

        long endTime = System.currentTimeMillis();

        System.out.println(endTime - startTime);

        transport.close();



    }

}

server

package com.ricisung.test.thrift;

import org.apache.thrift.server.TServer;  
import org.apache.thrift.server.TServer.Args;  
import org.apache.thrift.server.TSimpleServer;  
import org.apache.thrift.transport.TServerSocket;  
import org.apache.thrift.transport.TServerTransport;  
import org.apache.thrift.transport.TTransportException;

public class Thrift_HelloWorldServer {

    public static void main(String[] args) throws TTransportException {

        HelloWordService.Processor<HelloWordService.Iface> processor =  new HelloWordService.Processor
                <HelloWordService.Iface>(new HelloWorldServiceImpl());

        TServerTransport serverTransport = new TServerSocket(9090);  
        TServer server = new TSimpleServer(new Args(serverTransport).processor(processor));  
        server.serve(); 

    }

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值