美文网首页
记录Elasticsearch的请求流程

记录Elasticsearch的请求流程

作者: Ombres | 来源:发表于2019-05-30 21:04 被阅读0次
  1. 在Elasticsearch启动的时候会同时启动一个netty服务进行监听,这个服务用来处理所有的HTTP请求。Netty4HttpRequestHandler

  2. 当请求到达时,从channelRead0(ChannelHandlerContext ctx, HttpPipelinedRequest<FullHttpRequest> msg)进入,获取请求内容然后简单封装Netty4HttpRequest,接下来交给Netty4HttpServerTransport

  3. 执行serverTransport.incomingRequest(httpRequest, channel),这里先封装了一个RestRequest,然后创建了一个RestChannel进行发送响应,然后执行dispatchRequest(restRequest, channel, badRequestCause);,这里调用的是RestController的方法

  4. 执行ryAllHandlers(final RestRequest request, final RestChannel channel, final ThreadContext threadContext),这个请求尝试索引可能的操作,然后对需要执行的操作进行调用dispatchRequest(final RestRequest request, final RestChannel channel, final NodeClient client, final Optional<RestHandler> mHandler) throws Exception,如果成功执行,则让channal发送响应,同时返回true

  5. 判断操作的不同执行不同的请求。对于大多数常用的请求会执行wrappedHandler.handleRequest(request, responseChannel, client);

  6. 调用BaseRestHandleraction.accept(channel);

  7. 提交任务。。

相关文章

网友评论

      本文标题:记录Elasticsearch的请求流程

      本文链接:https://www.haomeiwen.com/subject/cysbtctx.html