zoukankan      html  css  js  c++  java
  • thritf

    thrift 创建java php ruby服务: http://reasoning-lipl.iteye.com/blog/1969747
    thrift 数据格式:http://wenku.baidu.com/view/3034b9c2bb4cf7ec4afed00b
    http://dongxicheng.org/search-engine/thrift-guide/
    http://www.it165.net/pro/html/201304/5438.html
    http://blog.163.com/scuqifuguang@126/blog/static/171370086201362273929684/
    http://www.iteye.com/problems/71700
    http://chinacheng.iteye.com/blog/838006

    三、Ruby

    server代码:server_demo.rb

    Ruby代码  收藏代码
    1. require '../lib/thrift'  
    2. require '../thrift-demo/gen-rb/user_service'  
    3.   
    4. class UserServiceHandler  
    5.   def getUserNameById(userId)  
    6.       return "hello, user(id: #{userId})"  
    7.   end  
    8. end  
    9.   
    10. handler = UserServiceHandler.new()  
    11. processor = UserService::Processor.new(handler)  
    12. transport = Thrift::ServerSocket.new('localhost', 9090)  
    13. transportFactory = Thrift::BufferedTransportFactory.new()  
    14. server = Thrift::SimpleServer.new(processor, transport, transportFactory)  
    15.   
    16. puts "Starting the server..."  
    17. server.serve()  

     client代码:client_demo.rb

    Ruby代码  收藏代码
    1. require '../lib/thrift'  
    2. require '../thrift-demo/gen-rb/user_service'  
    3.   
    4. begin  
    5.   transport = Thrift::BufferedTransport.new(Thrift::Socket.new("localhost", 9090))  
    6.   protocol = Thrift::BinaryProtocol.new(transport)  
    7.   client = UserService::Client.new(protocol)  
    8.   
    9.   transport.open()  
    10.   puts client.getUserNameById(24)  
    11.   transport.close()  
    12. rescue Thrift::Exception => tx  
    13.   puts 'Thrift.Exception: ', tx.message  
    14. end  

     ruby还是很简洁的,执行`thrift --gen rb UserService.thrift`生成ruby的接口类文件,然后依次运行server脚本和client脚本。

    begin
      #...
    rescue Thrift::TransportException => e
      raise e unless e.type == Thrift::TransportException::END_OF_FILE
      # do whatever if it is not end of file reached.
    end
  • 相关阅读:
    【pyarmor】代码加密
    Multi-Window Data Augmentation Approach for Speech Emotion Recognition
    SVM / SVC / SVR
    【python】不同的dropout们
    【aubio】音频处理笔记
    Git 笔记
    【stay foolish】代码片段
    BERT笔记
    【pytorch】torch.utils.data数据处理
    Scoket例子
  • 原文地址:https://www.cnblogs.com/qinyan20/p/3992076.html
Copyright © 2011-2022 走看看