微服务-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 ...
随机推荐
- HDOJ 2008 数值统计
#include<iostream> using namespace std; int main() { int n; ) { , y = , z = ; double t; ;i < ...
- Volley 结合GSON或FastJson用法
自定义GSON类 public class GsonRequest<T> extends Request<T> { private final Gson mGson = new ...
- github_源码
固定头部: hongyangAndroid/Android-StickyNavLayout:ListView 与ViewPager 滑动冲突处理,滑动到顶部固定位置停顿; ufo22940268/ ...
- [UE4]单机游戏改网络游戏,不完全清单
把Actor的复制打开 中腰数据的复制打开,且只在服务器修改(比如角色属性血量) 需要同步的Actor,不在客户端Spawn 客户端的操作,先报告到服务器,服务器再广播到所有客户端 某些逻辑只在服务器 ...
- MongoDb进阶实践之一 如何在Linux系统上安装和配置MongoDB
转载来源:https://www.cnblogs.com/PatrickLiu/p/8630151.html 一.NoSQL数据简介 1.NoSQL概念 NoSQL(NoSQL = Not Only ...
- ORACLE 通过连接查询更新 update select
注意: 关键的地方是where 语句的加入. 在11G中, 如果不加11G , 或造成除匹配的行数更新为相应的值之后, 其余的会变成负数. 所以,执行前需要测试, 普通办法就是: 先查看需要更新的 ...
- CentOS7 设置集群时间同步
1. 安装ntp时间同步工具 yum -y install ntp ntpdate #安装ntpdate时间同步工具 ntpdate cn.pool.ntp.org #设置时间同步 hwclock - ...
- ZooKeeper系列(8):ZooKeeper伸缩性
一.ZooKeeper中Observer 1.1 ZooKeeper角色 经过前面的介绍,我想大家都已经知道了在ZooKeeper集群当中有两种角色Leader和Follower.Leader可以接受 ...
- 关于jdango框架静态文件配置的问题
一: 我们首先要知道什么是静态文件: 静态文件就是我们的HTML,css,图片等文件. 二: 我们要知道我们的Django框架是一个web服务器,那么web服务器,我们是通过一个url地址来访问它的, ...
- JS中 == ,===, !=, !==的区别
一个等号是赋值操作,==先转换类型再比较,===先判断类型,如果不是同一类型直接为false. === 判断规则 如果类型不同,就[不相等] 如果两个都是数值,并且是同一个值,那么[相等]:(!例外 ...