Spring Cloud (vi): Integration of Zuul

Source: Internet
Author: User

1. Concept

Zuul is a framework for providing dynamic routing, monitoring, resiliency, security and other edge services on cloud platforms. Zuul corresponds to the front door of all requests from the Web site backend of the device and Netflix streaming app. Another need to understand the concept is the reverse proxy and load balancing, reverse proxy: is the external network to request resources to the intranet, and the resources back to the client, is the opposite of the proxy; Load balancing is a multiple client request, and if there are multiple identical Serviceid, the gateway will be polled for access.

2. Build

2.1. Add dependencies

<dependency>

<groupId>org.springframework.cloud</groupId>

<artifactId>spring-cloud-starter-zuul</artifactId>

<version>1.3.4.RELEASE</version>

</dependency>

<dependency>

<groupId>org.springframework.cloud</groupId>

<artifactId>spring-cloud-starter-eureka</artifactId>

<version>1.3.2.RELEASE</version>

</dependency>

2.2. Concrete Realization

@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 the side is bound by the ServiceId address, when the path after adding/xx-a/is to access service-a corresponding services.

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 micro-service service-a and micro-service Service-b

You can inject @Autowired private discoveryclient client into the controller, and then use the client to get the host and port number

2.5, A, B service copy, modify the port, to start, and then request, you will find two requests a service, to obtain a different port number of the micro-service, thus achieving client load balancing.

3. Summary

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


Spring Cloud (vi): Integration of Zuul

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.