In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "What are the functions of API gateway of microservice architecture". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn "What are the functions of API gateway of microservice architecture"!
Why do I need an API Gateway?
Why do microservices require an API gateway? What exactly does the API Gateway do? Did we ever use the API Gateway concept when we had a simpler project structure?
In fact, when our project was still a single application, although there was no concept of "API gateway", filter/filter and the like were generally used in the project. The function of filter was to extract some non-business logic functions from the project and handle them independently to avoid mixing with business logic to increase code complexity. For example, authentication function, Session processing, security check, log processing, etc.
Now we use microservice architecture, in a project microservice node a lot, if let each node to deal with the above "authentication function, Session processing, security check, log processing, etc." will add a lot of redundant code, but also to increase the complexity of the business code, so we need to have an "API gateway" to these common functions independent into a service to deal with these things in a unified way.
Let's take a look at the following microservices architecture diagram:
The API Gateway is like a gatekeeper for microservices, a bridge between external clients and internal microservices.
Its main functions are:
route forwarding
It was said that the API gateway is the only external entrance to the internal microservice, so all external requests will be sent to this API gateway first, and then the API gateway will route to different microservice nodes according to different requests. For example, it can be forwarded according to the path or according to the parameters.
And because internal microservice instances change constantly with business adjustments, adding or deleting nodes, the API Gateway can work with the Service Registration module to ensure that external requests are forwarded to the most appropriate microservice instance.
Load Balancer
Since the API Gateway is a single entry point for internal microservices, the API Gateway can also dynamically Load Balancer adjust the load of each instance of the internal microservices after receiving external requests. Once an internal microservice instance is heavily loaded or even unable to respond in time, the API Gateway reduces or stops forwarding requests to that instance through a Load Balancer policy. When all internal microservice instances cannot be processed, the API gateway can also block external requests in the form of current limiting or fusing to ensure the availability of the entire system.
safety certification
"API gateway" is like a gate guard for microservices. After each request comes in, it must be authenticated on the "API gateway" first. After the authentication passes, it will be forwarded to the following service. When forwarding, it will generally bring identity information.
API Gateway also needs to perform security checks on each request, such as security of parameters, security of transmission, etc.
logging
Since all requests need to go through the API Gateway, we can record these behavior logs centrally on the API Gateway. These logs can be used both as our follow-up event queries and as performance monitoring of the system.
data conversion
Because the API Gateway is open to a variety of different clients, the types of data transmitted by different clients may be different. Therefore, the API gateway also needs to have the function of data conversion, converting the data transmitted by different clients into the same type and forwarding it to the internal microservice, so as to be compatible with the diversity of these requests and ensure the flexibility of microservices.
II. Principle and application of API gateway?
After talking about "why do you need an API gateway" above, let's take a look at how it should be applied in actual projects. Although we can develop a set of "API Gateway" ourselves, if there is no special need, it is not recommended to repeat the wheel, there are many mature solutions on the market that can be used directly, the following is a brief introduction to Zuul, Tyk, Kong three popular open source components.
Zuul
Zuul is an open source component developed by Netflix and based on the Java technology stack.
Zuul Gateway is very popular, and it is also integrated into Spring Cloud family bucket, which is very convenient to use.
Tyk is a lightweight, fast scalable open source API gateway written on GO.
You can see how Tyk works by looking at the diagram below.
Kong is an open source gateway service based on OpenResty technology stack, so it is also based on Nginx implementation.
Kong enables high performance, plug-in customization, clustering, and easy-to-use Restful API management.
At this point, I believe everyone has a deeper understanding of "what functions the API gateway of microservice architecture has". Let's actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!
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: 0
*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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.