当前位置:网站首页>Ribbon load balancing service call
Ribbon load balancing service call
2022-07-19 08:27:00 【Illusory clarity】
summary
Spring Cloud Ribbon Is based on Netflix Ribbon A set of implementations client Load balancing Tools for .
To put it simply ,Ribbon yes Netflix Published open source projects , The main function is to provide Software load balancing algorithm and service invocation of client .Ribbon The client component provides a complete set of configuration items such as connection timeouts , Retry etc. . To put it simply , This is listed in the configuration file Load Balancer ( abbreviation LB) All the machines in the back ,Ribbon Will automatically help you based on certain rules ( Such as simple polling , Random connection, etc ) To connect the machines . It's easy for us to use Ribbon Implement custom load balancing algorithm .
Ribbon Official website information
Ribbon At present, it also enters maintenance mode , But still in use .
What can I do?
LB( Load balancing )
LB Load balancing (Load Balance) What is it? ?
To put it simply, users' requests are evenly distributed to multiple services , So as to achieve systematic HA ( High availability ). Common load balancing software Nginx, LVS, Hardware F5 etc. .
Ribbon Local load balancing client VS Nginx The difference between server-side load balancing
Nginx It's server load balancing , All client requests are delivered to nginx, Then from nginx Implement forwarding request . That is to say, the load balance is realized by the server .
Ribbon Local load balancing , When calling the microservice interface , The registration information service list will be retrieved from the registry and then cached to JVM Local , So that it can be implemented locally RPC Remote service call technology .
1.1 Centralized LB
I.e. use independent... Between consumers and providers of services LB facilities ( It can be hardware , Such as F5, It can also be software , Such as nginx), The facility is responsible for forwarding access requests through some policy to the service provider :
1.2 In process LB
take LB Logic is integrated into the consumer , The consumer knows from the service registry what addresses are available , Then I choose a suitable server from these addresses .Ribbon It's in the process LB, It's just a class library , Integrated into consumer processes , The consumer uses it to get the address of the service provider .
In a word :
Load balancing +RestTemplate call
summary :Ribbon In fact, it is a soft load balancing client component , It can be used in combination with other clients that require requests , and eureka Combination is just one example .
Two 、Ribbon Load balancing Demo
1. Architecture description 
Ribbon Work in two steps
The first step is to choose EurekaServer , It preferentially selects the one with less load in the same area server.
The second step is according to the policy specified by the user , In from server Select an address from the service registration list .
among Ribbon There are many strategies : Like polling 、 Random and weighted by response time .
3.Ribbon Core components IRule
IRule: Select a service to be accessed from the service list according to a specific algorithm
Ribbon Seven ways of load balancing :
The default is polling algorithm , How to replace ?
1. Create a configuration class .
@Configuration
public class MySelfRule {
@Bean
public IRule myRule(){
return new RandomRule();// Defined as random
}
}
Be careful : This configuration class cannot be in @CompontentScan Under the current package and sub package scanned , Otherwise, the configuration class we defined will be used by all Ribbon Shared by the client , Can not achieve the purpose of special customization .
2. Modify the startup class
@SpringBootApplication
@EnableEurekaClient
@RibbonClient(name = "CLOUD-PAYMENT-SERVICE",configuration = MySelfRule.class)
public class OrderMain80 {
public static void main(String[] args) {
SpringApplication.run(OrderMain80.class,args);
}
}
add @RibbonClient(name = "CLOUD-PAYMENT-SERVICE",configuration = MySelfRule.class) Annotations can be !!
4. Principle of load balancing algorithm

边栏推荐
- 没那么大的组合数
- 网传USDT和USDC要做空?带你一探究竟 | Tokenview
- 真实案例:系统上线后Cpu使用率飙升如何排查?
- Redis message subscription
- Seaport 以及 ERC-4907 能否成为释放NFT流动性的新途径?| Tokenview
- 深度学习之 7 深度前馈网络2
- Redis常用数据类型——哈希(Hash)和有序集合 Zset(sorted set)
- SPARK中的FileSourceStrategy,DataSourceStrategy以及DataSourceV2Strategy
- 在VSCode中设置settings.json
- Stm32f103c8t6 hardware IIC control 4-pin 0.96 inch OLED display
猜你喜欢

全志V3s学习记录(13)OV2640的使用

Redis message subscription

Stm32f103c8t6 hardware IIC control 4-pin 0.96 inch OLED display

Visual studio 2022 (vs 2022) cannot read memory
![leetcode:287. Find the repetition number [fast and slow pointer board]](/img/4c/6278584f528f00776ed75f846edb3a.png)
leetcode:287. Find the repetition number [fast and slow pointer board]

Redis common data types - hash and ordered set Zset (sorted set)

Unity: WebGL发布后在浏览器上运行时窗口大小自适应

最新一代互联网:WEB 3.0

Redis overview installation

凭借左程云(左神)的这份 “程序员代码面试指南”我入职了字节
随机推荐
65. Restful specification
leetcode:287. Find the repetition number [fast and slow pointer board]
New redis6 features
The core problem of concurrent programming
No module named ‘yaml‘ 解决办法
Filesourcestrategy, datasourcestrategy and datasourcev2strategy in spark
leetcode:287. 寻找重复数【快慢指针板子】
深度学习之 7 深度前馈网络
经典通用的Pbootcms花卉网站模板源码,自适应手机端,带后台管理
Interview question: outer margin folding problem (bug of block level elements in ordinary document flow)
Database write Optimization: database and table segmentation and related issues
sudo pip install gevent 安装失败的解决办法
Sword finger offer 42 Maximum sum dynamic programming method for continuous subarrays
visual studio 2022(VS 2022)无法读取内存的问题
Redis6 new data type - hyperloglog
5.1 安全漏洞与防范
通过ip获取归属地
Redis的发布和订阅
深度学习之 7 深度前馈网络2
Redis6 新数据类型——Geospatial