In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "what are the advantages of the micro-service gateway gateway". In the daily operation, I believe many people have doubts about the advantages of the micro-service gateway gateway. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "what are the advantages of the micro-service gateway gateway?" Next, please follow the editor to study!
Brief introduction
Spring Cloud Gateway is a sub-project of Spring Cloud, which is a gateway developed based on Spring 5.0, Spring Boot 2.0 and Project Reactor technologies. It aims to provide a simple and effective unified API route management method for micro-service architecture.
As a gateway in the Spring Cloud ecosystem, Spring Cloud Gateway aims to replace Netflix Zuul. It not only provides a unified routing method, but also provides the basic functions of the gateway based on Filter, such as security, monitoring / metrics, and current restriction.
Related concepts
Route (routing): the basic building block of a gateway, similar to the location configuration of nginx. Defined by an ID, a target URI, a set of Predicate, and a set of Filter
Predicate (assertion): the part of a route that is mainly responsible for route matching to determine whether the request matches the route. We can use it to match anything from the HTTP request, such as path, parameter, header information, etc.
Filter (filter): this is an instance of GatewayFilter, which executes Filter after the request is routed by a Predicate match, and we can use it to modify the request and response.
There are two ways to configure Spring Cloud Gateway gateway routing:
Configure through a profile
Configure through @ Bean custom RouteLocator
These two methods are equivalent, and it is recommended to use configuration files. Because Spring Cloud Gateway uses a responsive programming framework, the learning curve is relatively steep.
Server: port: 8088eureka: client: serviceUrl: # Registry address defaultZone: http://localhost:8761/eurekaspring: application: name: test-gateway cloud: gateway: routes:-id: test1 uri: http://www.fhadmin.org predicates:-Path=/fhadmin/** filters:-StripPrefix=1
The meanings of each field are as follows:
Id: our custom routing ID, which remains unique
Uri: the destination service address. For most of the scenarios, we forward it to a service. Configuring uri: lb://user-service means that the request is forwarded to the user-service service in the registry.
Predicates: a routing condition that accepts a parameter and returns a Boolean result to determine whether it matches. Gateway has built-in a variety of routing conditions for us, including Path, Cookie, Param, Header, Before, After and so on, which can be used right out of the box. Of course, we can also implement predicates ourselves.
Filters: a filtering rule that executes filter when the request is successfully matched by predicate, which we can use to modify the request and response. The example indicates that the path received by the target service will have no first level.
Start the program, and when we access localhost:8088/baidu, gateway will forward it to https://www.fhadmin.org according to the routing rules we configured.
working principle
Solve the problem of single point of failure
Use nginx in front of gateway and load balance with nginx to different gateway services.
At this point, the study on "what are the advantages of the micro-service gateway gateway" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.