GateWay的作用和两种配置方式


1.网关

gateway使用webflux 底层使用异步非阻塞IO模型

2.作用

1.统一微服务的入口
2.实现请求的负载均衡
3.过滤处理

gateway = filter + router

3.两种配置方式

1.配置文件
server:
  port: 8088

spring:
  application:
    name: GATEWAY
  cloud:
    consul:
      host: localhost
      port: 8500
    gateway:
      routes:
        - id: category_route							# 指定路由唯一标识
          uri: http://localhost:8085 # 指定路由服务的地址
          predicates:
            - Path=/category					  # 指定路由规则

        - id: product_route
          uri: http://localhost:8084
          predicates:
            - Path=/product

2.java代码的配置类
@Configuration
public class GatewayConfig {
    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
        return builder.routes()
                .route("order_route", r -> r.path("/order/**")
                        .uri("http://localhost:9999"))
                .build();
    }
}

java代码的配置是优先于配置文件的


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM