关于Gateway知识的小结

gateway zuul 1
spring gateway使用基于netty异步io; zuul 1使用servlet 3,每个请求一个线程,同步Servlet,多线程阻塞模型。

在低并发的情况下,zuul 1和spring gateway差距并不大,
在高并发情况下,差距会很明显。
这也就是异步io和多线程阻塞模型的区别。

Springboot版本为:2.1.7.RELEASE, SpringCloud版本为:Greenwich.SR2

pom配置

<dependencies>

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-gateway</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-webflux</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-redis-reactive</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>com.nimbusds</groupId>
        <artifactId>nimbus-jose-jwt</artifactId>
        <version>6.0</version>
    </dependency>

    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.8.5</version>
    </dependency>

    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>fastjson</artifactId>
        <version>1.2.58</version>
    </dependency>

</dependencies>

application.yml

1、设置StripPrefix=1表示从二级url路径转发
2、参数spring.cloud.gateway.discovery.locator.enabled为true,表明Gateway开启服务注册和发现的功能

当client端使用http://localhost:10003/boss-bes-auth-center/api/路径进行请求时,如果根据上述进行配置Gateway会将请求转换为http://localhost:10016/api/。以此作为前端请求的最终目的地。

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:10000/eureka/
server:
  port: 10003
spring:
  application:
    name: boss-bes-gateway
  redis:
    host: 58.22.61.222
    port: 27014
    database: 1
  main:
    allow-bean-definition-overriding: true
  cloud:
    gateway:
      discovery:
        locator:
          enabled: true
      routes:
        #       权限验证
        - id: boss-bes-auth-center
          uri: http://localhost:10016/
          predicates:
            - Path=/boss-bes-auth-center/api/**
          filters:
            - StripPrefix=1
            - name: Retry
              args:
                retries: 3
                statuses: BAD_GATEWAY
            - name: Hystrix
              args:
                name: fallbackcmd
                fallbackUri: forward:/fallback
        #        用户与权限管理
        - id: boss-bes-user-permission-center
          uri: http://localhost:10015/
          predicates:
            - Path=/boss-bes-user-permission-center/api/**
          filters:
            - StripPrefix=1
            - name: Retry
              args:
                retries: 3
                statuses: BAD_GATEWAY
            - name: Hystrix
              args:
                name: fallbackcmd
                fallbackUri: forward:/fallback
        #        基础数据管理
        - id: boss-bes-basedata-center
          uri: http://localhost:10001/
          predicates:
            - Path=/boss-bes-basedata-center/api/**
          #            - Path=/api/**
          filters:
            - StripPrefix=1
            - name: Retry
              args:
                retries: 3
                statuses: BAD_GATEWAY
            - name: Hystrix
              args:
                name: fallbackcmd
                fallbackUri: forward:/fallback
        #        考试中心
        - id: boss-bes-exam-center
          uri: http://localhost:8015/
          predicates:
            - Path=/boss-bes-exam-center/api/**
          filters:
            - StripPrefix=1
            - name: Retry
              args:
                retries: 3
                statuses: BAD_GATEWAY
            - name: Hystrix
              args:
                name: fallbackcmd
                fallbackUri: forward:/fallback
        #        试卷中心
        - id: boss-bes-paper-center
          uri: http://localhost:10010/
          predicates:
            - Path=/boss-bes-paper-center/**
          filters:
          #  设置StripPrefix=1表示从二级url路径转发
            - StripPrefix=1
            - name: Retry
              args:
                retries: 3
                statuses: BAD_GATEWAY
            - name: Hystrix
              args:
                name: fallbackcmd
                fallbackUri: forward:/fallback
#            - name: RequestRateLimiter
#              args:
#                key-resolver: '#{@hostAddrKeyResolver}'
#                redis-rate-limiter.replenishRate: 1
#                redis-rate-limiter.burstCapacity: 3

hystrix:
  command:
    default:
      execution:
        isolation:
          thread:
            timeoutInMilliseconds: 10000

你可能感兴趣的:(关于Gateway知识的小结)