Spring Cloud Gateway 指定 Ribbon 策略

		<spring.boot.version>2.3.1.RELEASEspring.boot.version>
        <spring-cloud.version>Hoxton.SR6spring-cloud.version>

spring cloud gateway 配置路由后使用 ribbon 的ZoneAvoidanceRule的规则。

想使用其他规则:

一.Bean注入

@Configuration
public class AppConfiguration {
    @Bean
    public IRule ribbonRule() {
        return new RandomRule();
    }
}

二.配置文件

spring:
  application:
    name: mp-api-gateway
  profiles:
    active: @env@
  cloud:
    gateway:
      enabled: true
      httpclient:
        response-timeout: 240000ms
        connect-timeout: 10000
      routes:
        - id: server1
          uri: lb://server1
          predicates:
            - Path=/**
##server1服务设置随机策略
server1:
  ribbon:
    NFLoadBalancerRuleClassName: com.netflix.loadbalancer.RandomRule

[clientName].ribbon.NFLoadBalancerClassName: Should implement ILoadBalancer
[clientName].ribbon.NFLoadBalancerRuleClassName: Should implement IRule
[clientName].ribbon.NFLoadBalancerPingClassName: Should implement IPing
[clientName].ribbon.NIWSServerListClassName: Should implement ServerList
[clientName].ribbon.NIWSServerListFilterClassName: Should implement ServerListFilter

参考:https://cloud.spring.io/spring-cloud-netflix/multi/multi_spring-cloud-ribbon.html

你可能感兴趣的:(springcloud)