pom.xml
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.SR2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
导入gateway的jar,以及eureka的jar
application.yml
spring:
cloud:
gateway:
routes:
- id: web
uri: lb://EURAKA-SERVER
predicates:
- Path=/hello/{segment}
application:
name: springcloud-gateway
cloud:
gateway:
discovery:
locator:
enabled: true
#系统端口
server:
port: 1200
#Eureka配置
eureka:
client:
service-url:
defaultZone: http://localhost:10001/eureka/
其中这一段比较重要
spring:
cloud:
gateway:
routes:
- id: web
uri: lb://EURAKA-SERVER
predicates:
- Path=/hello/{segment}
lb代表后面写入的是服务名,如果uri你写入http://localhost:1200,那么它转发的是到特定的端口号,而不会说转发到特定的服务名,这里注意一下。
其次上面这段什么意思呢?
当匹配到http://localhost:1200/hello/xx的时候会跳转到服务名为euraka-server的服务去。
限流
http://www.ityouknow.com/springcloud/2019/01/26/spring-cloud-gateway-limit.html
熔断器使用hystrix,这个比较简单
比较重要的是它的过滤参数,比如header,cookie验证等等
http://www.ityouknow.com/springcloud/2019/01/19/spring-cloud-gateway-service.html