spring cloud: 关闭ribbon负载均衡

1.eureka服务

2.2个user服务:7900/7901

3,movie服务

movie服务去请求 user的用户信息,而此时只想请求7900不想请求7901服务

user服务名:

spring-boot-user:7900

spring-boot-user: 7901

那么可以在配置文件中配置:

application.properties

#close-eureka
ribbon.eureka.enabled=false
#only-visted-spring-boot-user:7900
spring-boot-user.ribbon.listOfServers=localhost:7900

  

movie服务启动文件:

@EnableEurekaClient
@SpringBootApplication
public class BootMovieApplication { @Bean
public RestTemplate restTemplate() {
return new RestTemplate();
} public static void main(String[] args) {
SpringApplication.run(BootMovieApplication.class, args);
}
}

  

movieController.java

@Autowired
private LoadBalancerClient loadBalancerClient; @Autowired
private RestTemplate restTemplate; @GetMapping("/test1")
public String findById()
{
//http://localhost:7900/simple/
ServiceInstance serviceInstance = this.loadBalancerClient.choose("spring-boot-user");
System.out.println("111:"+serviceInstance.getServiceId() + ":" + serviceInstance.getHost() + ":" + serviceInstance.getPort()); return "1";
}

  

04-26 12:40