最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

在Windows系統(tǒng)下安裝Thrift的方法與使用講解

 更新時間:2018年12月12日 11:51:25   作者:灰灰是菇?jīng)鲅? 
今天小編就為大家分享一篇關(guān)于在Windows系統(tǒng)下安裝Thrift的方法與使用講解,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧

安裝

下載

下載地址:http://archive.apache.org/dist/thrift/0.10.0/

將thrift-0.10.0.exe放到一個文件下,如F:\thrift下,將其重命名為thrift.exe。如果不重命名,需要使用thrift-0.10.0調(diào)用thrift命令。

配置環(huán)境變量

Path中添加變量值,值為thrift.exe的地址,如F:\thrift。

測試

命令行輸入thrift -version,如果輸出thrift的版本即表明安裝成功。

使用

編寫IDL接口

HelloService.thrift

namespace java com.thrift.demo.service 
service HelloService{ 
 string sayHello(1:string username)
}

編譯

編譯之后會生成類HelloService。

thrift -gen java HelloService.thrift

編寫實(shí)現(xiàn)類

HelloServiceImpl.java

public class HelloServiceImpl implements HelloService.Iface {
 @Override
 public String sayHello(String username) throws TException {
 return "Hello Thrift Service : " + username;
 }
}

編寫服務(wù)端代碼

public class HelloServer {
 public static final int SERVER_PORT = 8090;
 public void startServer() {
 try {
  System.out.println("HelloService TSimpleServer start ....");
  TProcessor tprocessor = new HelloService.Processor<HelloService.Iface>(new HelloServiceImpl());
  // 簡單的單線程服務(wù)模型,一般用于測試
  TServerSocket serverTransport = new TServerSocket(SERVER_PORT);
  TServer.Args tArgs = new TServer.Args(serverTransport);
  tArgs.processor(tprocessor);
  tArgs.protocolFactory(new TBinaryProtocol.Factory());
  TServer server = new TSimpleServer(tArgs);
  server.serve();
 } catch (Exception e) {
  System.out.println("Server start error!!!");
  e.printStackTrace();
 }
 }
 public static void main(String[] args) {
 HelloServer server = new HelloServer();
 server.startServer();
 }
}

編寫客戶端代碼

public class HelloClient {
 public static final String SERVER_IP = "localhost";
 public static final int SERVER_PORT = 8090;
 public static final int TIMEOUT = 30000;
 public void startClient(String userName) {
 TTransport transport = null;
 try {
  transport = new TSocket(SERVER_IP, SERVER_PORT, TIMEOUT);
  // 協(xié)議要和服務(wù)端一致
  TProtocol protocol = new TBinaryProtocol(transport);
  HelloService.Client client = new HelloService.Client(protocol);
  transport.open();
  String result = client.sayHello(userName);
  System.out.println("Thrify client result =: " + result);
 } catch (TTransportException e) {
  e.printStackTrace();
 } catch (TException e) {
  e.printStackTrace();
 } finally {
  if (null != transport) {
  transport.close();
  }
 }
 }
 public static void main(String[] args) {
 HelloClient client = new HelloClient();
 client.startClient("Michael");
 }
}

運(yùn)行

先運(yùn)行服務(wù)端,再運(yùn)行客戶端。

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,謝謝大家對腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請查看下面相關(guān)鏈接

相關(guān)文章

最新評論

赤城县| 时尚| 青海省| 枞阳县| 米易县| 仁寿县| 民丰县| 阆中市| 安丘市| 视频| 宽城| 云阳县| 伊春市| 沧州市| 盐津县| 徐州市| 都匀市| 宜兴市| 太白县| 上饶县| 陇川县| 翼城县| 紫金县| 东乌| 泰宁县| 平昌县| 南靖县| 怀集县| 大名县| 交口县| 襄樊市| 华容县| 门源| 曲阜市| 科技| 吉首市| 鹤山市| 宝兴县| 陆河县| 安康市| 贵港市|