Ribbon基础入门和特性讲解

来源:互联网 发布:java 1603 编辑:程序博客网 时间:2024/06/08 08:42

转载请注明出处 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 {

@AutowiredIClientConfig ribbonClientConfig;@Beanpublic IPing ribbonPing(IClientConfig config) {    return new PingUrl();}@Beanpublic IRule ribbonRule(IClientConfig config) {    return new AvailabilityFilteringRule();}

}

```

其他知识点

自定义 Ribbon client

可以使用