In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces what Zuul is, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
1. What is Zuul?
In the micro-service scenario, each micro-service exposes a set of fine-grained services. The request of the client may involve a series of service calls, and if these micro-services are exposed to the client, it will increase the complexity of the client code.
Refer to the Facade pattern in the GOF design pattern, combine fine-grained services to provide a coarse-grained service, and all requests are imported into a unified entry, then the whole service only needs to expose an api, shielding the implementation details of the server, and reducing the number of network calls between the client and the server. This is api gateway.
With api gateway, some general processing logic that is not related to the business can be stripped out of api gateway, and api gateway is only responsible for the orchestration of services and the assembly of results.
The Zuul component of Spring Cloud Netflix can do the function of reverse proxy, forward the request to the back-end coarse-grained service through routing addressing, and do some general logic processing.
What can 2.Zuul do?
Zuul can load a dynamic filtering mechanism to achieve the following functions:
Verification and security: identify verification requirements for all types of resources and reject requests that do not meet the requirements.
Review and monitoring: track meaningful data and statistical results at the edge, so as to bring us accurate production status conclusions.
Dynamic routing: dynamically routes requests to different back-end clusters as needed.
Stress testing: gradually increase the load flow to the cluster to calculate the performance level.
Load distribution: allocate the corresponding capacity for each load type and discard requests that exceed the limit.
Static response processing: establish a partial response directly at the edge to prevent it from flowing into the internal cluster.
Multi-area resiliency: request routing across AWS areas is designed to diversify the use of ELB and ensure that the edge location is as close as possible to the user.
The core of 3.Zuul
Filter is the core of Zuul, which is used to control external services. Filter has four lifecycles, namely "PRE", "ROUTING", "POST" and "ERROR". The entire lifecycle can be represented by the following figure.
Most of the functionality of Zuul is achieved through filters, which correspond to the typical lifecycle of the request.
PRE: this filter is called before the request is routed. We can use this filter to authenticate, select the requested micro-service in the cluster, record debugging information, and so on.
ROUTING: this filter routes requests to microservices. This filter is used to build requests sent to microservices and to request microservices using Apache HttpClient or Netfilx Ribbon.
POST: this filter is executed after routing to the microservice. This filter can be used to add standard HTTP Header to responses, collect statistics and metrics, send responses from microservices to clients, and so on.
ERROR: this filter is executed when an error occurs in other phases. In addition to the default filter type, Zuul allows us to create custom filter types. For example, we can customize a filter of STATIC type to generate a response directly in Zuul without forwarding the request to the back-end microservice.
Filter implemented by default in Zuul
4. How to use Zuul
Spring Cloud Zuul routing is an indispensable part of micro-service architecture, which provides edge services such as dynamic routing, monitoring, resiliency, security and so on. Zuul is a load balancer based on JVM routing and server produced by Netflix.
Let's use the code to understand how Zuul works
1. Easy to use
1. Add dependencies
Org.springframework.cloud spring-cloud-starter-zuul
Introduction of spring-cloud-starter-zuul package
2. Configuration file
The configuration here in spring.application.name=gateway-service-zuulserver.port=8888# indicates that access / it/** is directly redirected to http://www.ityouknow.com/**zuul.routes.baidu.path=/it/**zuul.routes.baidu.url=http://www.ityouknow.com/
3. Startup class
@ SpringBootApplication@EnableZuulProxypublic class GatewayServiceZuulApplication {public static void main (String [] args) {SpringApplication.run (GatewayServiceZuulApplication.class, args);}}
Add @ EnableZuulProxy to the startup class to support gateway routing.
Thank you for reading this article carefully. I hope the article "what is Zuul" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you 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.