spring-cloud: eureka之:ribbon負載平衡配置(一)

來源:互聯網
上載者:User

標籤:cli   use   app   mapping   ping   repos   ase   pos   autowired   

spring-cloud: eureka之:ribbon負載平衡配置(一)

比如我有:

一個eureka服務:8761

兩個user使用者服務: 7900/7901連接埠

一個movie服務:8010

 

1.啟動eureka服務後

2.同事啟動user的兩個服務

3.啟動movie服務

 

eureka服務開機檔案加入:

@EnableEurekaServer

 

user/movie伺服器開機檔案加入

@EnableEurekaClient

 

user服務提供介面:
http://spring-boot-user:7900/simple/1

http://spring-boot-user:7901/simple/1

@RestControllerpublic class UserController {@Autowiredprivate UserRepository userRepository;@GetMapping("/simple/{id}")public User findById(@PathVariable Long id){return userRepository.findOne(id);}}

 

 

movie服務開機檔案加入:

@Bean@LoadBalancedpublic RestTemplate restTemplate() {return new RestTemplate();}

 

movie服務檔案movieController.java調用user服務

@RestControllerpublic class MovieController {@Autowiredprivate RestTemplate restTemplate;@GetMapping("/movie/{id}")public User findById(@PathVariable Long id){//http://localhost:7900/simple/return restTemplate.getForObject("http://spring-boot-user/simple/" + id, User.class);}}

 

 

 

http://spring-boot-user/simple/

spring-cloud: eureka之:ribbon負載平衡配置(一)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.