Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of API Gateway in spring cloud

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the example analysis of API gateway in spring cloud, which is very detailed and has certain reference value. Friends who are interested must finish it!

1. Introduction of service gateway 1. Appearance mode

The communication between the client and each business subsystem must be carried out through a unified appearance object, and the appearance pattern provides a high-level interface to make the subsystem easier to use:

To put it simply, the gateway is very similar to this pattern, but more complex than the appearance pattern. Patterns, structures, and principles are all common and are used in a variety of architectures or components.

2. Brief introduction of Gateway

From the sense of microservice gateway, it is very similar to interceptor + route + filter, intercept request, series of basic processing, route forwarding to specified service.

The service gateway is also a server in the whole architecture, as the only entrance to the request, which is very similar to the appearance pattern. It handles all non-business functions at the gateway layer and provides customized API for the client. In the gateway layer, it usually performs the following operations: such as permission verification, monitoring, load balancing, caching, logging, current restriction, and so on.

Second, gateway mode 1. Mode comparison.

Here we compare the commonly used request service management mode with the gateway mode, as shown in the figure:

Conventional mode

In the absence of a gateway, the micro-service architecture will provide an API service on the business layer service to receive parameters, such as Client-API, which is usually divided into multiple API according to the system module, such as operating system, user system and so on.

Request for unified access to Client-API service

Client-API goes through authentication, current restriction, routing and other operations.

If the request is passed, it will be forwarded to the corresponding business service.

If the request is intercepted, it will be returned directly to the client

An open interface for Client-API to integrate all business services

The disadvantage of this mode is very obvious, each Client-API needs to implement a set of non-business services, code redundancy, when the system expansion, the maintenance cost is very high, suitable for lightweight system architecture.

Gateway mode

On the business service layer, add a layer of gateway control to complete a series of crosscutting non-business functions in the service gateway:

The client requests unified interception at the gateway layer.

Gateway execution: routing / authentication / current restriction / demotion and other operations

The gateway determines whether to forward the request or respond directly to the client.

The gateway service layer performs many non-business processes, as the only entrance to the server of the system, and bears the functions of routing and forwarding, security, current restriction, caching, logging, monitoring, circuit breaker degradation and other functions of all services. Gateway services should not only be highly available, but also avoid performance bottlenecks.

2. Multiple gateways

In large and complex systems, gateways are usually managed hierarchically to plan a class of services under one gateway to avoid overly bloated gateways and facilitate maintenance and management:

Master gateway: commonly used for routing and forwarding function

Module gateway: classified business service aggregation gateway, which does non-business operations for such services, and finally forwards the request to specific services. On the data platform, it usually makes an independent service gateway for the data channel (inflow and outflow). Make a layer independent gateway for data analysis services, which is basically divided according to the usage of services, so as to avoid the overcomplexity of single-layer service gateways.

Third, core functions 1, configuration level

Service discovery

The gateway should have the service discovery function and obtain the service list through the unified registry, so that the unified proxy service and route forwarding function can be performed.

Routing request

After the gateway layer service is implanted, the client does not know which specific service he is requesting, but only needs to forward the request to the gateway. After the gateway is released, the request will be routed to the specified business service.

Load balancing

The service instances connected by the gateway may exist in cluster mode, so the gateway can also implement load balancing policies on each service instance. The common strategy is service polling or routing by weight.

2. Customized development

Custom development, such as: authority verification, log integration, interface current limit, and other related functions, need to interact with the database, can be made into an independent service, in the service to achieve specific processing logic, the gateway layer can be called directly.

4. Gateway component 1, Netflix-Zuul

Zuul gateway mainly provides dynamic routing, monitoring, flexibility, security control and other functions. In the distributed micro-service system, the system is divided into several micro-service modules, and the user's request is routed through the zuul gateway and forwarded to the specific post-micro-service module. Netflix is an open source load balancer based on JVM routing and server.

2. Tyk components

Tyk is an open source, lightweight, fast and scalable API gateway that supports quotas and speed limits, authentication and data analysis, and multi-user and multi-organization. Based on the go language, it is rarely used in Java architecture systems.

3. Kong components

Kong is a highly available, extensible open source gateway project based on Nginx+Lua, opened by Mashape. The core is to implement database abstraction, routing, and plug-in management, which can exist in a separate code base and can be injected anywhere in the request life cycle in a few lines of code. Provide easy-to-use RESTfulAPI to operate and configure API management, and can scale multiple Kong servers horizontally, and distribute requests evenly to each Server through pre-load balancing configuration to deal with high concurrency network requests.

The above is all the contents of the article "sample Analysis of API Gateway in spring cloud". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 261

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report