当前位置:网站首页>Ribbon-负载均衡原理及部分源码
Ribbon-负载均衡原理及部分源码
2022-07-27 03:19:00 【茂桑】
前提:服务提供者有多个服务集群,不然要是只有一个服务,还负载均衡个锤子!
Ribbon负载均衡基本原理:
1、Ribbon会拦截Eureka Client客户端发出的http请求,获得服务名(userservice)
2、从Eureka中拉取动态服务列表(8081、8082。。。。。)
3、从里面选一个服务(如8081)出来(轮询、随机等算法)
4、去调用这个服务
详细步骤:
1、客户端发起http请求,比如使用RestTemplate发起;
2、LoadBalancerInterceptor负载均衡拦截器,会拦截所有这个客户端发起的http请求,进行解析,获取服务ID(实例名例如:userservice);
3、通过这个实例名,从Eureka中拉取动态服务列表;
4、Eureka返回服务列表,此时LoadBalancerInterceptor负载均衡拦截器拿到了所有的该服务实例;
5、使用IRule接口进行负载均衡,IRule规则接口包括:客户端自定义规则、轮询、随机、重试等负载均衡算法:
6、使用客户端规定好的,或者默认的负载均衡算法,从服务列表中进行选择一个,返回给RibbonLoadBanlancerClient(Ribbon负载均衡器客户端)
7、RibbonLoadBanlancerClient(Ribbon负载均衡器客户端)使用真实的ip和端口(http://127.0.0.1:8080/user/1)替换原来的“服务名+路径”(http://userservice/user/1),并发起请求
8、最终,请求到经过负载均衡之后选择的对应的服务器
当使用@LoadBalanced注解时,会自动调用spring-cloud中的Ribbon组件进行负载均衡,我们只需配置Ribbon的算法即可按我们心意进行使用
边栏推荐
- 356页14万字高端商业办公综合楼弱电智能化系统2022版
- Parallel desktop startup virtual machine "operation failed" problem solution
- Big talk · book sharing | lean product development: principles, methods and Implementation
- Manually build ABP framework from 0 -abp official complete solution and manually build simplified solution practice
- 物联网智能家居项目---智能卧室
- C语言学习笔记 —— 内存管理
- First pass of routing strategy
- Redis database, which can be understood by zero foundation Xiaobai, is easy to learn and use!
- 大咖说·图书分享|精益产品开发:原则、方法与实施
- 利用LCD1602显示超声波测距
猜你喜欢

零基础小白也能懂的 Redis 数据库,手把手教你易学易用!

【比赛参考】PyTorch常用代码段以及操作合集

Maximum subarray cumulative sum less than or equal to K

什么是动画效果?什么是过渡效果?

Navicat将MySQL导出表结构以及字段说明

2022危险化学品生产单位安全生产管理人员考试题模拟考试题库模拟考试平台操作

3381. Mobile keyboard (Tsinghua University postgraduate entrance examination machine test question)

H. 265 web player easyplayer's method of opening video to the public

Is VR panoramic production a single weapon in the home decoration industry? Why is this?

2022年危险化学品经营单位主要负责人复训题库及答案
随机推荐
Subject 3: Jinan Zhangqiu line 3
Specified interval inversion in the linked list
对NIO的初步理解
科目三: 济南章丘三号线
物联网智能家居项目---智能卧室
Redis database, which can be understood by zero foundation Xiaobai, is easy to learn and use!
[OBS] dynamic bit rate: bit rate estimation
Redis面试题(2022)
Greenplum [deployment 08] database small version upgrade process and problem handling error: open-source-greenplum-db-6 conflicts with
Which securities company has the lowest handling charge? Is it safe to open an account on your mobile phone
2022 retraining question bank and answers for main principals of hazardous chemical business units
An online duplicate of a hidden bug
C语言学习笔记 —— 内存管理
A. Parkway Walk
First pass of routing strategy
C#怎么实现给Word每一页设置不同文字水印
每日一题:奇偶树
Kotlin中lateinit和lazy的原理区别是什么
Sum of binary numbers from root to leaf
暑假加餐|有钱人和你想的不一样(第5天)+电力系统潮流仿真(文档和Matlab代码)