当前位置:网站首页>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

边栏推荐
- Redis transaction
- How to use curl in Jenkins pipeline and process response results
- Spark miscellaneous -- why reuse exchange and subquery
- 在VSCode中设置settings.json
- Redis的发布和订阅
- 聊聊分布式锁
- Redis6 新数据类型——Geospatial
- Excellent résumé! Enfin quelqu'un a compris toutes les connexions SQL
- Redis介绍
- Enjoy JVM -- knowledge about GC garbage collection
猜你喜欢
随机推荐
SPARK闲杂--为什么复用Exchange和subquery
Application of SCA on devsecops platform
Redis介绍
超干货!彻底搞懂Golang内存管理和垃圾回收
美国压力激增,TikTok 更换全球安全主管
全志V3s学习记录(13)OV2640的使用
US pressure surges, tiktok changes global safety director
Eureka自我保护
Detailed explanation of ansible automatic operation and maintenance (IV) preparation, use, command execution and example demonstration of playbook in ansible
Openfeign service interface call
5.1 vulnérabilités et précautions en matière de sécurité
Viewing the technology stack of distributed system from the crash report of station B
sudo pip install gevent 安装失败的解决办法
Redis master-slave replication
Redis6新数据类型——HyperLogLog
Will it be a little late to realize your "wonderful" 360?
A small program about daily habit clock in
5.2 database security
Redis common data types - hash and ordered set Zset (sorted set)
Redis6 new data type geospatial








