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

Spring cloud (VI): the Integration of Zuul

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

1. Concept

Zuul is a framework that provides dynamic routing, monitoring, resiliency, security and other edge services on cloud platforms. Zuul acts as the front door for all requests at the back end of the Web website for devices and Netflix streaming applications. Another concept that needs to be understood is reverse proxy and load balancer, reverse proxy: the public network requests resources from the private network and returns the resources to the client, which is opposite to the forward proxy; load balancing is multiple client requests, and if there are multiple identical serviceid, the gateway will access it by polling.

2. Set up

2.1. Add dependencies

Org.springframework.cloud

Spring-cloud-starter-zuul

1.3.4.RELEASE

Org.springframework.cloud

Spring-cloud-starter-eureka

1.3.2.RELEASE

2.2. Concrete implementation

@ EnableZuulProxy

@ SpringCloudApplication

Public class ZuulApplication {

Public static void main (String [] args) {

New SpringApplicationBuilder (ZuulApplication.class) .web (true) .run (args)

}

}

2.3, configuration

Spring.application.name=api-gateway

Server.port=9412

# routes to serviceId here binds the address through serviceid. When / xx-a/ is added after the path, the service corresponding to service-An is accessed.

Zuul.routes.xx-a.path=/xx-a/**

Zuul.routes.xx-a.serviceId=service-A

Zuul.routes.yy-b.path=/yy-b/**

Zuul.routes.yy-b.serviceId=service-B

Eureka.client.serviceUrl.defaultZone= http://localhost:8761/eureka/

2.4.New microservice service-An and microservice service-B

You can inject @ Autowired private DiscoveryClient client; into controller and then get the host and port number through client

2.5. If you make a copy of An and B services, modify the port, start them, and then request them separately, you will find two requests for A services and get micro-services with different port numbers, thus achieving client-side load balancing.

3. Summary

Zuul simplifies the complexity of client calls; load balancing reduces the pressure on a single server and distributes the request pressure to the same service.

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.

Share To

Internet Technology

Wechat

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

12
Report