Ribbon 负载均衡 IRule

package com.service.config;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import com.netflix.loadbalancer.RetryRule;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

@Configuration
public class Dept_Config {

@Bean
@LoadBalanced
public RestTemplate getRestTemplate(){
return new RestTemplate();
}

@Bean
public IRule myRule(){

// RoundRobinRule 轮询
// RandomRule 随机
return new RetryRule();
}
}

自定义Ribbon
1.加载注解

2.配置mySelfRule.class

3.自定义时要实现

猜你喜欢

转载自www.cnblogs.com/mm163/p/10590231.html