spring cloud ribbon
简介
ribbon
用以实现负载均衡;实现软负载均衡,核心有三点:
- 服务发现,发现依赖服务的列表
- 服务选择规则,在多个服务中如何选择一个有效服务
- 服务监听,检测失效的服务,高效剔除失效服务
netflix ribbon
一个简单的demo
配置文件:
# Max number of retries on the same server (excluding the first try)
sample-client.ribbon.MaxAutoRetries=1
# Max number of next servers to retry (excluding the first server)
sample-client.ribbon.MaxAutoRetriesNextServer=1
# Whether all operations can be retried for this client
sample-client.ribbon.OkToRetryOnAllOperations=true
# Interval to refresh the server list from the source
sample-client.ribbon.ServerListRefreshInterval=2000
# Connect timeout used by Apache HttpClient
sample-client.ribbon.ConnectTimeout=3000
# Read timeout used by Apache HttpClient
sample-client.ribbon.ReadTimeout=3000
# Initial list of servers, can be changed via Archaius dynamic property at runtime
sample-client.ribbon.listOfServers=www.u51.xin:80,www.baidu.com:80,www.163.com:80,www.csdn.net:80
配置格式为 clientName.spaceName.params
核心配置sample-client.ribbon.listOfServers
表明有效的服务列表
BasicTest.java
package com.lkl.springcloud.ribbon;
import com.netflix.client.ClientFactory;
import com<