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
  • 相关阅读:
    MySQL调优篇 | 逻辑架构解读(1)
    SQLPlus 在连接时通常有四种方式
    Oracle解决索引碎片功能
    windows2003 ftp 无法下载 解决
    bat记录
    ACCESS字符串操作函数
    缓存和RAID如何提高磁盘IO性能
    TortoiseSVN 命令 (命令行执行工具)
    在RHEL5下实现磁盘分区和磁盘配额
    PS 命令详解
  • 原文地址:https://www.cnblogs.com/qinyan20/p/3992076.html
Copyright © 2011-2022 走看看