微服务
1.SpringCloud中的核心组件
Spring Cloud Netflix组件
组件名称 | 作用 |
---|---|
Eureka | 服务注册中心 |
Ribbon | Ribbon |
Feign | 声明式服务调⽤ |
Hystrix | 客户端容错保护 |
Zuul | API服务⽹关 |
Spring Cloud Alibaba组件
组件名称 | 作用 |
---|---|
Nacos | 服务注册中心 |
Sentinel | 客户端容错保护 |
Spring Cloud原⽣及其他组件
组件 | 作用 |
---|---|
Consul | 服务注册中心 |
Config | 分布式配置中心 |
Gateway | API服务网关 |
Sleuth/Zipkin | 分布式链路追踪 |
2.服务调用
2.1RestTemplate介绍
Spring框架提供的RestTemplate类可⽤于在应⽤中调⽤rest服务,它简化了与http服务的通信⽅式,统⼀了RESTful的标准,封装了http链接, 我们只需要传⼊url及返回值类型即可。相较于之前常⽤的HttpClient ,RestTemplate是⼀种更优雅的调⽤RESTful服务的⽅式。
2.2RestTemplate方法介绍
2.3通过RestTemplate调用微服务
在 shop_order⼯程中配置RestTemplate
//配置RestTemplate交给spring管理
@Bean
public RestTemplate getRestTemplate() {
return new RestTemplate();
}
3.注册中心
3.1注册中心的主要作用
服务注册中⼼(下称注册中⼼)是微服务架构⾮常重要的⼀个组件,在微服务架构⾥主要起到了协调者的⼀个作⽤。注册中⼼⼀般包含如下⼏个功能:
- 服务发现:
● 服务注册/反注册:保存服务提供者和服务调⽤者的信息