com.netflix.loadbalancer.IRule Java Examples
The following examples show how to use
com.netflix.loadbalancer.IRule.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LBBuilderTest.java From ribbon with Apache License 2.0 | 6 votes |
@Test public void testBuildWithDiscoveryEnabledNIWSServerListAndUpdater() { IRule rule = new AvailabilityFilteringRule(); ServerList<DiscoveryEnabledServer> list = new DiscoveryEnabledNIWSServerList("dummy:7001"); ServerListFilter<DiscoveryEnabledServer> filter = new ZoneAffinityServerListFilter<>(); ServerListUpdater updater = new PollingServerListUpdater(); ZoneAwareLoadBalancer<DiscoveryEnabledServer> lb = LoadBalancerBuilder.<DiscoveryEnabledServer>newBuilder() .withDynamicServerList(list) .withRule(rule) .withServerListFilter(filter) .withServerListUpdater(updater) .buildDynamicServerListLoadBalancerWithUpdater(); assertNotNull(lb); assertEquals(Lists.newArrayList(expected), lb.getAllServers()); assertSame(filter, lb.getFilter()); assertSame(list, lb.getServerListImpl()); assertSame(updater, lb.getServerListUpdater()); Server server = lb.chooseServer(); // make sure load balancer does not recreate the server instance assertTrue(server instanceof DiscoveryEnabledServer); }
Example #2
Source File: LBBuilderTest.java From ribbon with Apache License 2.0 | 6 votes |
@Test public void testBuildWithDiscoveryEnabledNIWSServerList() { IRule rule = new AvailabilityFilteringRule(); ServerList<DiscoveryEnabledServer> list = new DiscoveryEnabledNIWSServerList("dummy:7001"); ServerListFilter<DiscoveryEnabledServer> filter = new ZoneAffinityServerListFilter<>(); ZoneAwareLoadBalancer<DiscoveryEnabledServer> lb = LoadBalancerBuilder.<DiscoveryEnabledServer>newBuilder() .withDynamicServerList(list) .withRule(rule) .withServerListFilter(filter) .buildDynamicServerListLoadBalancer(); assertNotNull(lb); assertEquals(Lists.newArrayList(expected), lb.getAllServers()); assertSame(filter, lb.getFilter()); assertSame(list, lb.getServerListImpl()); Server server = lb.chooseServer(); // make sure load balancer does not recreate the server instance assertTrue(server instanceof DiscoveryEnabledServer); }
Example #3
Source File: RouterClientConfiguration.java From spring-cloud-huawei with Apache License 2.0 | 5 votes |
@Bean public IRule ribbonRule( @Autowired(required = false) IClientConfig config) { ZoneAvoidanceRule rule = new RouterLoadBalanceRule(); rule.initWithNiwsConfig(config); return rule; }
Example #4
Source File: HmilyLoadBalancerConfiguration.java From hmily with Apache License 2.0 | 5 votes |
/** * Hmily load balancer rule. * * @return the rule */ @Bean @ConditionalOnProperty(name = "hmily.ribbon.rule.enabled") @Scope("prototype") public IRule hmilyLoadBalancer() { return new HmilyZoneAwareLoadBalancer(); }
Example #5
Source File: LBBuilderTest.java From ribbon with Apache License 2.0 | 5 votes |
@Test public void testBuildStaticServerListLoadBalancer() { List<Server> list = Lists.newArrayList(expected, expected); IRule rule = new AvailabilityFilteringRule(); IClientConfig clientConfig = IClientConfig.Builder.newBuilder() .withDefaultValues() .withMaxAutoRetriesNextServer(3).build(); assertEquals(3, clientConfig.get(Keys.MaxAutoRetriesNextServer).intValue()); BaseLoadBalancer lb = LoadBalancerBuilder.newBuilder() .withRule(rule) .buildFixedServerListLoadBalancer(list); assertEquals(list, lb.getAllServers()); assertSame(rule, lb.getRule()); }
Example #6
Source File: EurekaRibbonConfig.java From fw-spring-cloud with Apache License 2.0 | 5 votes |
@Bean public IRule ribbonRule() { //默认ZoneAvoidanceRule请求,实现自定义的规则 //自定义成随机 return new RandomRule(); }
Example #7
Source File: RouteListener.java From spring-cloud-formula with Apache License 2.0 | 5 votes |
/** * 监听EnvironmentChangeEvent 事件,更改相关环境变量 * @param event */ @Override @EventListener(EnvironmentChangeEvent.class) public void onApplicationEvent(EnvironmentChangeEvent event) { try { LOGGER.info("environment change."); Map<String, Object> propertySource = Maps.newHashMap(); if (!routeMatcher.match()) { LOGGER.info("this route rules does not match this instance."); return; } // 多条路由规则已先后顺序进行匹配 FormulaRouteProperty formulaRouteProperty = routeMatcher.getMatchedFormulaRouteProperty(); // 获取新的负载均衡策略 String iRuleName = formulaRouteProperty.getLoadbalance(); String destServiceName = formulaRouteProperty.getDestServiceName(); IRule oldRule = springClientFactory.getInstance(destServiceName, IRule.class); if (oldRule instanceof WeightedResponseTimeRule) { // 关闭线程池 ((WeightedResponseTimeRule) oldRule).shutdown(); } // 清理ribbon 中 所有的client的负载均衡器配置,更改环境变量值,等待下次重新加载client的负载均衡配置 springClientFactory.destroy(); // 按照ribbon的规范,配置IRule String configClientRule = destServiceName + "." + CONFIG_NAMESPACE + "." + CONFIG_RULE_CLASS; propertySource.put(configClientRule, IRuleInfo.getRulePath(iRuleName)); // 加入至环境变量中 this.configurableEnvironment.getPropertySources().addFirst(new RoutePropertySource(ROUTE_PROPERTY_SOURCE, propertySource)); } catch (Exception e) { LOGGER.error("refresh route rule exception: {}", e); } }
Example #8
Source File: RibbonCientConfiguration.java From summerframework with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnMissingBean public IRule ribbonRule(IClientConfig config) { if (this.propertiesFactory.isSet(IRule.class, name)) { return this.propertiesFactory.get(IRule.class, config, name); } ZoneAvoidanceAndGrayAndLoadBasedRule rule = new ZoneAvoidanceAndGrayAndLoadBasedRule(); rule.initWithNiwsConfig(config); return rule; }
Example #9
Source File: RuleBaseConfig.java From spring-cloud-ribbon-extensions with Apache License 2.0 | 5 votes |
/** * The load balancer definition. * * @param config the client config. * @param serverList the server list. * @param serverListFilter the server list filter. * @param rule the load balancing rule. * @param ping the ping strategy. * @param serverListUpdater the server list updater. * @return The Dynamic Server List Load Balancer. */ @Bean @ConditionalOnMissingBean public ILoadBalancer loadBalancer(IClientConfig config, ServerList<Server> serverList, ServerListFilter<Server> serverListFilter, IRule rule, IPing ping, ServerListUpdater serverListUpdater) { log.debug("dynamic server list load balancer enabled."); return new DynamicServerListLoadBalancer<>(config, rule, ping, serverList, serverListFilter, serverListUpdater); }
Example #10
Source File: RadarRibbonClientConfiguration.java From radar with Apache License 2.0 | 5 votes |
@Bean public ILoadBalancer createLoadBalancer(ServerList<? extends Server> serverList, IClientConfig config, IRule rule, IPing ping) { if (this.propertiesFactory.isSet(ILoadBalancer.class, serviceId)) { return this.propertiesFactory.get(ILoadBalancer.class, config, serviceId); } ILoadBalancer iLoadBalancer = new RadarLoadBalancer(serverList, config, rule, ping); return iLoadBalancer; }
Example #11
Source File: RadarRibbonClientConfiguration.java From radar with Apache License 2.0 | 5 votes |
@Bean public IRule createRule(IClientConfig config) { if (this.propertiesFactory.isSet(IRule.class, serviceId)) { return this.propertiesFactory.get(IRule.class, config, serviceId); } // return new RadarRandomRule(); return new RoundRobinRule(); }
Example #12
Source File: GrayRibbonClientsConfiguration.java From spring-cloud-gray with Apache License 2.0 | 5 votes |
@Bean public IRule ribbonRule( @Autowired(required = false) IClientConfig config) { ZoneAvoidanceRule rule = null; if(GrayClientHolder.getServerChooser()!=null){ rule = new GrayChooserRule(); }else{ rule = new GrayLoadBalanceRule(); } rule.initWithNiwsConfig(config); return rule; }
Example #13
Source File: LoadbalancerConfiguration.java From tx-lcn with Apache License 2.0 | 4 votes |
@Bean @ConditionalOnProperty(name = "tx-lcn.ribbon.loadbalancer.dtx.enabled", matchIfMissing = true) @Scope("prototype") public IRule ribbonRule(Registration registration) { return new TxlcnZoneAvoidanceRule(registration); }
Example #14
Source File: RestConfiguration.java From spring-boot-demo with MIT License | 4 votes |
/** * 随机选取负载均衡策略 * @return */ @Bean public IRule testRule() { return new RandomRule(); }
Example #15
Source File: SayHelloConfiguration.java From spring-boot-inside with MIT License | 4 votes |
@Bean public IRule ribbonRule(IClientConfig config) { return new AvailabilityFilteringRule(); }
Example #16
Source File: RibbonConfiguration.java From spring-cloud-docker-microservice-book-code with Apache License 2.0 | 4 votes |
@Bean public IRule ribbonRule() { // 负载均衡规则,改为随机 return new RandomRule(); }
Example #17
Source File: RibbonConfiguration.java From Mastering-Spring-Cloud with MIT License | 4 votes |
@Bean public IRule ribbonRule() { return new WeightedResponseTimeRule(); }
Example #18
Source File: RibbonConfiguration.java From code-examples with MIT License | 4 votes |
@Bean public IRule ribbonRule(IClientConfig config) { return new RandomRule(); }
Example #19
Source File: RibbonConfiguration.java From spring-cloud-docker-microservice-book-code with Apache License 2.0 | 4 votes |
@Bean public IRule ribbonRule() { // 负载均衡规则,改为随机 return new RandomRule(); }
Example #20
Source File: RibbonConfiguration.java From tutorials with MIT License | 4 votes |
@Bean public IRule ribbonRule() { return new WeightedResponseTimeRule(); }
Example #21
Source File: RibbonConfiguration.java From tutorials with MIT License | 4 votes |
@Bean public IRule ribbonRule(IClientConfig config) { return new WeightedResponseTimeRule(); }
Example #22
Source File: RibbonApplication.java From micro-service with Apache License 2.0 | 4 votes |
@Bean public IRule ribbonRule() { return new RandomRule(); }
Example #23
Source File: MyDefaultRibbonConfig.java From spring-cloud-release-tools with Apache License 2.0 | 4 votes |
@Bean public IRule ribbonRule() { return new BestAvailableRule(); }
Example #24
Source File: RestRibbonEasyTransRpcConsumerImpl.java From EasyTransaction with Apache License 2.0 | 4 votes |
@Bean public IRule easyTransLoadBalanceRule(){ return new StickyBestAvailableRule(); }
Example #25
Source File: RadarLoadBalancer.java From radar with Apache License 2.0 | 4 votes |
public RadarLoadBalancer(ServerList<? extends Server> serverList, IClientConfig config, IRule rule, IPing ping) { super(config, rule, ping); this.serverList = serverList; }
Example #26
Source File: RibbonTimeConfig.java From Spring with Apache License 2.0 | 4 votes |
@Bean public IRule ribbonRule(){ return new RandomRule(); }
Example #27
Source File: RibbonServiceConfiguration.java From Spring with Apache License 2.0 | 4 votes |
@Bean public IRule iRule(IClientConfig iClientConfig) { return new AvailabilityFilteringRule(); }
Example #28
Source File: RibbonConfiguration.java From springcloud-study with Apache License 2.0 | 4 votes |
@Bean public IRule ribbonRule(){ //随机负载 return new RandomRule(); }
Example #29
Source File: CustomIloadBalancer.java From spring-cloud-formula with Apache License 2.0 | 4 votes |
public CustomIloadBalancer(IClientConfig config, IRule rule, IPing ping, ServerList serverList, ServerListFilter serverListFilter, ServerListUpdater serverListUpdater) { super(config, rule, ping, serverList, serverListFilter, serverListUpdater); }
Example #30
Source File: EurekaRibbonConfig.java From fw-spring-cloud with Apache License 2.0 | 4 votes |
@Bean public IRule ribbonRule() { //自定义成随机 return new RandomRule(); }