负载平衡
容错
异步模型中的多种协议支持
缓存和批处理
ribbon: 这是一个集成了负载平衡,容错,缓存的API
ribbon-loadbalancer: 这是一个负载平衡器API,可以单独使用或与其他模块一起使用。
ribbon eureka 它使用 Eureka 客户端,该客户端为Spring Cloud提供了动态服务器列表。
ribbon-transport: 这是支持 HTTP,TCP,和 UDP 的传输客户端,这些协议使用RxNetty 具有负载平衡功能。
ribbon-httpclient: 这是一个基于Apache HttpClient并与负载均衡器集成的REST客户端。
ribbon-core: 这是一个客户端配置API。
服务器端负载平衡: 服务器端负载平衡是整体式,它适用于客户端和服务器之间。它接受传入的网络,应用程序流量,并使用各种方法在多个后端服务器之间分配流量。中间组件负责将客户端请求分发到服务器。
客户端负载平衡: 客户端保存服务器IP列表,以便可以传递请求。客户端从列表中随机选择一个IP,然后将请求转发到服务器。
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-ribbon</artifactId> </dependency>
@RibbonClient(name="currency-exchange-service")
package com.lidihuo.microservices.currencyconversionservice; import org.springframework.cloud.netflix.ribbon.RibbonClient; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; //@FeignClient(name="currency-exchange-service", url="localhost:8000") //Enabling feign @FeignClient(name="currency-exchange-service") //enabling ribbon @RibbonClient(name="currency-exchange-service") public interface CurrencyExchangeServiceProxy { @GetMapping("/currency-exchange/from/{from}/to/{to}") //where {from} and {to} are path variable public CurrencyConversionBean retrieveExchangeValue(@PathVariable("from") String from, @PathVariable("to") String to); //from map to USD and to map to INR }
name-of-the-application.ribbon.listOfServers=URLs
currency-exchange-service.ribbon.listOfServers=http://localhost:8000, http://localhost:8001
spring.application.name=currency-conversion-service server.port=8100 currency-exchange-service.ribbon.listOfServers=http://localhost:8000, http://localhost:8001