Ribbon基础入门和特性讲解

本文介绍了Ribbon负载均衡器的基本概念及使用方法,Ribbon作为一个客户端负载均衡器,提供了丰富的配置选项来控制HTTP和TCP客户端的行为。文章还详细解释了如何在Spring Boot项目中集成并自定义Ribbon配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转载请注明出处 http://www.paraller.com 原文排版地址 点击获取更好阅读体验

介绍

ribbon 是一个客户端负载均衡器,可以简单的理解成类似于 nginx的负载均衡模块的功能。

Ribbon is a client side load balancer which gives you a lot of control over the behaviour of HTTP and TCP clients. Feign already uses Ribbon, so if you are using @FeignClient then this section also applies.

使用方法

application.yml:

ribbon: eureka: enabled: true MaxAutoRetries: 0 MaxAutoRetriesNextServer: 0

ps:有一些属性是在feign中使用的 , 在配置文件中配置不生效; springboot中的feign集成了ribbon

pom.xml:

因为是在feign中集成的 ,所以参考feign的依赖

程序入口添加注释:

```

@RibbonClient(name = "yea-ribbon", configuration = YeaRibbonConfiguration.class) public class Application {

public static void main(String[] args) {feign
    SpringApplication.run(Application.class, args);
}

}

```

自定义属性:RibbonConfiguration

``` public class YeaRibbonConfiguration {

@Autowired
IClientConfig ribbonClientConfig;

@Bean
public IPing ribbonPing(IClientConfig config) {
    return new PingUrl();
}

@Bean
public IRule ribbonRule(IClientConfig config) {
    return new AvailabilityFilteringRule();
}

}

```

其他知识点

自定义 Ribbon client

可以使用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值