Zuul is an edge service that provides dynamic routing, monitoring, resiliency, security, and more. Zuul corresponds to the front door of all requests from the Web site backend of the device and Netflix streaming app.
Zuul can appropriately route requests to multiple Amazon Auto Scaling Groups.
First create a new MAVEN project and add the following dependencies
<dependencyManagement>
<dependencies>
<dependency>
<groupId> org.springframework.cloud</groupid>
<artifactId>spring-cloud-netflix</artifactId>
<version>1.1.3.RELEASE</version>
<type>pom</type>
<scope>import</ scope>
</dependency>
</dependencies>
</dependencyManagement>
< dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
<dependency >
<groupId>org.springframework.cloud</groupId>
<artifactId> spring-cloud-starter-zuul</artifactid>
</dependency>
</dependencies>
Package Com.pp.zuul;
Import org.springframework.boot.SpringApplication;
Import org.springframework.boot.autoconfigure.SpringBootApplication;
Import Org.springframework.cloud.netflix.zuul.EnableZuulProxy;
@EnableZuulProxy
@SpringBootApplication Public
class App {public
static void Main (string[] args) { C8/>springapplication.run (App.class, args);
}
}
Package Com.pp.zuul;
Import org.springframework.web.bind.annotation.RequestMapping;
Import Org.springframework.web.bind.annotation.RestController;
@RestController public
class HomeController {
@RequestMapping ("/index") public
Object Index () {
Return "index";
}
The @RequestMapping ("Home") public
Object Home () {
return "to";
}
}
Configuration file: Application.properties
server.port=8181
#这里的配置表示, Access/baidu/** Direct redirect to http://www.baidu.com
zuul.routes.baidu.path=/baidu/**
zuul.routes.baidu.url=http://www.baidu.com
#反响代理配置
#这里的配置类似nginx的反响代理
#当请求/api/** will be delivered directly to the Listofservers configured server
when processing #当stripPrefix =true (http://127.0.0.1:8181/api/user/list/HTTP// 192.168.1.100:8080/user/list)
when #当stripPrefix =false (http://127.0.0.1:8181/api/user/list/HTTP// 192.168.1.100:8080/api/user/list)
zuul.routes.api.path=/api/**
zuul.routes.api.stripprefix=false
api.ribbon.listofservers=192.168.1.100:8080,192.168.1.101:8080,192.168.1.102:8080
#url重写配置
#这里的配置, The equivalent of accessing/index/** directly renders the request content of/home (as with the direct request to/home effect), and the URL address is the same
zuul.routes.index.path=/index/**
Zuul.routes.index.url=forward:/home