Вот простой пример передачи структуры в Thrift IDL:
https://github.com/RandyAbernethy/ThriftBook/blob/master/part1/arch/halibut.thrift
struct Date {
1: i16 year
2: i16 month
3: i16 day
}
service HalibutTracking {
i32 get_catch_in_pounds_today()
i32 get_catch_in_pounds_by_date(1: Date dt, 2: double tm)
}
Здесь есть пример клиента и сервера Java:
https://github.com/RandyAbernethy/ThriftBook/tree/master/part3/ws/thrift
Показывает возврат структуры (но ее передача довольно легко экстраполировать).Есть также много примеров в репозитории ThriftBook на Python и Java (все источники из Руководства программиста по Apache Thrift):
Пример структуры return thrift idl выглядит так:
struct TradeReport {
1: string symbol,
2: double price,
3: i32 size,
4: i32 seq_num
}
service TradeHistory {
TradeReport get_last_sale(1: string Symbol)
}
Java Client в листинге выглядит следующим образом:
import java.io.IOException;
import org.apache.thrift.TException;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.protocol.TBinaryProtocol;
public class ThriftClient {
public static void main(String[] args)
throws IOException, TException {
TSocket trans = new TSocket("localhost", 9090);
TBinaryProtocol proto = new TBinaryProtocol(trans);
TradeHistory.Client client = new TradeHistory.Client(proto);
trans.open();
for (int i = 0; i < 1000000; i++) {
TradeReport tr = client.get_last_sale("APPL");
}
trans.close();
}
}
Другие примеры IDL здесь (включая несколько, которые передают структуры):
https://github.com/RandyAbernethy/ThriftBook/tree/master/part2/IDL