日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

spring cloud整合Ribbon

發(fā)布時(shí)間:2024/9/19 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 spring cloud整合Ribbon 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

spring cloud整合Ribbon

使用Eureka中自帶的Ribbon

如果你使用的是Eureka做服務(wù)發(fā)現(xiàn)和注冊的話,在比較新版本的Eureka中,Eureka已經(jīng)集成了Ribbon進(jìn)入Eureka中,當(dāng)你引入

dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-clientr</artifactId> </dependency>

使用十分簡單,只需要在服務(wù)消費(fèi)端的RestTemplate的配置類上添加@LoadBalanced即可。

@Configuration public class ApplicationContextConfig {@Bean@LoadBalancedpublic RestTemplate getRestTemplate(){return new RestTemplate();} }

使用獨(dú)立的Ribbon

配置輪詢規(guī)則

自定義一個(gè)RibbonConfiguration配置類。在配置類中創(chuàng)建IRule規(guī)則,指定輪詢算法,這里使用Ribbon自帶的隨機(jī)輪詢

@Configuration public class RibbonConfiguration {@Autowiredprivate IClientConfig config;@Beanpublic IRule ribbonRule(IClientConfig config) { // 自定義為隨機(jī)規(guī)則return new RandomRule();} }

主啟動類

在spring的主啟動類上添加@RibbonClient注解,來使用Ribbon

@SpringBootApplication @RibbonClient(name = "consumer-payment",configuration = RibbonConfiguration.class) public class OrderApplication {public static void main(String[] args) {SpringApplication.run(OrderApplication.class,args);} }

總結(jié)

以上是生活随笔為你收集整理的spring cloud整合Ribbon的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。