Thrift Oneway是什么?

网上很多文章,都有各种涉及使用 oneway 的,基本是一个THRIFT IDL示例接口前面加 oneway。看完之后对

oneway的理解还是很模糊,于是看了下Thrift的代码,终于搞懂了 oneway 。

代码位置: org.apache.thrift.ProcessFunction#isOneway

 1 try {
 2             result = this.getResult(iface, args);
 3         } catch (TException var9) {
 4             LOGGER.error("Internal error processing " + this.getMethodName(), var9);
 5             TApplicationException x = new TApplicationException(6, "Internal error processing " + this.getMethodName());
 6             oprot.writeMessageBegin(new TMessage(this.getMethodName(), (byte)3, seqid));
 7             x.write(oprot);
 8             oprot.writeMessageEnd();
 9             oprot.getTransport().flush();
10             return;
11         }
12 
13         if (!this.isOneway()) {
14             oprot.writeMessageBegin(new TMessage(this.getMethodName(), (byte)2, seqid));
15             result.write(oprot);
16             oprot.writeMessageEnd();
17             oprot.getTransport().flush();
18         }

原来开启了 oneway ,一次RPC调用服务端不会返回response 给客户端,也就相当于客户端是忽略结果的一次调用。

默认这个 oneway 是false 的,也就是默认都会返回结果,业务上不关心调用结果的接口可以设置为 oneway,可以稍微提升接口性能。

猜你喜欢

转载自www.cnblogs.com/Joynic/p/10985729.html