什么是Ribbon?
Spring Cloud Ribbon是一个基于HTTP和TCP的客户端负载均衡工具,它基于Netflix Ribbon实现。通过Spring Cloud的封装,可以让我们轻松地将面向服务的REST模版请求自动转换成客户端负载均衡的服务调用。Spring Cloud Ribbon虽然只是一个工具类框架,它不像服务注册中心、配置中心、API网关那样需要独立部署,但是它几乎存在于每一个Spring Cloud构建的微服务和基础设施中。因为微服务间的调用,API网关的请求转发等内容,实际上都是通过Ribbon来实现的,包括后续我们将要介绍的Feign,它也是基于Ribbon实现的工具。所以,对Spring Cloud Ribbon的理解和使用,对于我们使用Spring Cloud来构建微服务非常重要。
Resttemplete的使用
1.简单介绍下get和post的请求
常用的方法:
getForEntity getForObject postForEntity postForObject
RestTemplate restTemplate =new RestTemplate();
Login login =new Login();
login.setPhoneNumer("13459009876");
login.setVarCode("admin");
Token token =restTemplate.postForObject("http://localhost:8081/api/login/getToken",login,Token.class);
其他的方法类似 只是返回方法不一样
网友评论