微服务-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 ...
随机推荐
- 06-ICMP: Internet 控制报文协议
I C M P经常被认为是I P层的一个组成部分.它传递差错报文以及其他需要注意的信息. I C M P报文通常被I P层或更高层协议( T C P或U D P)使用.一些I C M P报文把差错报文 ...
- mysql 8.0 错误The server requested authentication method unknown to the client
mysql 安装了最新版本8.0.11后创建用户并授权后,授权的用户连接数据库提示 The server requested authentication method unknown to the ...
- 在VMware安装Centos7
1.新建虚拟机==>典型==>稍后安装操作系统==>选择linux==>centos 64位 2.填写虚拟机名字以及安装位置. 3.磁盘容量采用默认即可. 4. 自定义硬件: ...
- HBase配置性能调优
因官方Book Performance Tuning部分章节没有按配置项进行索引,不能达到快速查阅的效果.所以我以配置项驱动,重新整理了原文,并补充一些自己的理解,如有错误,欢迎指正. 配置优化 zo ...
- Install Greenplum OSS on Ubuntu
About Greenplum Database Greenplum Database is an MPP SQL Database based on PostgreSQL. Its used in ...
- (转)深入sql server中的事务
原文地址:http://www.cnblogs.com/chnking/archive/2007/05/27/761209.html 参考文章:http://www.cnblogs.com/zhuif ...
- 06 I/O重定向与管道符
首先,我们知道我们的计算机结构,在第一节的时候已经介绍过了,CPU进行数据运算,同时控制器负责指令的发送,而内存则是数据存储的地方,CPU读取的数据均从内存中调取.电脑除了CPU和内存外,我们还有I/ ...
- python随机数random
1.random.random()方法用于生成一个0到1的随机浮点数:0<=n<1.0 2.random.uniform(a,b):用于生成一个指定范围内的随机浮点数,两格参数中,其中一个 ...
- Java可视操作界面例子
package rom; import java.lang.*; import java.awt.*; import java.awt.event.ActionEvent; import java.a ...
- spring mvc 异常处理
一般实现业务的时候避免不了会抛一些自定义异常 抛给controller进行最终处理.如果业务上比较复杂.频繁的在try catch操作. 时间一长,代码维护性,可读性自然而然就上来了. 然后,spri ...