spring-cloud:覆盖功能区配置以实现Zone Affinity

时间:2015-01-28 13:45:49

标签: spring-cloud

我希望在负载平衡期间实现Zone Affinity。在日志中,我看到了DynamicServerListLoadBalancer'正在使用并根据行为看起来循环规则是活跃的。

我创建了自定义配置以覆盖RibbonClientConfiguration,但它不起作用。这是对的吗?

public class CustomConfiguration {

    @Autowired
    private IClientConfig config;

    @Autowired
    ServerListFilter<Server> filter;

    @Bean
    public ILoadBalancer ribbonLoadBalancer(IClientConfig config,
            ServerListFilter<Server> filter) {
        ZoneAwareLoadBalancer<Server> balancer = new ZoneAwareLoadBalancer<>(config);
        balancer.setFilter(filter);
        return balancer;
    }

    @Bean
    public ServerListFilter<Server> ribbonServerListFilter(IClientConfig config) {
        ZonePreferenceServerListFilter filter = new ZonePreferenceServerListFilter();
        filter.initWithNiwsConfig(config);
        return filter;
    }
}

@Configuration
@RibbonClient(name = "custom", configuration = CustomConfiguration.class)
public class CustomApplicationConfiguration {
}

0 个答案:

没有答案