博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring Cloud构建微服务架构(二)服务消费者
阅读量:6436 次
发布时间:2019-06-23

本文共 2917 字,大约阅读时间需要 9 分钟。

 

Netflix Ribbon is an Inter Process Communication (IPC) cloud library. Ribbon primarily provides client-side load balancing algorithms.

Apart from the client-side load balancing algorithms, Ribbon provides also other features:

Service Discovery Integration – Ribbon load balancers provide service discovery in dynamic environments like a cloud. Integration with Eureka and Netflix service discovery component is included in the ribbon library

Fault Tolerance – the Ribbon API can dynamically determine whether the servers are up and running in a live environment and can detect those servers that are down
Configurable load-balancing rules – Ribbon supports RoundRobinRule, AvailabilityFilteringRule, WeightedResponseTimeRule out of the box and also supports defining custom rules
Ribbon API works based on the concept called “Named Client”. While configuring Ribbon in our application configuration file we provide a name for the list of servers included for the load balancing.

Let’s take it for a spin.

Ribbon Configuration

Ribbon API enables us to configure the following components of the load balancer:

Rule – Logic component which specifies the load balancing rule we are using in our application

Ping – A Component which specifies the mechanism we use to determine the server’s availability in real-time
ServerList – can be dynamic or static. In our case, we are using a static list of servers and hence we are defining them in the application configuration file directly

public class RibbonConfiguration {     @Autowired    IClientConfig ribbonClientConfig;     @Bean    public IPing ribbonPing(IClientConfig config) {        return new PingUrl();    }     @Bean    public IRule ribbonRule(IClientConfig config) {        return new WeightedResponseTimeRule();    }}

Notice how we used the WeightedResponseTimeRule rule to determine the server and PingUrl mechanism to determine the server’s availability in real-time.

According to this rule, each server is given a weight according to its average response time, lesser the response time gives lesser the weight. This rule randomly selects a server where the possibility is determined by server’s weight.

And the PingUrl will ping every URL to determine the server’s availability.

http://www.baeldung.com/spring-cloud-rest-client-with-netflix-ribbon

 

在上一篇中,我们已经成功创建了“服务注册中心”,实现并注册了一个“服务提供者:COMPUTE-SERVICE”。那么我们要如何去消费服务提供者的接口内容呢?

Ribbon

Ribbon是一个基于HTTP和TCP客户端的负载均衡器。Feign中也使用Ribbon,后续会介绍Feign的使用。

Ribbon可以在通过客户端中配置的ribbonServerList服务端列表去轮询访问以达到均衡负载的作用。

当Ribbon与Eureka联合使用时,ribbonServerList会被DiscoveryEnabledNIWSServerList重写,扩展成从Eureka注册中心中获取服务端列表。同时它也会用NIWSDiscoveryPing来取代IPing,它将职责委托给Eureka来确定服务端是否已经启动。

下面我们通过实例看看如何使用Ribbon来调用服务,并实现客户端的均衡负载。

准备工作

  • 启动中的服务注册中心:eureka-server
  • 启动中的服务提供方:compute-service
  • 修改compute-service中的server-port为2223,再启动一个服务提供方:compute-service

此时访问:

http://blog.didispace.com/springcloud2/

 

转载于:https://www.cnblogs.com/softidea/p/6590020.html

你可能感兴趣的文章
C/C++ 一段代码区分数组指针|指针数组|函数指针|函数指针数组
查看>>
awakeFromNib小总结
查看>>
java知识大全积累篇
查看>>
善于总结所做所学的内容
查看>>
Lua-简洁、轻量、可扩展的脚本语言
查看>>
org.hibernate.MappingException: entity class not found hbm可以解析,但是实体类不能解析...
查看>>
Android -- Drag&&Drop
查看>>
Extjs4:改变Grid单元格背景色(转载)
查看>>
中医无绝症[转载]
查看>>
ZendStudio10.6.1如何安装最新的集成svn小工具?
查看>>
PHP中$_SERVER的详细参数与说明
查看>>
jquery easyui datagrid mvc server端分页排序筛选的实现
查看>>
去了大公司就一定能学到很牛的技术么?
查看>>
methanol 模块化的可定制的网页爬虫软件,主要的优点是速度快。
查看>>
IOS开发之表视图(UITableView)
查看>>
Notepad++去除代码行号的几种方法
查看>>
polay定理总结
查看>>
IIS如何配置可以下载APK、IPA文件
查看>>
CodeForces 396C 树状数组 + DFS
查看>>
[sharepoint]rest api文档库文件上传,下载,拷贝,剪切,删除文件,创建文件夹,修改文件夹属性,删除文件夹,获取文档列表...
查看>>