1.Zuul
2.操作
2.1 pom
<?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"> <parent> <artifactId>spring-cloud-learning</artifactId> <groupId>org.org.maple</groupId> <version>0.0.1-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>ms-zuul-gateway-9527</artifactId> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-zuul</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.org.maple</groupId> <artifactId>ms-common-api</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> </dependencies> </project>
2.2 yml
server:
port: 9527
spring:
application:
name: ms-zuul-gateway
eureka:
client:
service-url:
defaultZone: http://eureka-server01:8761/eureka/,http://eureka-server02:8762/eureka/
instance:
instance-id: gateway-9527
prefer-ip-address: true
info:
app.name: spring-cloud-learning
company.name: mapleins
build.artifactId: $[project.artifactId]
build.version: $[project.version]
2.3 启动类
package org.mape; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.zuul.EnableZuulProxy; /** * @author mapleins * @Date 2019-01-13 13:26 * @Desc **/ @SpringBootApplication @EnableZuulProxy public class App_Zuul_Gateway_9527 { public static void main(String[] args) { SpringApplication.run(App_Zuul_Gateway_9527.class,args); } }
2.4 host文件
2.5 访问
直接访问
通过网关访问
2.6 重新配置
zuul:
prefix: /springcloud #添加统一前缀
ignored-services: ms-provider-dept # 忽略真实地址 忽略所有的真实地址 使用 "*"
# 相当于把微服务的名字换成了 新的名字
routes:
dept: # 随便写,起个名字
serviceId: ms-provider-dept
path: /mydept/**