spring cloud Ribbon
参考:https://www.jianshu.com/p/1bd66db5dc46
Ribbon 是什么
spring cloud ribbon 是一个基于HTTP 和 TCP 的客户端负载均衡工具,它基于 NetFlix Ribbon 实现。通过spring cloud 封装,可以将面向
服务的REST 模板请求自动转换为客户端负载均衡的服务调用。
RestTenolate 实现访问
方式一:将url写死
RestTemplate restTemplate = new RestTemplate();
String response =restTemplate.getForObject("http://localhost:8090/msg",String.class);
方式二:动态获取host + port
@Autowired
private LoadBalancerClient loadBalancerClient;
RestTemplate restTemplate = new RestTemplate();
ServiceInstance serviceInstance = loadBalancerClient.choose("product");
String url = String.format("http://%s:%s",serviceInstance.getHost(),serviceInstance.getPort())+"/msg";
String response = restTemplate.getForObject(url,String.class);
方式三:
写一个配置类
@Component
public class RestTemplateConfig { @Bean
@LoadBalanced
public RestTemplate restTemplate(){
return new RestTemplate();
}
}
@Autowired
private RestTemplate restTemplate;
String response = restTemplate.getForObject("http://product/msg",String.class);
spring cloud Ribbon的更多相关文章
- 撸一撸Spring Cloud Ribbon的原理-负载均衡器
在上一篇<撸一撸Spring Cloud Ribbon的原理>中整理发现,RestTemplate内部调用负载均衡拦截器,拦截器内最终是调用了负载均衡器来选择服务实例. 接下来撸一撸负载均 ...
- 笔记:Spring Cloud Ribbon 客户端配置详解
自动化配置 由于 Ribbon 中定义的每一个接口都有多种不同的策略实现,同时这些接口之间又有一定的依赖关系,Spring Cloud Ribbon 中的自动化配置能够很方便的自动化构建接口的具体实现 ...
- 笔记:Spring Cloud Ribbon 客户端负载均衡
Spring Cloud Ribbon 是一个基于 HTTP 和 TCP 的客户端负载均衡工具,基于 Netflix Ribbon 实现,通过Spring Cloud 的封装,可以让我们轻松的将面向服 ...
- 为Spring Cloud Ribbon配置请求重试(Camden.SR2+)
当我们使用Spring Cloud Ribbon实现客户端负载均衡的时候,通常都会利用@LoadBalanced来让RestTemplate具备客户端负载功能,从而实现面向服务名的接口访问. 下面的例 ...
- Spring Cloud微服务笔记(四)客户端负载均衡:Spring Cloud Ribbon
客户端负载均衡:Spring Cloud Ribbon 一.负载均衡概念 负载均衡在系统架构中是一个非常重要,并且是不得不去实施的内容.因为负载均衡对系统的高可用性. 网络压力的缓解和处理能力的扩容的 ...
- 基于Spring cloud Ribbon和Eureka实现客户端负载均衡
前言 本案例将基于Spring cloud Ribbon和Eureka实现客户端负载均衡,其中Ribbon用于实现客户端负载均衡,Eureka主要是用于服务注册及发现: 传统的服务端负载均衡 常见的服 ...
- 撸一撸Spring Cloud Ribbon的原理-负载均衡策略
在前两篇<撸一撸Spring Cloud Ribbon的原理>,<撸一撸Spring Cloud Ribbon的原理-负载均衡器>中,整理了Ribbon如何通过负载均衡拦截器植 ...
- 第四章 客户端负载均衡:Spring Cloud Ribbon
spring cloud ribbon 是一个基于 HTTP 和 TCP 的客户端负载均衡工具,它基于Netflix Ribbon 实现.通过Spring Cloud 的封装,可以轻松的将面向服务的R ...
- Spring Cloud Ribbon入门
一.简介 Spring Cloud Ribbon是一个基于Http和TCP的客户端负载均衡工具,它是基于Netflix Ribbon实现的.它不像服务注册中心.配置中心.API网关那样独立部署,但是它 ...
随机推荐
- ES - dynamic field mapping
Dynamic field mapping 1.我们向es提交一个json对象进行索引,es会对json字段和索引字段进行字段类型适配. 规则如下: 2.string字段的转换规则 当date det ...
- 自定义页面微信、微博、QQ分享效果
几行简单的分享代码既可以实现,先看下效果: 第一步:页面因为结构代码 <div id="freebtn"> <ul> <li class=" ...
- scrapyd和scrapyd-client使用教程
原文地址:http://blog.wiseturtles.com/posts/scrapyd.html Tags scrapyd scrapy scrapyd-client By crazygit O ...
- 去中心化存储项目终极指南 | Filecoin, Storj 和 PPIO 项目异同
Filecoin,Storj 以及 PPIO 这三个存储公链的设计思路是不一样的,没有优劣之分,写这篇文章也并不是为了争论各项目的好坏对错.去中心化存储是一个长期商业赛道,不同团队在同一个赛道上往不同 ...
- python3 模拟鼠标和键盘操作
1. 安装pyperclip pip install pyperclip 使用方法复制 pyperclip.copy("hello world") 粘贴 pyperclip.pas ...
- 微信小程序tab栏切换
Wxml代码:<view class="body"> <view class="nav bc_white"> <view clas ...
- JS面试Q&A(续2): Rest parameter,Arrow function 等
rest parameter 和 Destructuring assignment. function fun1(...theArgs) { console.log(theArgs.length);} ...
- 逆向工程vgenerator(一)
前言 想要自己实现一个mybatis-generator类似的轮子,目前只实现MySQL部分的方法.利用下班时间,写了一个小项目,实现了这个功能.我准备分成三篇博客来写这个东西. 基类 /** *基类 ...
- Linux基础(学习过程记录)
常用快捷键:Tab:使用Tab键来进行命令补全,补全目录.补全命令参数Ctrl+c键来强行终止当前程序Ctrl+d 键盘输入结束或退出终端Ctrl+s 暂停当前程序,暂停后按下任意键恢复运行Ctrl+ ...
- 再论 ORM
Object-Relationl Mapping,它的作用是在关系型数据库和对象之间作一个映射. ORM 对象关系映射,这样说还是懵. 这里比较难理解的是 关系 —— 即Relationl ,虽然看起 ...