zoukankan      html  css  js  c++  java
  • SpringCloud- 负载均衡(ribbon)

    1.nginx实现负载均衡原理:

     能实现负载均衡的工具有nginx lvs F5(硬件)

    2.SpringCloud实现负载均衡原理

    3.搭建ribbon实现负载均衡demo(如果没项目可以从eureka demo那里获取)

     步骤一:pom文件导入所需要的依赖

    <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-ribbon</artifactId>
    </dependency>

    步骤二:加上开启负载均衡的注解

    package com;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.cloud.client.loadbalancer.LoadBalanced;
    import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
    import org.springframework.context.annotation.Bean;
    import org.springframework.web.client.RestTemplate;
    
    @SpringBootApplication
    @EnableEurekaServer
    public class OrderApp {
    
        public static void main(String[] args) {
            SpringApplication.run(OrderApp.class, args);
        }
    
        @Bean
        @LoadBalanced//这个注解的作用就是允许Rest调用开启负载均衡
        RestTemplate restTemplate() {
            return new RestTemplate();
        }
    }

    步骤三:测试负载均衡生效

    从截图中可以看出来,此时的eureka中心有两个 service-member 服务

    请求地址:http://127.0.0.1:8764/getOrderByUserList

    结果显示:

    ps:负载均衡的配置应该是在消费接口这边,因为是消费接口调用接口提供者!

  • 相关阅读:
    菜根谭#250
    菜根谭#249
    菜根谭#248
    [转载]将网卡(设备中断)绑定到特定CPU
    request_mem_region,ioremap 和phys_to_virt()
    [转载]python的range()函数用法
    [转载]Python print函数用法,print 格式化输出
    [转载]python datetime处理时间
    Linux驱动
    Linux驱动
  • 原文地址:https://www.cnblogs.com/920913cheng/p/10844761.html
Copyright © 2011-2022 走看看