Ribbon Loadbalance核心接口是什么,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。
IRule
ILoadBalancer
ServerList
ServerListFilter
IPing
配置入口:RibbonClientConfiguration
合适的方式选择合适的节点
接口定义:com.netflix.loadbalancer.ILoadBalancer
核心方法:
/**
* Choose a server from load balancer.
*
* @param key An object that the load balancer may use to determine which server to return. null if
* the load balancer does not use this parameter.
* @return server chosen
*/
public Server chooseServer(Object key);
/**
* @return Only the servers that are up and reachable.
*/
public List<Server> getReachableServers();
/**
* @return All known servers, both reachable and unreachable.
*/
public List<Server> getAllServers();
核心作用:维护全量服务列表及可用列表,依赖IPing接口标记失效节点,标识失效依赖IPing实现
默认实现:ZoneAwareLoadBalancer
接口定义:com.netflix.loadbalancer.IRule
核心方法:
/*
* choose one alive server from lb.allServers or
* lb.upServers according to key
*
* @return choosen Server object. NULL is returned if none
* server is available
*/
public Server choose(Object key);
核心作用:从loadbalance里面选取一个server;提供多种选择策略
默认实现:ZoneAvoidanceRule
接口定义:com.netflix.loadbalancer.ServerList
核心方法:
/**
* Return updated list of servers. This is called say every 30 secs
* (configurable) by the Loadbalancer's Ping cycle
*
*/
public List<T> getUpdatedListOfServers();
核心作用:获取更新服务列表
默认实现:ConfigurationBasedServerList
接口定义:com.netflix.loadbalancer.ServerListFilter
核心方法:
public List<T> getFilteredListOfServers(List<T> servers);
核心作用:
默认实现:ZonePreferenceServerListFilter
接口定义:com.netflix.loadbalancer.IPing
核心方法:
/**
* Checks whether the given <code>Server</code> is "alive" i.e. should be
* considered a candidate while loadbalancing
*
*/
public boolean isAlive(Server server);
核心作用:检测特定服务是否活着,在ILoadBalance中做失效服务检测作用
默认实现:DummyPing
Ribbon最大的有点就是允许用户定制化各种规则,很好的管理了节点状态及访问规则,基于规则扩展做一些好用的产品,比如灰度管理、目标节点能力不对等下的权重控制
看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注亿速云行业资讯频道,感谢您对亿速云的支持。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。
原文链接:https://my.oschina.net/yugj/blog/4494780