当前位置:网站首页>ES 源码 API调用链路源码分析
ES 源码 API调用链路源码分析
2022-07-31 04:45:00 【水的精神】
关于API调用链路,我们先从熟悉的MVC三层架构说起。做开发的比较熟悉spring springMVC ,我们熟悉的套路是,请求先到 controller层,然后controller去调用service层,然后结果返回。通常,我们还有tomcat作为服务器,来接收请求,接收到的请求调用controller层。用户的请求,例如http请求,一般是先到tomcat服务,然后调用程序的controller。
然后再看es是怎么玩的,es没有用spring spingMVC这些,只用了Guice来做容器管理,es并没有选择使用类似于tomcat的服务器来接收请求,而是选择netty来实现服务器,完成请求的接收与发送。这就对应了下图的RestController,这一层这是和tomcat有相同的作用。而下图的BaseRestHandler实际上可以理解成来选择controller路由器,它要根据请求中的url路径,来选择一个controller。而下图第三步的RestSearchAction,正是我们之前理解的MVC中的 controller层,不同的功能放在了不同的RestAction里边,实际上一些逻辑也放在这里边。而NodeClient这一层实际上有点service的味道,它是真正去执行逻辑的地方。和传统的服务不同的是,es是一个天然的分布式应用。
Netty4HttpServerTransport.dispatchRequest()
RestController.dispatchRequest().tryAllHandlers()
RestController.dispatchRequest() 调用方法里边的wrappedHandler.handleRequest()
BaseRestHandler.handleRequest() 再调用方法里边的prepareRequest()方法,到这一步,实际上会根据请求来选一个具体的action。prepareRequest()实际上是一个接口,可以看下边的实现类,红框只是一个案例(这就是一个删除索引对应的Action)在prepareRequest里边,将rest请求,转换成es内部认识的请求。

以一个案例来分析(RestDeleteIndexAction)
接着看到的是:
@Overridepublic RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(Strings.splitStringByCommaToArray(request.param("index"))); deleteIndexRequest.timeout(request.paramAsTime("timeout", deleteIndexRequest.timeout())); deleteIndexRequest.masterNodeTimeout(request.paramAsTime("master_timeout", deleteIndexRequest.masterNodeTimeout())); deleteIndexRequest.indicesOptions(IndicesOptions.fromRequest(request, deleteIndexRequest.indicesOptions())); return channel -> client.admin().indices().delete(deleteIndexRequest, new RestToXContentListener<>(channel));}
跟着第五步的 delete一直向下,走到的是ElasticsearchClient.execute(),这又是一个接口,接着跟到它的实现类,来到AbstractClient.execute(),调用doExecute(),这是一个抽象方法,它的实现类NodeClient.doExecute(),在方法中调用了executeLocally(),这个方法会调用transportAction(action).execute(),可以看到 action被执行了!
接着第6步,点进去transportAction(action).execute()来到了TransportAction.execute() 在这个类中,继续点击execute(),里边调用的是requestFilterChain.proceed(), 在向下走到proceed()里边,调用的是this.action.doExecute(task, request, listener),这个doExecute()是 TransportAction类中的方法,并且这个类是一个抽象类,于是根据doExecute看它的实现类,不同的功能也对应不同的action,还是以删除索引这个为例,

边栏推荐
猜你喜欢

手把手实现图片预览插件(三)

WPF WPF 】 【 the depth resolution of the template
![Summary of Huawei Distributed Storage FusionStorage Knowledge Points [Interview]](/img/83/e0163b324448c6ef5b106862673637.jpg)
Summary of Huawei Distributed Storage FusionStorage Knowledge Points [Interview]

【wpf】wpf中的那些模板之深度解析

Puzzle Game Level Design: Reverse Method--Explaining Puzzle Game Level Design
![[C language] Detailed explanation of operators](/img/fa/dce3da39f19b51c6d1b682128da36b.png)
[C language] Detailed explanation of operators

exsl文件预览,word文件预览网页方法

Solved (the latest version of selenium framework element positioning error) NameError: name 'By' is not defined

ENSP, VLAN division, static routing, comprehensive configuration of Layer 3 switches

Musk talks to the "virtual version" of Musk, how far is the brain-computer interaction technology from us
随机推荐
mysql数据库安装(详细)
Unity shader forge和自带的shader graph,有哪些优缺点?
Vue项目通过node连接MySQL数据库并实现增删改查操作
(6) Enumeration and annotation
PCL 计算点云坐标最值及其索引
数字经济时代的开源数据库创新 | 2022开放原子全球开源峰会数据库分论坛圆满召开
MATLAB/Simulink&&STM32CubeMX工具链完成基于模型的设计开发(MBD)(三)
两个地址池r2负责管地址池r1负责管dhcp中继
C# 实现PLC的定时器
MySQL database addition, deletion, modification and query (detailed explanation of basic operation commands)
MySQL修改root账号密码
HCIP第十天_BGP路由汇总实验
MATLAB/Simulink & & STM32CubeMX tool chain completes model-based design development (MBD) (three)
XSS靶场(三)prompt to win
The Vue project connects to the MySQL database through node and implements addition, deletion, modification and query operations
Industry landing presents new progress | 2022 OpenAtom Global Open Source Summit OpenAtom OpenHarmony sub-forum was successfully held
开源汇智创未来 | 2022开放原子全球开源峰会OpenAtom openEuler分论坛圆满召开
(8) Math class, Arrays class, System class, Biglnteger and BigDecimal classes, date class
MySQL数据库安装配置保姆级教程(以8.0.29为例)有手就行
ERROR 2003 (HY000) Can‘t connect to MySQL server on ‘localhost3306‘ (10061)解决办法