微服务-springcloud
感觉微服务都差不多概念,最近稍微看了下springcloud,感觉入门还是很简单的,框架用用就那么回事,深入的话需要很多时间投入了
学一个东西,我推荐首先从概念上了解到他是做什么的,什么时候需要,基本模块是什么,然后可以自己写一些小的例子,后续根据需要深入到探寻源码
某位热心同学写的入门例子,我下载学习了下:http://git.oschina.net/zhou666/spring-cloud-7simple
集成了了Netfix的一些关键组件:
服务发现——Netflix Eureka
客服端负载均衡——Netflix Ribbon
断路器——Netflix Hystrix
服务网关——Netflix Zuul
分布式配置——Spring Cloud Config
Eureka服务发现,启动后可以在控制台看到其他配置了该eureka地址的服务
application.properties中定义eureka服务相关信息
server.port=1111
eureka.instance.hostname=localhost
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false
eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/
spring.application.name=cloud-eureka-server
manager url:http://localhost:1111/
spring-boot 注解方式启动服务
@SpringBootApplication
@EnableEurekaServer
public class EurekaServer {
public static void main(String[] args) {
SpringApplication.run(EurekaServer.class, args);
}
}
打开控制台可以看到eureka服务已经启动成功

启动两个server2222/2223,在配置中制定eureka的服务地址
spring.application.name=ribbon-consumer
server.port=2222
eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/
@EnableDiscoveryClient
@SpringBootApplication
public class ComputeServiceApplication {
public static void main(String[] args) {
new SpringApplicationBuilder(ComputeServiceApplication.class).web(true).run(args);
}
}
启动后可以看到eureka控制台有这两个服务出现

