ZUUL集成了负载均衡和断路器:
具体可参考如下文章:
全部spring cloud全部框架示例参考:http://www.weiqinxue.cn/blogs/index.php/User/articleview/ArticleID/U2A226
POM.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>springCloudAllZuul</groupId> <artifactId>springCloudAllZuul</artifactId> <version>1.0-SNAPSHOT</version> <parent> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-parent</artifactId> <version>Angel.SR3</version> <relativePath/> </parent> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka-server</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-zuul</artifactId> </dependency> </dependencies> </project>
ZuulApplication.java
package com.springCloudAll;
import org.springframework.boot.SpringApplication;
import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
/**
* Created by YouGuessWho on 2017/4/26.
*/
@EnableZuulProxy
@SpringCloudApplication
public class ZuulApplication {
public static void main(String[] args){
SpringApplication.run(ZuulApplication.class,args);
}
}
boostrap.yml:
spring: application: name: zuul-service eureka: instance: non-secure-port: ${server.port:10002} #3 metadata-map: instanceId: ${spring.application.name}:${random.value} # 当前服务在eureka server 的ID client: register-with-eureka: true #当前服务需要在Eureka server注册 fetch-registry: false #是否eureka服务器获取注册信息 service-url: defaultZone: http://${eureka.host:localhost}:${eureka.port:10001}/eureka/applicaton.xml(包含代理跳转规则):
server: port: 10005 zuul: routes: baidu: path: /qinxue/** url: http://www.weiqinxue.com api-a: path: /api/** serviceId: resource-service访问地址:localhost:10005/qinxue,会跳转到本站首页