发送申请
Consumer 的 Handler 解决链最初一个是 TransportClientHandler,这个 Handler 次要是:
1. 发动连贯
2. 申请之前执行 HttpClientFilter 的 beforeSendRequest
3. 塞入 ServiceComb 的微服务调用上下文,设置响应回调解决,发送申请
ServiceComb 发送申请应用 vertx,而 vertx 网络发送接管构建在 netty 之上,因此可能异步高并发。
java 很大一个特点是向建设大楼的脚手架,一个套在一个下面,举例,serviceComb 网络发送与接管是: 最根底是 jdk,下面是 netty,而后是 vertx,而后是 serviceComb。
1. 发动连贯
transport 实际上是 VertxRestTransport,最终到 RestClientInvocation 的 invoke,这个 invoke 重点剖析,
public void invoke(Invocation invocation, AsyncResponse asyncResp) throws Exception {
...
Future<HttpClientRequest> requestFuture = createRequest(ipPort, path);
...
}
Future<HttpClientRequest> createRequest(IpPort ipPort, String path) {
...
return httpClientWithContext.getHttpClient().request(requestOptions);
...
}
public Future<HttpClientRequest> request(RequestOptions options) {ContextInternal ctx = this.vertx.getOrCreateContext();
PromiseInternal<HttpClientRequest> promise = ctx.promise();
this.doRequest(options, promise);
return promise.future();}
private void doRequest(HttpMethod method, SocketAddress peerAddress, SocketAddress server, String host, int port, Boolean useSSL, String requestURI, MultiMap headers, long timeout, Boolean followRedirects, ProxyOptions proxyOptions, PromiseInternal<HttpClientRequest> requestPromise) {
...
this.httpCM.getConnection(eventLoopContext, key, timeout, (ar1) -> {
...
requestPromise.tryComplete(req);
...
}
...
}
httpCM 建设连贯胜利后,把 requestPromise 设置 Complete,到此连贯建设实现。