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

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

Ribbon

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

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

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

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

准备工作

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

此时访问:http://localhost:1111/

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

Spring Cloud构建微服务架构(二)服务消费者的更多相关文章

  1. Spring Cloud构建微服务架构

    Dalston版本 由于Brixton和Camden版本的教程已经停止更新,所以笔者计划在2017年上半年完成Dalston版本的教程编写(原计划完成Camden版本教程,但由于写了两篇Dalston ...

  2. Spring Cloud构建微服务架构(三)消息总线

     注:此文不适合0基础学习者直接阅读,请先完整的将作者关于微服务的博文全部阅读一遍,如果还有疑问,可以再来阅读此文,地址:http://blog.csdn.net/sosfnima/article/d ...

  3. 《Spring Cloud构建微服务架构》系列博文示例

    SpringCloud-Learning   源码下载地址:http://download.csdn.net/detail/k21325/9650968     本项目内容为Spring Cloud教 ...

  4. Spring Cloud构建微服务架构:服务网关(路由配置)【Dalston版】

    转载:http://blog.didispace.com/spring-cloud-starter-dalston-6-2/ 原创  2017-08-26  翟永超  Spring Cloud 被围观 ...

  5. Cola Cloud 基于 Spring Boot, Spring Cloud 构建微服务架构企业级开发平台

    Cola Cloud 基于 Spring Boot, Spring Cloud 构建微服务架构企业级开发平台: https://gitee.com/leecho/cola-cloud

  6. Spring Cloud构建微服务架构(五)服务网关

    通过之前几篇Spring Cloud中几个核心组件的介绍,我们已经可以构建一个简略的(不够完善)微服务架构了.比如下图所示: 我们使用Spring Cloud Netflix中的Eureka实现了服务 ...

  7. Spring Cloud构建微服务架构 - 服务网关

    通过之前几篇Spring Cloud中几个核心组件的介绍,我们已经可以构建一个简略的(不够完善)微服务架构了.比如下图所示: alt 我们使用Spring Cloud Netflix中的Eureka实 ...

  8. Spring Cloud构建微服务架构(二)分布式配置中心

     注:此文不适合0基础学习者直接阅读,请先完整的将作者关于微服务的博文全部阅读一遍,如果还有疑问,可以再来阅读此文,地址:http://blog.csdn.net/sosfnima/article/d ...

  9. 第1章 Spring Cloud 构建微服务架构(一)服务注册与发现

      一.Spring Cloud 简介 Spring Cloud是一个基于Spring Boot实现的云应用开发工具,它为基于JVM的云应用开发中的配置管理.服务发现.断路器.智能路由.微代理.控制总 ...

随机推荐

  1. linux内核 container_ofC语言之应用

    之前在剖析内核链表的文章中就有说到这个 container_of宏展开后的应用技巧. //offset(struct list , list);----->展开后((size_t) & ...

  2. Erlang和Web

    Erlang和Web 本文译自: http://ninenines.eu/docs/en/cowboy/1.0/guide/erlang_web/ Web是并发的 当你访问一个网站,很少有并发.几个连 ...

  3. PHP 查询脚本

    POST查询以表格传参数支持中文,GET不支持. POST查询: <?php $id=$_POST["id"];//id(中括号)为传来的参数,$id为php中的变量 //l ...

  4. nasm中的表达式

    nasm表达式支持2个特殊的记号 $和$$;前者标识其所在源码行的开始处地址,所以你可以这样写死循环: jmp $ 而后者标识当前段开始处的地址,你可以通过: $-$$ 找出当前代码在段内的偏移. n ...

  5. mybatis中autoCommit自动提交事务

    今天学习了下mybatis, 对其中的autoCommit自动提交事务比较好奇, 研究了下,把配置和代码都放上 mapper.xml如下: <?xml version="1.0&quo ...

  6. 听晴明老师从头讲React Native 百度云下载 百度网盘

    适用人群 能使用至少一门主流编程语言:有基本的面向对象的概念:最好有一些web相关的知识和概念. 课程概述 新颖.实用.详尽的ReactNative零基础课程,由国内权威的ReactNative中文网 ...

  7. 布局display属性(一)--【Flex】

    一.Flex 布局是什么? Flex 是 Flexible Box 的缩写,意为"弹性布局",用来为盒状模型提供最大的灵活性. 任何一个容器都可以指定为 Flex 布局. .box ...

  8. javascript学习(一)构建自己的JS库

    库是一个饱受争议的热门话题.一种观点认为它是一种非常棒的工具,是任何开发者都不可或缺的:另一种观点则认为在不理解库的内部工作原理的情况下对库形成依赖,会助长懒惰的风气从而导致开发者素质下降 库是一个饱 ...

  9. oracle to_date 函数

    update pamsodt0p10 set cursysdate =  to_date('2014-12-29 00:00:00','yyyy-mm-dd hh24:mi:ss') where cu ...

  10. python3 数据科学基础

    第一章 1.Anaconda(最著名的python数据科学平台) 下面小伙伴们咱们来初初识下Anaconda吧 What is Anaconda???? 回答: (1).科学计算的平台 (2).有很多 ...