helloservice.thrift
namespace java com.meituan.service
include "model.thrift"
service HelloService {
model.Response sayHello(1: model.Request req)
}
model.thrift
namespace java com.meituan.model
struct Request {
1: required i32 age;
2: required string name;
}
struct Response {
1: required i16 code;
2: required string msg;
}
实现类
public class HelloServiceImpl implements HelloService.Iface {
@Override
public Response sayHello(Request req) throws TException {
System.out.println(req);
Response response = new Response();
response.setMsg("hi");
response.setCode((short) 255);
return response;
}
}
使用 tcpdump 监听 thrift 字节流
sudo tcpdump -i any -Xvv dst port 8899 and tcp
请求消息
18:40:43.204079 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto TCP (6), length 410, bad cksum 0 (->2644)!)
172.18.221.122.58766 > 172.18.221.122.8899: Flags [P.], cksum 0x14a7 (incorrect -> 0x40bf), seq 0:358, ack 1, win 6379, options [nop,nop,TS val 269827676 ecr 269824325], length 358
0x0000: 0200 0000 4500 019a 0000 4000 4006 0000 ....E.....@.@...
0x0010: ac12 dd7a ac12 dd7a e58e 22c3 67d5 1441 ...z...z..".g..A
0x0020: 7e7a 6334 8018 18eb 14a7 0000 0101 080a ~zc4............
0x0030: 1015 3e5c 1015 3145 0000 0162 8001 0001 ..>\..1E...b....
0x0040: 0000 0008 7361 7948 656c 6c6f 0000 0001 ....sayHello....
0x0050: 0c7f ff0b 2711 0000 0013 3330 3631 3432 ....'.....306142
0x0060: 3034 3230 3538 3933 3331 3339 360b 2712 0420589331396.'.
0x0070: 0000 0001 300b 2713 0000 0019 636f 6d2e ....0.'.....com.
0x0080: 7361 6e6b 7561 692e 6665 2e65 766f 6c76 sankuai.fe.evolv
0x0090: 652e 6170 690b 2714 0000 000e 3137 322e e.api.'.....172.
0x00a0: 3138 2e32 3231 2e31 3232 0b27 1500 0000 18.221.122.'....
0x00b0: 1548 656c 6c6f 5365 7276 6963 652e 7361 .HelloService.sa
0x00c0: 7948 656c 6c6f 0b27 1600 0000 0e31 3237 yHello.'.....127
0x00d0: 2e30 2e30 2e31 3a38 3839 3902 2717 0002 .0.0.1:8899.'...
0x00e0: 2718 000b 2719 0000 0007 312e 382e 372e '...'.....1.8.7.
0x00f0: 320d 271a 0b0b 0000 0003 0000 000b 6175 2.'...........au
0x0100: 7468 2d61 7070 6b65 7900 0000 1963 6f6d th-appkey....com
0x0110: 2e73 616e 6b75 6169 2e66 652e 6576 6f6c .sankuai.fe.evol
0x0120: 7665 2e61 7069 0000 000e 6175 7468 2d73 ve.api....auth-s
0x0130: 6967 6e61 7475 7265 0000 0028 3331 3244 ignature...(312D
0x0140: 3935 3732 3730 4244 4634 4645 3532 3832 957270BDF4FE5282
0x0150: 3136 4539 3142 3035 4538 3641 4441 4545 16E91B05E86ADAEE
0x0160: 3941 3432 0000 000b 696e 665f 7469 6d65 9A42....inf_time
0x0170: 6f75 7400 0000 0731 3030 3030 3030 0d27 out....1000000.'
0x0180: 1b0b 0b00 0000 0000 0c00 0108 0001 0000 ................
0x0190: 001b 0b00 0200 0000 036c 6768 0000 .........lgh..
8001 0001 到 0c00 0108 为美团自定义 Mtrace 信息。
sudo tcpdump -i any -Xvv src port 8899 and tcp
返回消息
16:12:16.009960 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto TCP (6), length 95, bad cksum 0 (->277f)!)
172.18.221.122.8899 > 172.18.221.122.49246: Flags [P.], cksum 0x136c (incorrect -> 0xbd5d), seq 1:44, ack 359, win 6374, options [nop,nop,TS val 261300760 ecr 261300750], length 43
0x0000: 0200 0000 4500 005f 0000 4000 4006 0000 ....E.._..@.@...
0x0010: ac12 dd7a ac12 dd7a 22c3 c05e 6745 7628 ...z...z"..^gEv(
0x0020: f56b afbc 8018 18e6 136c 0000 0101 080a .k.......l......
0x0030: 0f93 2218 0f93 220e 0000 0027 8001 0002 .."..."....'....
0x0040: 0000 0008 7361 7948 656c 6c6f 0000 0001 ....sayHello....
0x0050: 0c00 0006 0001 00ff 0b00 0200 0000 0268 ...............h
0x0060: 6900 00 i..