修改端口为3333
启动ribbon轮询负载均衡器:
@SpringBootApplication
@EnableDiscoveryClient
public class RibbonApplication {
@Bean
@LoadBalanced
RestTemplate restTemplate() {
return new RestTemplate();
}
public static void main(String[] args) {
SpringApplication.run(RibbonApplication.class, args);
}
}
可以看到eureka可以发现该服务,并且访问http://localhost:3333/add?a=1&b=2时,后台分别传递给了2222和2223实现了负载均衡调度
Hystrix熔断机制:
application.yml
server:
port: 8989 spring:
application:
name: turbine
cloud:
config:
enabled: true
uri: http://localhost:8888
eureka:
instance:
leaseRenewalIntervalInSeconds: 10
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://localhost:1111/eureka/ turbine:
aggregator:
clusterConfig: CLOUD-SIMPLE-UI
appConfig: cloud-simple-ui
clusterNameExpression: metadata['cluster']
@SpringBootApplication
@EnableEurekaClient
@EnableHystrixDashboard
@EnableTurbine
public class TurbineApplication { public static void main(String[] args) {
SpringApplication.run(TurbineApplication.class, args);
}
}
Config配置管理:
server.port=8888
spring.cloud.config.server.git.uri=https://git.oschina.net/zhou666/spring-cloud-7simple.git
spring.cloud.config.server.git.searchPaths=cloud-config-repo
eureka.client.serviceUrl.defaultZone=http\://localhost\:1111/eureka/
spring.application.name=cloud-config-server
@Configuration
@EnableAutoConfiguration
@EnableDiscoveryClient
@EnableConfigServer
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
zuul服务网关,类似Nginx反向代理服务器,配置各种Ip过来给哪个下级处理
logging:
level.org.springframework.cloud: DEBUG
server:
port: 8080
zuul:
ignoredPatterns: /health,/error
retryable: true
routes:
smarts:
stripPrefix: true
path: /smart/**
serviceId: smarts
ribbon:
eureka:
enabled: false
smarts:
ribbon:
listOfServers: localhost:2222,localhost:2223
定义映射规则,当访问http://localhost:8080/smart/add?a=1&b=2会按照规则/smart/**将请求定位到2222/2223
@EnableZuulProxy
@SpringBootApplication
public class ZuulApplication {
public static void main(String[] args) {
SpringApplication.run(ZuulApplication.class, args);
}
}
微服务-springcloud的更多相关文章
- 微服务SpringCloud之配置中心和消息总线
在微服务SpringCloud之Spring Cloud Config配置中心SVN博客中每个client刷新配置信息时需要post请求/actuator/refresh,但客户端越来越多时,,需要每 ...
- Java生鲜电商平台-深入理解微服务SpringCloud各个组件的关联与架构
Java生鲜电商平台-深入理解微服务SpringCloud各个组件的关联与架构 概述 毫无疑问,Spring Cloud是目前微服务架构领域的翘楚,无数的书籍博客都在讲解这个技术.不过大多数讲解还停留 ...
- 小D课堂 - 新版本微服务springcloud+Docker教程_汇总
小D课堂 - 新版本微服务springcloud+Docker教程_1_01课程简介 小D课堂 - 新版本微服务springcloud+Docker教程_1_02技术选型 小D课堂 - 新版本微服务s ...
- 「 从0到1学习微服务SpringCloud 」10 服务网关Zuul
系列文章(更新ing): 「 从0到1学习微服务SpringCloud 」06 统一配置中心Spring Cloud Config 「 从0到1学习微服务SpringCloud 」07 RabbitM ...
- 「 从0到1学习微服务SpringCloud 」09 补充篇-maven父子模块项目
系列文章(更新ing): 「 从0到1学习微服务SpringCloud 」06 统一配置中心Spring Cloud Config 「 从0到1学习微服务SpringCloud 」07 RabbitM ...
- 「 从0到1学习微服务SpringCloud 」08 构建消息驱动微服务的框架 Spring Cloud Stream
系列文章(更新ing): 「 从0到1学习微服务SpringCloud 」01 一起来学呀! 「 从0到1学习微服务SpringCloud 」02 Eureka服务注册与发现 「 从0到1学习微服务S ...
- 「 从0到1学习微服务SpringCloud 」07 RabbitMq的基本使用
系列文章(更新ing): 「 从0到1学习微服务SpringCloud 」01 一起来学呀! 「 从0到1学习微服务SpringCloud 」02 Eureka服务注册与发现 「 从0到1学习微服务S ...
- 「 从0到1学习微服务SpringCloud 」06 统一配置中心Spring Cloud Config
系列文章(更新ing): 「 从0到1学习微服务SpringCloud 」01 一起来学呀! 「 从0到1学习微服务SpringCloud 」02 Eureka服务注册与发现 「 从0到1学习微服务S ...
- 「 从0到1学习微服务SpringCloud 」05服务消费者Fegin
系列文章(更新ing): 「 从0到1学习微服务SpringCloud 」01 一起来学呀! 「 从0到1学习微服务SpringCloud 」02 Eureka服务注册与发现 「 从0到1学习微服务S ...
- 「 从0到1学习微服务SpringCloud 」04服务消费者Ribbon+RestTemplate
系列文章(更新ing): 「 从0到1学习微服务SpringCloud 」01 一起来学呀! 「 从0到1学习微服务SpringCloud 」02 Eureka服务注册与发现 「 从0到1学习微服务S ...
随机推荐
- 关于oracle的sqlplus显示不完全的修改方法
这样的显示看起来很痛苦 需要换行的时候没有进行换行,不需要换行的时候却进行了换行 参考的博客地址 https://blog.csdn.net/pan_tian/article/details/8059 ...
- 事件之父View和子view的点击事件的执行过程
Android中的事件类型分为按键事件和屏幕触摸事件,Touch事件是屏幕触摸事件的基础事件,有必要对它进行深入的了解. 一个最简单的屏幕触摸动作触发了一系列Touch事件:ACTION_DOWN-& ...
- [UE4]控制流
虽然官方文档说复杂的蓝图循环是会跨域多帧运行,但实际上测试下来,如果在循环体进行大量复杂的运算,不足以在一帧内完成时,游戏就会在当前帧卡住,直到循环结束为止. 一.Switch Switch可以在所有 ...
- maven的web项目和shiro集成的问题
在自定义shiro然后在加入spring的配置文件时,启动tomcat的时候一直报错 原因:刚学,对maven的依赖构建属性不熟悉 只是完成了maven父项目和子项目的依赖关系,并没有配置子项目之间的 ...
- AWS之SSH登录:使用 PuTTY 从 Windows 连接到 Linux 实例
使用 PuTTY 从 Windows 连接到 Linux 实例 启动您的实例之后,您可以连接到该实例,然后像使用您面前的计算机一样来使用它. 注意 启动实例后,需要几分钟准备好实例,以便您能连接到实例 ...
- unity3d动态创建一个文本
2D文本需要Canvas和EventSystem,最好使用Editor来添加: 动态显示一个文本,采用3D Text的方式: GameObject text = new GameObject(); t ...
- 卷积神经网络之GoogleNet:inceptionV3模型学习
Rethinking the Inception Architecture for Computer Vision 论文地址:https://arxiv.org/abs/1512.00567 Abst ...
- 让WordPress支持google AMP
1.关于AMP 在移动互联网的时代,尽管网站响应式设计可以满足多屏(pc.手机.ipad等)浏览,但google在2015年10月推出了更快移动页面访问速度的技术-Accelerated Mobile ...
- python学习笔记-学习大纲
- MySql存储过程与函数详解
存储过程和函数是在数据库中定义一些SQL语句的集合,然后直接调用这些存储过程和函数来执行已经定义好的SQL语句.存储过程和函数可以避免开发人员重复的编写相同的SQL语句.而且,存储过程和函数是在MyS ...