黑马十次方项目day07-06之eureka的负载均衡

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_33229669/article/details/87522065

一 . eureka负载均衡的准备工作

测试:同时开启多个基础微服务,看是否是轮流调用。如果是轮流的调用,那么代表eureka是有负载均衡的效果的,即依次调用各个微服务.
首先在BaseApplication项目,勾选上右边的框框,代表允许不同端口的并行运行

在tensquare_base的yml中,配置9001的端口下, 其LabelController的findById写一个输出语句,输出11111. 然后启动tensquare_base项目(前提是tensquare_eureka项目已经启动).

/**
     * 方法名: findById
     * 方法描述: 根据id查询标签
     * 修改日期: 2019/1/6 15:20
      * @param labelId
     * @return entity.Result
     * @author taohongchao
     * @throws
     */
    @RequestMapping(value = "/{labelId}",method = RequestMethod.GET)
    public Result findById(@PathVariable("labelId") String labelId) {
        System.out.println("333333");
        return new Result(true, StatusCode.OK, "查询成功!",labelService.findById(labelId));
    }

接着修改tensquare_base的yml中,配置9201,端口, 在Controller方法中,写入输出语句为22222.再次启动该项目.
接着修改tensquare_base的yml中,配置9301,端口, 在Controller方法中,写入输出语句为33333.再次启动该项目.
至此, tensquare_base项目启动了三个微服务
在eureka中显示如下

接着启动tensquare_qa项目. 进行服务的调用

二.负载均衡的实验

调用tensquare_qa项目, 使用9003的端口.
依次发送三个如下的get请求
http://localhost:9003/problem/label/1
可以在后台中,看到,打印了11111,2222,3333 说明这三次的调用,是分别进行调用的,进行了负载均衡.
在实际的调用中,可能不是按照123的顺序,但是一定是分别调用的.


猜你喜欢

转载自blog.csdn.net/qq_33229669/article/details/87522065