本文主要是预研Spring Cloud Alibaba技术。主要有Nacos、Disconvery、Config、Sentiel。
参考资料 SpringCloud官网Nacos中文文档SpringCloudGateway 技术框架 SpringBoot-2.1.5.RELEASESpringCloud-Greenwich.SR3SpringCloudAlibaba-2.1.0SpringCloudGateway-2.1.3 源码地址:https://github.com/CNXMBuyu/springclouddemo/tree/alibabaNacos是阿里巴巴开源的一个更易于构建云原生应用的动态服务发现、配置管理和服务管理平台。Nacos是单独的一个应用程序。
点击查看使用手册
默认用户名/密码:nacos/nacos
复制cluster.conf.example,改为cluster.conf。集群配置如下:
#it is ip 172.16.85.223:8846 172.16.85.223:8847 172.16.85.223:8848sh startup.sh -p embedded
如果不加属性-p embedded,则默认使用mysql作为持久化数据库
默认集成了Ribbon,可以使用RestTemplate和FeignClient
Discovery遵循了spring cloud common标准,实现了AutoServiceRegistration、ServiceRegistry、Registration 这三个接口。
在spring cloud应用的启动阶段,监听了WebServerInitializedEvent事件,当Web容器初始化完成后,即收到WebServerInitializedEvent事件后,会触发注册的动作,调用ServiceRegistry的register方法,将服务注册到Nacos Server。
NacosServerList实现了com.netflix.loadbalancer.ServerList接口,并在@ConditionOnMissingBean的条件下进行自动注入,默认集成了Ribbon。
如果需要有更加自定义的可以使用 @Autowired注入一个NacosRegistration实例,通过其持有的NamingService字段内容直接调用 Nacos API。
http://localhost:8001/actuator/nacos-discovery
SpingCloudAlibaba的config没有服务端,直接在nacos的配置管理中添加配置即可。
官方帮助手册官方示例Nacos中配置管理使用说明Nacos Config主要通过dataId和group来唯一确定一条配置,我们假定你已经了解此背景。
Nacos Client从Nacos Server端获取数据时,调用的是此接口ConfigService.getConfig(String dataId, String group, long timeoutMs)。
Nacos Config Starter实现了org.springframework.cloud.bootstrap.config.PropertySourceLocator接口,并将优先级设置成了最高。
在Spring Cloud应用启动阶段,会主动从Nacos Server端获取对应的数据,并将获取到的数据转换成PropertySource且注入到Environment的PropertySources 属性中,所以使用 @Value 注解也能直接获取Nacos Server端配置的内容。
Nacos Config Starter默认为所有获取数据成功的Nacos的配置项添加了监听功能,在监听到服务端配置发生变化时会实时触发org.springframework.cloud.context.refresh.ContextRefresher的refresh方法 。
如果需要对Bean进行动态刷新,请参照Spring和Spring Cloud规范。推荐给类添加@RefreshScope或@ConfigurationProperties 注解,更多详情请参考 ContextRefresher Java Doc。
http://127.0.0.1:8001/actuator/nacos-config
Gateway并不属于SpringCloudAlibaba的一个组件。
https://github.com/spring-cloud/spring-cloud-gateway/blob/v2.1.3.RELEASE/spring-cloud-gateway-sample/pom.xml
Sentinel是阿里巴巴开源的分布式系统的流量防卫组件,Sentinel把流量作为切入点,从流量控制,熔断降级,系统负载保护等多个维度保护服务的稳定性。
example:https://github.com/alibaba/spring-cloud-alibaba/tree/v2.1.0.RELEASE/spring-cloud-alibaba-examples/sentinel-example
略过
产品介绍
阿里云EDAS的组件,提供商业版的服务注册功能。EDAS介绍
阿里云的应用配置管理。ACM介绍
阿里云的对象存储。OSS介绍
阿里云EDAS的组件,提供符合Spring Cloud规范的分布式作业调度。EDAS介绍
阿里云短信服务
