摘要
随着物联网技术和微服务架构的快速发展,越来越多的基于Mina框架的现场终端设备需要通过TCP通信机制与基于HTTP通信的Spring Cloud微服务系统进行数据交互。而网关Zuul作为外部设备访问微服务系统的唯一入口,并不具备对Mina客户端传送过来的TCP请求进行路由转发的功能,因此本文对服务网关Zuul进行了TCP通信功能扩展。为了保障服务网关Zuul在高并发下的稳定性,结合令牌桶算法实现了限流策略,但该策略无法确保核心服务在高并发情况下的高可用性,并且限流开关无法动态更新,为此本文提出了相应的改进方法并进行了实验分析。主要研究工作内容如下:
(1)针对服务网关Zuul不支持TCP通信机制的问题,本文对网关Zuul 进行了TCP功能扩展,其主要工作内容分为三个方面:1)由于网关Zuul并没有与Mina客户端建立连接的功能,本文设计了Mina服务器的通信框架,并通过接口实现的方式构建了Zuul-Mina服务器,成功与Mina客户端建立了通信连接;2)为了解决Mina客户端与微服务实例之间存在通信协议不同的问题,本文设计了Mina客户端与微服务实例之间的通信流程,并通过自定义通信协议及编解码器实现了协议转换;3)对于协议转换后的请求,Zuul-Mina服务器并不具备将其转发到具体的服务实例上的消息代理功能。因此本文通过构建请求转发类,对解析之后的请求进行了重构,并将重构后的请求通过负载均衡转发到了具体的服务实例上。
(2)针对网关Zuul使用令牌桶算法进行限流操作时,存在着无法保障核心服务在高并发情况下的可用性分布式和微服务的关系
的缺陷,提出了基于URI配置文件的拦截策略,该策略能够对核心URI与非核心URI进行不同的过滤处理,并通过自定义网关过滤器将该拦截策略应用到传统令牌桶算法中,实现了令牌桶算法能够针对不同请求采取不同限流操作的改进,保障了核心服务在高并发下的可用性。该限流策略存在的另一个缺陷在于限流功能的开启与关闭之间的切换,只能通过修改配置文件并重启网关服务来实现,无法做到动态的更新。因此本文在改进的限流策略基础上,通过在自定义的限流过滤器中设置不同的时间段来开启和关闭过滤器,实现了限流开关的动态更新。
(3)对服务网关Zuul的TCP功能扩展进行了功能性测试,通过测试结果分析扩展的TCP通信功能能够正常工作。对改进的限流算法进行功能测试和性
能测试,并与传统的令牌桶算法进行实验对比,分析了改进的令牌桶算法在核心服务的请求响应时间上具有明显的性能优势。对限流开关的动态更新进行功能测试,验证了其有效性。
关键词:微服务;Zuul;Mina;TCP;令牌桶算法
Abstract
With the rapid development of Internet of Tings technology and microservices architecture, more and more remote terminal devices based on Mina framework need to upload data to the Spring Cloud mi
croservices system based on the HTTP protocol through TCP communication. As the only entrance for external devices to access the microservices architecture, Zuul does not have the function of routing and forwarding TCP requests sent by Mina clients, so it is necessary to extend the TCP communication function for the service gateway Zuul. At the same time, in order to ensure the stability of service gateway Zuul under high concurrency, the token bucket algorithm is combined to realize the traffic limiting strategy. However, this strategy could not ensure the high availability of core services under high concurrency, and the traffic limiting switch could not be updated dynamically. Therefore, the corresponding improvement studies and experimental analysis are carried out. The main research works presented in this thesis are as follows:
(1)Since the service gateway Zuul does not directly support TCP communications, the research and development work of extending the TCP communication function for the gateway Zuul is carried out. The main work consists of three parts: 1) For the gateway Zuul lacking of the function of establishing connections with Mina clients, this thesis designs the Mina server communication framework, to build a Zuul-Mina server by the interface implementation, which successfully establishes communications with Mina clients; 2) In order to solve the problem of different communication protocols between Mina clients and micro service instances, this thesis designs the communication process between Mina cli
ents and micro service instances, defines customized communication protocol, and develops codec for protocol conversion; 3) After the request is converted, Zuul-Mina server does not have the message proxy function to forward it to the specific micro service instances. Based on the gateway Zuul, the request forwarding class is constructed for reconstructing request after parsing. With this class, the reconstructed request is forwarded to a specific service instance through load balancing.
(2)When the gateway Zuul uses the token bucket algorithm for traffic limiting operations, there is a defect that the core services are unable be guaranteed in high concurrency.To deal with this problem, a URI configuration file interception strategy is proposed, which can provide different filtering processing for core URI and non-core URI. The interception policy is applied to the traditional token bucket algorithm through a custom gateway filter. So that the token bucket algorithm can be improved by taking different traffic limiting operations according to the different requests, and the availability of core services can be guaranteed. Another drawback of the gateway Zuul when providing the traffic limiting function is that the switching between the opening and closing of the current limiting operation can only be achieved by modifying the configuration file and restarting the gateway service, and cannot be updated dynamically. Therefore, based on the improved traffic limiting strategy, the dynamic update of the traffic limiting switch is realized by setting different time periods in the customized filter to turn the filter on and off.
(3)Functional tests are carried out on the TCP function extension of service gateway Zuul, and the results show that the extended TCP communication function can work normally. The function and performance of the improved algorithm are tested. Comparing with the traditional token bucket algorithm, the improved token bucket algorithm has obvious performance advantages in the core services request response time. The dynamic update of traffic limiting switch is tested to verify its effectiveness.
Keywords: Microservices; Zuul; Mina; TCP; Token bucket algorithm
目录
第1章 绪论 (1)
1.1 研究背景与意义 (1)
1.2 研究现状 (2)
1.2.1 微服务通信的研究现状 (2)
1.2.2 微服务网关的研究现状 (3)
1.2.3 多通信机制的研究现状 (4)
1.2.4 流量限制策略的研究现状 (5)
1.3 研究内容 (5)
1.4 组织结构 (6)
第2章 基于服务网关Zuul的相关技术研究 (8)
2.1 关键技术点分析 (8)
2.2 网关Zuul技术分析 (8)
2.2.1 Zuul组件调用关系分析 (9)
2.2.2 Zuul路由配置分析 (9)
2.3 Apache Mina框架技术分析 (10)
2.4 网关Zuul的限流策略研究 (12)
2.5 整体架构图的提出 (14)
2.6 本章小结 (15)
第3章 基于服务网关Zuul的TCP功能扩展 (17)
3.1 TCP功能扩展结构图 (17)
3.2 Zuul-Mina服务器模块 (18)
3.2.1 Zuul的启动过程分析 (18)
3.2.2 Mina服务器设计原理分析 (20)
3.2.3 Zuul-Mina服务器模块的设计与实现 (21)
3.3协议转换模块 (22)
3.3.1 通信流程的设计 (22)
3.3.2 自定义报文格式及映射表 (23)
3.3.3 自定义编解码器 (25)

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。