Ribbon负载均衡

简介

在这里插入图片描述

LB负载均衡

在这里插入图片描述

集中LB(负载均衡)

在这里插入图片描述

进程LB(负载均衡)

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

RestTemplate (远程)调用

在这里插入图片描述
在这里插入图片描述

Ribbon 的核心组件 IRule

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

Ribbon 负载均衡的算法如何替换

在这里插入图片描述
注意:不要将这个自定义的配置类放在主启动类的包下以及主启动类的包的子包下

  1. 新建 package 包名为 com.atguigu.myrule
  2. 在 com.atguigu.myrule 包下新建 MySelfRule 类
package com.atguigu.myrule;

import com.netflix.client.IResponse;
import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MySelfRule {
    @Bean
    public IRule myRule() {
        return new RandomRule();   // 定义为随机
    }
}
  1. 主启动类添加 @RibbonClient 注解
package com.atguigu.springcloud;

import com.atguigu.myrule.MySelfRule;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.ribbon.RibbonClient;

@SpringBootApplication
@EnableEurekaClient
// 需要访问的服务的名称 CLOUD-PAYMENT-SERVICE
@RibbonClient(name = "CLOUD-PAYMENT-SERVICE", configuration = MySelfRule.class)
public class OrderMain80 {
    public static void main(String[] args) {
        SpringApplication.run(OrderMain80.class, args);
    }
}

Ribbon 负载均衡算法

Ribbon 轮询算法原理

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值