微服务负载均衡组件Ribbon——实战篇

Ribbon是一个有容错能力的客户端负载均衡器,支持HTTP\TCP\UDP协议,从前面Feign的源码可以看出来,默认Feign集成了Ribbon。下面是官方对Ribbon特性的一个简介。
Ribbon is a client side IPC library that is battle-tested in cloud. It provides the following features
Load balancing
Fault tolerance
Multiple protocol (HTTP, TCP, UDP) support in an asynchronous and reactive model
Caching and batching
值得注意的是Ribbon项目目前的状态为维护,也就是说官方不会有大规模程度的开发,提供新特性,理由是一方面Ribbon运行十分稳定,另一方面Netflex在研发基于gRPC的RPC框架,精力有限。
笔者也搜索了下有关RPC的项目,star数目在3000以上,用Java语言写的,发现有几个项目可以关注以下,如微博的motan,阿里巴巴的dubbo和谷歌的grpc,这些可以重点关注。

rpc in:readme stars:>3000 language:java

weibocom/motan
apache/dubbo
grpc/grpc-java
sofastack/sofa-boot
关于Spring与RPC的集成,Spring官方在2015年出了一篇文章描述spring boot如何集成谷歌的protocol buffers,不过反馈并不好,更多人希望这个功能集成在Spring的框架里,而不是在简单的CRUD操作里写一堆的controller。

Using Google Protocol Buffers with Spring MVC-based REST Services

有鉴于此,学习下dubbo在RPC方面的成果是很有益处的,有机会,笔者也会在未来的文章中加入在这一方面的探讨。
在讲Ribbon负载均衡实例之前还要说明一些参数,这样能更好地理解之后的演示代码。Ribbon的行为是由下面的七个Bean的行为所决定的,因此可以搭配不同的实现来满足负载均衡的要求,或者实现提供的接口来做自定义实现。

定义Ribbon行为的关键类

Bean Type

Bean Name

Class Name

Description

IClientConfig

ribbonClientConfig

DefaultClientConfigImpl

defines the client configuration used by various APIs to initialize clients or load balancers and for method execution

IRule

ribbonRule

ZoneAvoidanceRule

defines a "Rule" for a LoadBalancer

IPing ribbonPing DummyPing

defines how we "ping" a server to check if its alive

ServerList<Server> ribbonServerList ConfigurationBasedServerList defines the methods sed to obtain the list of servers

ServerListFilter<Server>

ribbonServerListFilter ZonePreferenceServerListFilter
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值