Skip to content

Commit

Permalink
test: 图片显示
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-qtp committed Dec 31, 2024
1 parent 1bddd60 commit ee8cceb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<p/>
<h1>『Qtp-稳重不爱吃肉』</h1>
</div>
:rocket: 无限进步,影视飓风的座右铭!
:rocket: 无限进步,影视飓风的座右铭!
:rocket: 做技术的应该多写点技术文章,输出的同时倒逼输入!

:fire: :fire: :fire: 推荐 | 在线阅读:<https://tim-qtp.github.io/blog/>
Expand Down
22 changes: 18 additions & 4 deletions src/framework/springcloud/Microservices with Eureka Ribbon.md
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,18 @@ eureka:
> spring会自动帮助我们从eureka-server端,根据userservice这个服务名称,获取实例列表,而后完成负载均衡.
>
> 注意如果不加 @LoadBalanced ,将无法通过服务名请求访问
>
> 注意:是在这加:
>
> ```java
> /**
> * 创建RestTemplate并注入Spring容器
> */
> @Bean
> public RestTemplate restTemplate(){
> return new RestTemplate();
> }
> ```

切换两个实例查看,发现确实实现了负载均衡**(这个课太棒了!)**

Expand Down Expand Up @@ -431,6 +443,8 @@ eureka:
- 给RestTemplate添加@LoadBalanced注解
- 用服务提供者的服务名称远程调用



## 四、Ribbon负载均衡

上一节中,我们添加了@LoadBalanced注解,即可实现负载均衡功能,这是什么原理呢?
Expand Down Expand Up @@ -465,7 +479,7 @@ SpringCloud底层其实是利用了一个名为Ribbon的组件,来实现负载

这里的`this.loadBalancer`是`LoadBalancerClient`类型,我们继续跟入。



**2)LoadBalancerClient**

Expand Down Expand Up @@ -498,7 +512,7 @@ SpringCloud底层其实是利用了一个名为Ribbon的组件,来实现负载

![](https://qtp-1324720525.cos.ap-shanghai.myqcloud.com/blog/a6675c34e11a186cbc0a57bda461c364.png)

继续跟踪源码chooseServer方法,发现这么一段代码:
继续跟踪源码chooseServer方法,发现这么一段代码:

![](https://qtp-1324720525.cos.ap-shanghai.myqcloud.com/blog/b696a05f4f6a57719ea0b88c29046f89.png)

Expand Down Expand Up @@ -576,7 +590,7 @@ public IRule randomRule(){
}
```


上面这个是全局的,在`order-service`里,不管你调用的是`user-service`,还是以后商品服务也好,它都是随机的。

2. 配置文件方式:在order-service的application.yml文件中,添加新的配置也可以修改规则:

Expand Down Expand Up @@ -667,7 +681,7 @@ Nacos是SpringCloudAlibaba的组件,而SpringCloudAlibaba也遵循SpringCloud
- 依赖不同
- 服务地址不同


![image-20241231121817181](https://qtp-1324720525.cos.ap-shanghai.myqcloud.com/blog/image-20241231121817181.png)

##### 1)引入依赖

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ category:

## Redis安装

- 下载Redis`7`的docker镜像:
- 下载Redis`7`的docker镜像:

```sh
docker pull redis:7
Expand Down

0 comments on commit ee8cceb

Please sign in to comment.