当前位置:网站首页>Ribbon 服务调用与负载均衡
Ribbon 服务调用与负载均衡
2022-06-29 06:32:00 【喵先森爱吃鱼】
前面的内容学习,已经实现了服务的注册和服务发现。当启动某个服务的时候,可以通过 HTTP 的形式将信息注册到注册中心,并且可以通过 SpringCloud 提供的工具获取注册中心的服务列表。但是服务之间的调用还存在很多的问题,如何更加方便的调用微服务,多个微服务的提供者如何选择,如何负载均衡等。
一、Ribbon 概述
1.1 什么是 Ribbon
Ribbon 是 Netflix 发布的一个负载均衡器,有助于控制 HTTP 和 TCP 客户端行为。在 SpringCloud 中,Eureka 一般配合 Ribbon 进行使用,Ribbon 提供了客户端负载均衡的功能,Ribbon 利用从 Eureka 中读取到的服务信息,在调用服务节点提供的服务时,会合理的进行负载。
在 SpringCloud 中可以将注册中心和 Ribbon 配合使用,Ribbon 自动地从注册中心获取服务提供者的列表信息,并基于内置的负载均衡算法,请求服务。
1.2 Ribbon 的主要作用
(1)服务调用
基于 Ribbon 实现服务调用,是通过拉取到的所有服务列表组成(服务名-请求路径的)映射关系。借助 RestTemplate 最终进行调用。
(2)负载均衡
当多个服务提供者时,Ribbon 可以根据负载均衡的算法(如简单轮询、随机连接等)自动地选择需要调用的服务地址。
1.3 Ribbon 负载均衡和 Nginx 负载均衡的区别
LB 负载均衡(Load Balance)是什么?简单的说就是将用户的请求平摊的分配到多个服务上,从而达到系统的 HA(高可用)。常见的负载均衡有软件 Nginx,LVS,硬件 F5 等。
Nginx 是服务器负载均衡,客户端所有请求都会交给 Nginx,然后由 Nginx 实现转发请求,即负载均衡是由,服务端实现的。
Ribbon 本地负载均衡,在调用微服务接口的时候,会在注册中心上获取到注册信息服务列表之后,缓存到 JVM 本地,从而在 本地实现 RPC 远程服务调用技术。
集中式LB:即在服务的消费方和提供方之间使用独立的 LB 设施(可以是硬件,如 F5,也可以是软件,如 Nginx),由该设施负载把访问请求通过某种策略转发至服务的提供方。
进程内LB:将 LB 逻辑集成到消费方,消费方从服务注册中心获知有哪些地址可用,然后自己再从这些地址中选择出一个合适的服务器。Ribbon 就属于进程内 LB,它只是一个类库,集成于消费方进程,消费方通过它来获取到服务提供方的地址。
边栏推荐
- It turns out that the joys and sorrows of programmers are not interlinked
- About: deleting unwanted event log lists
- Single application and microservice application
- Week 10 - task 0- execution process instance resolution of constructors and destructors
- Hyperledger Fabric 2. X custom smart contract
- How to use regex in file find
- Delete tag
- Pointer from beginner to advanced (2)
- [chromium] win10 vs2019 environment chromium configuration and compilation.
- 力扣每日一题-第30天-1281.整数的各位积和之差
猜你喜欢

The echares map is implemented separately by provinces, and the tooltip user-defined prompt box, scattered annotation and scattered illumination are explained in detail

There are two ways for golang to develop mobile applications

Chapter V online logic analyzer signaltap

Failure: unable to log in to "taxpayer equity platform"

Pytest (7) -yield and termination function

Chapter IV introduction to FPGA development platform
![[deep learning] - maze task learning I (to realize the random movement of agents)](/img/c1/95b476ec62436a35d418754e4b11dc.jpg)
[deep learning] - maze task learning I (to realize the random movement of agents)
![[high concurrency] deeply analyze the callable interface](/img/fb/89ebd5592f1383c8015a47cec78a59.jpg)
[high concurrency] deeply analyze the callable interface

5,10,15,20-tetra (3,5-dimethoxyphenyl) porphyrin ((tdmpp) H2) /2-nitro-5,10,15,20-tetra (3,5-dimethoxyphenyl) porphyrin copper (no2tdmpp) Cu) supplied by Qiyue

力扣今日题-324. 摆动排序 II
随机推荐
Teach you how to develop your own NPM package (publish to the NPM official website)
Delete tag
Small program large screen adaptation Guide
Monitor employee turnover dynamics. This system makes employees tremble!
[deep learning] - maze task learning I (to realize the random movement of agents)
How to use regex in file find
Stack -- 739 Daily temperature
2022.02.14 - 239. A single element in an ordered array
Go compile source code (window environment)
Fault: NetBt log for id4321
Skills of writing test cases efficiently
Sourcetree remote red exclamation point
The first commercial spacewalk of mankind is finalized! Musk SpaceX announced a new round of space travel plan, and the American rich became repeat customers
Establishing the development environment of esp8266
Fault: KDC warning log for id29
2022.02.15
MySQL learning notes
Implementation of queue
P5 DS - component and document Association
Why can't the article be posted?