• ribbon学习


    spring cloud 中的负载均衡有ribbon和feign

    引入ribbon依赖

            <!--ribbon相关-->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-eureka</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-ribbon</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-config</artifactId>
            </dependency>

    在客户端加入loadblance

         @Bean
        @LoadBalanced  //ribbon负载均衡,
        public RestTemplate getRestaTemplate(){
            return new RestTemplate();
        }

    ribbon的负载均衡算法有七种,默认轮询,要更换:

       @Bean
        @LoadBalanced  //ribbon负载均衡,
        public RestTemplate getRestaTemplate(){
            return new RestTemplate();
        }
    
    
        //更换算法
    @Bean
    public IRule defRule(){ return new RandomRule(); }

    自定义Rule,不能建在与主类及子包下面:

    @SpringBootApplication
    @EnableEurekaClient
    @RibbonClient(name = "MICROSERVICECLOUD",configuration = "自定义的rule")
    public class Consumer80 {
        public static void main(String[] args) {
            SpringApplication.run(Consumer80.class,args);
        }
    }
    ...
  • 相关阅读:
    scrapy相关信息
    BeautifulSoup常见使用
    requests常用模块以及爬取github个人项目
    django rest framework 与前端跨域问题解决
    nginx配置正向代理与反向代理
    django+nginx+uwsgi+https
    linux基本命令
    python基本算法
    centos7配置ftp服务器
    nginx1.12配置
  • 原文地址:https://www.cnblogs.com/javage/p/9492705.html
Copyright © 2020-2023  润新知