thrift实现java与ruby的交互
编程技术  /  houtizong 发布于 3年前   110
bool: A boolean value (true or false)byte: An 8-bit signed integeri16: A 16-bit signed integeri32: A 32-bit signed integeri64: A 64-bit signed integerdouble: A 64-bit floating point numberstring: A text string encoded using UTF-8 encoding
binary: a sequence of unencoded bytes
list<type>: An ordered list of elements. Translates to an STL vector, Java ArrayList, native arrays in scripting languages, etc.set<type>: An unordered set of unique elements. Translates to an STL set, Java HashSet, set in Python, etc. This type is not supported in PHP! Use lists instead.map<type1,type2>: A map of strictly unique keys to values. Translates to an STL map, Java HashMap, PHP associative array, Python/Ruby dictionary, etc.
struct User { 1: string id, 2: string name,}service UserStorage { void set_user(1: User user), User get_user(1: string id)}
thrift -r -gen java user.thrift
thrift -r -gen rb user.thrift
public class UserServiceHandler implements UserStorage.Iface { public void set_user(User user) throws TException { System.out.println(user.name + " " + user.id); } public User get_user(String id) throws TException { // 没有逻辑意义,纯粹是为了返回一个user User user = new User(); user.setId(id); user.setName("user_one"); return user; } }
public static void main(String[] args) { try { UserServiceHandler handler = new UserServiceHandler(); UserStorage.Processor processor = new UserStorage.Processor(handler); TServerTransport serverTransport = new TServerSocket(9090); TServer server = new TSimpleServer(processor, serverTransport); // Use this for a multithreaded server // server = new TThreadPoolServer(processor, serverTransport); System.out.println("Starting the server..."); server.serve(); } catch (TTransportException tTransportException) { } }
require 'thrift'require 'user_constants'require 'user_storage'transport = Thrift::BufferedTransport.new(Thrift::Socket.new('localhost', 5555))protocol = Thrift::BinaryProtocol.new(transport)client = UserStorage::Client.new(protocol)transport.open()user = client.get_user('123')p user
请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!
技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成
网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];
文章归档
文章标签
友情链接