├── microservice-hystrix-dashboard ├── src │ └── main │ │ ├── resources │ │ └── application.yml │ │ └── java │ │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ └── hystrixdashboard │ │ └── HystrixDashboardApplication.java └── pom.xml ├── microservice-provider-user ├── src │ └── main │ │ ├── resources │ │ ├── schema.sql │ │ ├── data.sql │ │ └── application.yml │ │ └── java │ │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ ├── repository │ │ └── UserRepository.java │ │ ├── UserApplication.java │ │ ├── domain │ │ └── User.java │ │ └── controller │ │ └── UserController.java └── pom.xml ├── microservice-api-gateway ├── src │ └── main │ │ ├── docker │ │ └── Dockerfile │ │ ├── java │ │ └── com │ │ │ └── itmuch │ │ │ └── cloud │ │ │ └── study │ │ │ └── ZuulApiGatewayApplication.java │ │ └── resources │ │ └── application.yml └── pom.xml ├── .gitignore ├── microservice-discovery-eureka ├── src │ └── main │ │ ├── docker │ │ └── Dockerfile │ │ ├── resources │ │ └── application.yml │ │ └── java │ │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ └── EurekaApplication.java └── pom.xml ├── microservice-consumer-movie-ribbon-with-hystrix ├── src │ └── main │ │ ├── resources │ │ └── application.yml │ │ └── java │ │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ ├── user │ │ ├── entity │ │ │ └── User.java │ │ ├── controller │ │ │ └── RibbonHystrixController.java │ │ └── service │ │ │ └── RibbonHystrixService.java │ │ └── MovieRibbonHystrixApplication.java └── pom.xml ├── microservice-hystrix-turbine ├── src │ └── main │ │ ├── java │ │ └── com │ │ │ └── itmuch │ │ │ └── cloud │ │ │ └── study │ │ │ └── turbine │ │ │ └── TurbineApplication.java │ │ └── resources │ │ └── application.yml └── pom.xml ├── docker-compose.yml ├── README.md └── pom.xml /microservice-hystrix-dashboard/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: hystrix-dashboard 4 | server: 5 | port: 8030 6 | -------------------------------------------------------------------------------- /microservice-provider-user/src/main/resources/schema.sql: -------------------------------------------------------------------------------- 1 | drop table user if exists; 2 | create table user (id bigint generated by default as identity, username varchar(255), age int, primary key (id)); -------------------------------------------------------------------------------- /microservice-api-gateway/src/main/docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM java:8 2 | VOLUME /tmp 3 | ADD api-gateway-microservice-0.1.0.jar app.jar 4 | RUN bash -c 'touch /app.jar' 5 | ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"] 6 | -------------------------------------------------------------------------------- /microservice-provider-user/src/main/resources/data.sql: -------------------------------------------------------------------------------- 1 | insert into user (id, username, age) values (1,'Tom',12); 2 | insert into user (id, username, age) values (2,'Jerry', 23); 3 | insert into user (id, username, age) values (3,'Reno', 44); 4 | insert into user (id, username, age) values (4,'Josh', 55); 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # maven ignore 2 | target/ 3 | *.jar 4 | *.war 5 | *.zip 6 | *.tar 7 | *.tar.gz 8 | 9 | # eclipse ignore 10 | .settings/ 11 | .project 12 | .classpath 13 | 14 | # idea ignore 15 | .idea/ 16 | *.ipr 17 | *.iml 18 | *.iws 19 | 20 | # temp ignore 21 | *.log 22 | *.cache 23 | *.diff 24 | *.patch 25 | *.tmp 26 | 27 | # system ignore 28 | .DS_Store 29 | Thumbs.db 30 | 31 | # else 32 | .springBeans 33 | -------------------------------------------------------------------------------- /microservice-provider-user/src/main/java/com/itmuch/cloud/study/repository/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.repository; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import org.springframework.stereotype.Repository; 5 | 6 | import com.itmuch.cloud.study.domain.User; 7 | 8 | @Repository 9 | public interface UserRepository extends JpaRepository { 10 | } 11 | -------------------------------------------------------------------------------- /microservice-discovery-eureka/src/main/docker/Dockerfile: -------------------------------------------------------------------------------- 1 | # 基于哪个镜像 2 | FROM java:8 3 | 4 | # 将本地文件夹挂载到当前容器 5 | VOLUME /tmp 6 | 7 | # 拷贝文件到容器,也可以直接写成ADD microservice-discovery-eureka-0.0.1-SNAPSHOT.jar /app.jar 8 | ADD microservice-discovery-eureka-0.0.1-SNAPSHOT.jar app.jar 9 | RUN bash -c 'touch /app.jar' 10 | 11 | # 开放8761端口 12 | EXPOSE 8761 13 | 14 | # 配置容器启动后执行的命令 15 | ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"] -------------------------------------------------------------------------------- /microservice-consumer-movie-ribbon-with-hystrix/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8011 3 | spring: 4 | application: 5 | name: microservice-consumer-movie-ribbon-with-hystrix 6 | eureka: 7 | client: 8 | serviceUrl: 9 | defaultZone: http://discovery:8761/eureka/ 10 | instance: 11 | hostname: ribbon # 此处,preferIpAddress不设置或者设为false,不能设为true,否则影响turbine的测试。turbine存在的问题:eureka.instance.hostname一致时只能检测到一个节点,会造成turbine数据不完整 -------------------------------------------------------------------------------- /microservice-discovery-eureka/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8761 # 指定该Eureka实例的端口 3 | 4 | eureka: 5 | instance: 6 | hostname: discovery # 指定该Eureka实例的主机名 7 | client: 8 | registerWithEureka: false 9 | fetchRegistry: false 10 | serviceUrl: 11 | defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ 12 | 13 | # 参考文档:http://projects.spring.io/spring-cloud/docs/1.0.3/spring-cloud.html#_standalone_mode 14 | # 参考文档:http://my.oschina.net/buwei/blog/618756 -------------------------------------------------------------------------------- /microservice-provider-user/src/main/java/com/itmuch/cloud/study/UserApplication.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | 7 | @SpringBootApplication 8 | @EnableDiscoveryClient 9 | public class UserApplication { 10 | public static void main(String[] args) { 11 | SpringApplication.run(UserApplication.class, args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /microservice-discovery-eureka/src/main/java/com/itmuch/cloud/study/EurekaApplication.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | /** 8 | * 使用Eureka做服务发现. 9 | * @author eacdy 10 | */ 11 | @SpringBootApplication 12 | @EnableEurekaServer 13 | public class EurekaApplication { 14 | public static void main(String[] args) { 15 | SpringApplication.run(EurekaApplication.class, args); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /microservice-hystrix-turbine/src/main/java/com/itmuch/cloud/study/turbine/TurbineApplication.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.turbine; 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication; 4 | import org.springframework.boot.builder.SpringApplicationBuilder; 5 | import org.springframework.cloud.netflix.turbine.EnableTurbine; 6 | 7 | /** 8 | * 通过@EnableTurbine接口,激活对Turbine的支持。 9 | * @author eacdy 10 | */ 11 | @SpringBootApplication 12 | @EnableTurbine 13 | public class TurbineApplication { 14 | public static void main(String[] args) { 15 | new SpringApplicationBuilder(TurbineApplication.class).web(true).run(args); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /microservice-api-gateway/src/main/java/com/itmuch/cloud/study/ZuulApiGatewayApplication.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.zuul.EnableZuulProxy; 6 | 7 | /** 8 | * 使用@EnableZuulProxy注解激活zuul。 9 | * 跟进该注解可以看到该注解整合了@EnableCircuitBreaker、@EnableDiscoveryClient,是个组合注解,目的是简化配置。 10 | * @author eacdy 11 | */ 12 | @SpringBootApplication 13 | @EnableZuulProxy 14 | public class ZuulApiGatewayApplication { 15 | public static void main(String[] args) { 16 | SpringApplication.run(ZuulApiGatewayApplication.class, args); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /microservice-api-gateway/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: microservice-api-gateway 4 | server: 5 | port: 8050 6 | eureka: 7 | instance: 8 | hostname: gateway 9 | client: 10 | serviceUrl: 11 | defaultZone: http://discovery:8761/eureka/ 12 | zuul: 13 | ignored-services: microservice-provider-user # 需要忽视的服务(配置后将不会被路由) 14 | routes: 15 | movie: # 可以随便写,在zuul上面唯一即可;当这里的值 = service-id时,service-id可以不写。 16 | path: /movie/** # 想要映射到的路径 17 | service-id: microservice-consumer-movie-ribbon-with-hystrix # Eureka中的serviceId 18 | -------------------------------------------------------------------------------- /microservice-consumer-movie-ribbon-with-hystrix/src/main/java/com/itmuch/cloud/study/user/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.user.entity; 2 | 3 | public class User { 4 | private Long id; 5 | private String username; 6 | private Integer age; 7 | 8 | public Long getId() { 9 | return this.id; 10 | } 11 | 12 | public void setId(Long id) { 13 | this.id = id; 14 | } 15 | 16 | public String getUsername() { 17 | return this.username; 18 | } 19 | 20 | public void setUsername(String username) { 21 | this.username = username; 22 | } 23 | 24 | public Integer getAge() { 25 | return this.age; 26 | } 27 | 28 | public void setAge(Integer age) { 29 | this.age = age; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /microservice-consumer-movie-ribbon-with-hystrix/src/main/java/com/itmuch/cloud/study/user/controller/RibbonHystrixController.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.user.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.PathVariable; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | import com.itmuch.cloud.study.user.entity.User; 9 | import com.itmuch.cloud.study.user.service.RibbonHystrixService; 10 | 11 | @RestController 12 | public class RibbonHystrixController { 13 | @Autowired 14 | private RibbonHystrixService ribbonHystrixService; 15 | 16 | @GetMapping("/ribbon/{id}") 17 | public User findById(@PathVariable Long id) { 18 | return this.ribbonHystrixService.findById(id); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /microservice-hystrix-dashboard/src/main/java/com/itmuch/cloud/study/hystrixdashboard/HystrixDashboardApplication.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.hystrixdashboard; 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication; 4 | import org.springframework.boot.builder.SpringApplicationBuilder; 5 | import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; 6 | 7 | /** 8 | * 测试步骤: 9 | * 1. 访问http://localhost:8030/hystrix.stream 可以查看Dashboard 10 | * 2. 在上面的输入框填入: http://想监控的服务:端口/hystrix.stream进行测试 11 | * 注意:首先要先调用一下想监控的服务的API,否则将会显示一个空的图表. 12 | * @author eacdy 13 | */ 14 | @SpringBootApplication 15 | @EnableHystrixDashboard 16 | public class HystrixDashboardApplication { 17 | public static void main(String[] args) { 18 | new SpringApplicationBuilder(HystrixDashboardApplication.class).web(true).run(args); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /microservice-provider-user/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8000 3 | spring: 4 | application: 5 | name: microservice-provider-user # 项目名称尽量用小写 6 | jpa: 7 | generate-ddl: false 8 | show-sql: true 9 | hibernate: 10 | ddl-auto: none 11 | datasource: # 指定数据源 12 | platform: h2 # 指定数据源类型 13 | schema: classpath:schema.sql # 指定h2数据库的建表脚本 14 | data: classpath:data.sql # 指定h2数据库的insert脚本 15 | logging: 16 | level: 17 | root: INFO 18 | org.hibernate: INFO 19 | org.hibernate.type.descriptor.sql.BasicBinder: TRACE 20 | org.hibernate.type.descriptor.sql.BasicExtractor: TRACE 21 | com.itmuch.youran.persistence: ERROR 22 | eureka: 23 | client: 24 | serviceUrl: 25 | defaultZone: http://discovery:8761/eureka/ # 指定注册中心的地址 26 | instance: 27 | preferIpAddress: true -------------------------------------------------------------------------------- /microservice-provider-user/src/main/java/com/itmuch/cloud/study/domain/User.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.domain; 2 | 3 | import javax.persistence.Column; 4 | import javax.persistence.Entity; 5 | import javax.persistence.GeneratedValue; 6 | import javax.persistence.GenerationType; 7 | import javax.persistence.Id; 8 | 9 | @Entity 10 | public class User { 11 | @Id 12 | @GeneratedValue(strategy = GenerationType.AUTO) 13 | private Long id; 14 | @Column 15 | private String username; 16 | @Column 17 | private Integer age; 18 | 19 | public Long getId() { 20 | return this.id; 21 | } 22 | 23 | public void setId(Long id) { 24 | this.id = id; 25 | } 26 | 27 | public String getUsername() { 28 | return this.username; 29 | } 30 | 31 | public void setUsername(String username) { 32 | this.username = username; 33 | } 34 | 35 | public Integer getAge() { 36 | return this.age; 37 | } 38 | 39 | public void setAge(Integer age) { 40 | this.age = age; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /microservice-hystrix-turbine/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application.name: microservice-hystrix-turbine 3 | server: 4 | port: 8031 5 | security.basic.enabled: false 6 | turbine: 7 | aggregator: 8 | clusterConfig: default # 指定聚合哪些集群,多个使用","分割,默认为default。可使用http://.../turbine.stream?cluster={clusterConfig之一}访问 9 | appConfig: microservice-consumer-movie-feign-with-hystrix-stream,microservice-consumer-movie-ribbon-with-hystrix ### 配置Eureka中的serviceId列表,表明监控哪些服务 10 | clusterNameExpression: new String("default") 11 | # 1. clusterNameExpression指定集群名称,默认表达式appName;此时:turbine.aggregator.clusterConfig需要配置想要监控的应用名称 12 | # 2. 当clusterNameExpression: default时,turbine.aggregator.clusterConfig可以不写,因为默认就是default 13 | # 3. 当clusterNameExpression: metadata['cluster']时,假设想要监控的应用配置了eureka.instance.metadata-map.cluster: ABC,则需要配置,同时turbine.aggregator.clusterConfig: ABC 14 | eureka: 15 | client: 16 | serviceUrl: 17 | defaultZone: http://discovery:8761/eureka/ 18 | 19 | 20 | ### 参考:http://blog.csdn.net/liaokailin/article/details/51344281 21 | ### 参考:http://blog.csdn.net/zhuchuangang/article/details/51289593 -------------------------------------------------------------------------------- /microservice-consumer-movie-ribbon-with-hystrix/src/main/java/com/itmuch/cloud/study/MovieRibbonHystrixApplication.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; 6 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 7 | import org.springframework.cloud.client.loadbalancer.LoadBalanced; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.web.client.RestTemplate; 10 | 11 | /** 12 | * 使用@EnableCircuitBreaker注解开启断路器功能 13 | * @author eacdy 14 | */ 15 | @SpringBootApplication 16 | @EnableDiscoveryClient 17 | @EnableCircuitBreaker 18 | public class MovieRibbonHystrixApplication { 19 | /** 20 | * 实例化RestTemplate,通过@LoadBalanced注解开启均衡负载能力. 21 | * @return restTemplate 22 | */ 23 | @Bean 24 | @LoadBalanced 25 | public RestTemplate restTemplate() { 26 | return new RestTemplate(); 27 | } 28 | 29 | public static void main(String[] args) { 30 | SpringApplication.run(MovieRibbonHystrixApplication.class, args); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | microservice-discovery-eureka: 2 | image: reg.itmuch.com/microservice-discovery-eureka 3 | ports: 4 | - 8761:8761 5 | hostname: discovery 6 | microservice-provider-user: 7 | image: reg.itmuch.com/microservice-provider-user 8 | ports: 9 | - 8000:8000 10 | links: 11 | - microservice-discovery-eureka 12 | microservice-consumer-movie-ribbon-with-hystrix: 13 | image: reg.itmuch.com/microservice-consumer-movie-ribbon-with-hystrix 14 | ports: 15 | - 8011:8011 16 | links: 17 | - microservice-discovery-eureka 18 | hostname: ribbon 19 | microservice-hystrix-dashboard: 20 | image: reg.itmuch.com/microservice-hystrix-dashboard 21 | ports: 22 | - 8030:8030 23 | links: 24 | - microservice-discovery-eureka 25 | - microservice-hystrix-turbine 26 | microservice-hystrix-turbine: 27 | image: reg.itmuch.com/microservice-hystrix-turbine 28 | ports: 29 | - 8031:8031 30 | links: 31 | - microservice-discovery-eureka 32 | - microservice-consumer-movie-ribbon-with-hystrix 33 | microservice-api-gateway: 34 | image: reg.itmuch.com/microservice-api-gateway 35 | ports: 36 | - 8050:8050 37 | links: 38 | - microservice-discovery-eureka 39 | - microservice-consumer-movie-ribbon-with-hystrix 40 | -------------------------------------------------------------------------------- /microservice-consumer-movie-ribbon-with-hystrix/src/main/java/com/itmuch/cloud/study/user/service/RibbonHystrixService.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.user.service; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | import org.springframework.web.client.RestTemplate; 8 | 9 | import com.itmuch.cloud.study.user.entity.User; 10 | import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; 11 | 12 | @Service 13 | public class RibbonHystrixService { 14 | @Autowired 15 | private RestTemplate restTemplate; 16 | private static final Logger LOGGER = LoggerFactory.getLogger(RibbonHystrixService.class); 17 | 18 | /** 19 | * 使用@HystrixCommand注解指定当该方法发生异常时调用的方法 20 | * @param id id 21 | * @return 通过id查询到的用户 22 | */ 23 | @HystrixCommand(fallbackMethod = "fallback") 24 | public User findById(Long id) { 25 | return this.restTemplate.getForObject("http://microservice-provider-user/" + id, User.class); 26 | } 27 | 28 | /** 29 | * hystrix fallback方法 30 | * @param id id 31 | * @return 默认的用户 32 | */ 33 | public User fallback(Long id) { 34 | RibbonHystrixService.LOGGER.info("异常发生,进入fallback方法,接收的参数:id = {}", id); 35 | User user = new User(); 36 | user.setId(-1L); 37 | user.setUsername("default username"); 38 | user.setAge(0); 39 | return user; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /microservice-provider-user/src/main/java/com/itmuch/cloud/study/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.cloud.client.ServiceInstance; 5 | import org.springframework.cloud.client.discovery.DiscoveryClient; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.PathVariable; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | import com.itmuch.cloud.study.domain.User; 11 | import com.itmuch.cloud.study.repository.UserRepository; 12 | 13 | /** 14 | * 作用: 15 | * ① 测试服务实例的相关内容 16 | * ② 为后来的服务做提供 17 | * @author eacdy 18 | */ 19 | @RestController 20 | public class UserController { 21 | @Autowired 22 | private DiscoveryClient discoveryClient; 23 | @Autowired 24 | private UserRepository userRepository; 25 | 26 | /** 27 | * 注:@GetMapping("/{id}")是spring 4.3的新注解等价于: 28 | * @RequestMapping(value = "/id", method = RequestMethod.GET) 29 | * 类似的注解还有@PostMapping等等 30 | * @param id 31 | * @return user信息 32 | */ 33 | @GetMapping("/{id}") 34 | public User findById(@PathVariable Long id) { 35 | User findOne = this.userRepository.findOne(id); 36 | return findOne; 37 | } 38 | 39 | /** 40 | * 本地服务实例的信息 41 | * @return 42 | */ 43 | @GetMapping("/instance-info") 44 | public ServiceInstance showInfo() { 45 | ServiceInstance localServiceInstance = this.discoveryClient.getLocalServiceInstance(); 46 | return localServiceInstance; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /microservice-discovery-eureka/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | microservice-discovery-eureka 7 | jar 8 | 9 | 10 | com.itmuch.cloud 11 | spring-cloud-microservice-study 12 | 0.0.1-SNAPSHOT 13 | 14 | 15 | 16 | 17 | org.springframework.cloud 18 | spring-cloud-starter-eureka-server 19 | 20 | 21 | 22 | 23 | 24 | 25 | com.spotify 26 | docker-maven-plugin 27 | 28 | 29 | build-image 30 | package 31 | 32 | build 33 | 34 | 35 | 36 | 37 | ${docker.image.prefix}/${project.artifactId} 38 | java 39 | ["java", "-jar", "/${project.build.finalName}.jar"] 40 | 41 | 42 | / 43 | ${project.build.directory} 44 | ${project.build.finalName}.jar 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /microservice-api-gateway/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 4.0.0 6 | 7 | microservice-api-gateway 8 | jar 9 | 10 | 11 | com.itmuch.cloud 12 | spring-cloud-microservice-study 13 | 0.0.1-SNAPSHOT 14 | 15 | 16 | 17 | 18 | org.springframework.cloud 19 | spring-cloud-starter-zuul 20 | 21 | 22 | 23 | org.springframework.cloud 24 | spring-cloud-starter-eureka 25 | 26 | 27 | 28 | 29 | 30 | 31 | com.spotify 32 | docker-maven-plugin 33 | 34 | 35 | build-image 36 | package 37 | 38 | build 39 | 40 | 41 | 42 | 43 | ${docker.image.prefix}/${project.artifactId} 44 | java 45 | ["java", "-jar", "/${project.build.finalName}.jar"] 46 | 47 | 48 | / 49 | ${project.build.directory} 50 | ${project.build.finalName}.jar 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /microservice-hystrix-dashboard/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | microservice-hystrix-dashboard 7 | jar 8 | 9 | 10 | com.itmuch.cloud 11 | spring-cloud-microservice-study 12 | 0.0.1-SNAPSHOT 13 | 14 | 15 | 16 | 17 | org.springframework.cloud 18 | spring-cloud-starter-hystrix-dashboard 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-actuator 23 | 24 | 25 | 26 | 27 | 28 | 29 | com.spotify 30 | docker-maven-plugin 31 | 32 | 33 | build-image 34 | package 35 | 36 | build 37 | 38 | 39 | 40 | 41 | ${docker.image.prefix}/${project.artifactId} 42 | java 43 | ["java", "-jar", "/${project.build.finalName}.jar"] 44 | 45 | 46 | / 47 | ${project.build.directory} 48 | ${project.build.finalName}.jar 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /microservice-hystrix-turbine/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | microservice-hystrix-turbine 7 | jar 8 | 9 | 10 | com.itmuch.cloud 11 | spring-cloud-microservice-study 12 | 0.0.1-SNAPSHOT 13 | 14 | 15 | 16 | 17 | org.springframework.cloud 18 | spring-cloud-starter-turbine 19 | 20 | 21 | org.springframework.cloud 22 | spring-cloud-netflix-turbine 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter-actuator 27 | 28 | 29 | 30 | 31 | 32 | 33 | com.spotify 34 | docker-maven-plugin 35 | 36 | 37 | build-image 38 | package 39 | 40 | build 41 | 42 | 43 | 44 | 45 | ${docker.image.prefix}/${project.artifactId} 46 | java 47 | ["java", "-jar", "/${project.build.finalName}.jar"] 48 | 49 | 50 | / 51 | ${project.build.directory} 52 | ${project.build.finalName}.jar 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 项目简介 2 | 本项目是《使用Spring Cloud与Docker实战微服务》: 3 | 4 | http://git.oschina.net/itmuch/spring-cloud-book 5 | 6 | http://www.github.com/eacdy/spring-cloud-book 7 | 8 | Docker章节的配套代码,如有疑问,请移步至spring-cloud-book地址。 9 | 10 | 11 | 12 | 微服务架构交流QQ群:157525002,欢迎加入。 13 | 14 | 微服务架构讨论社区:[http://ask.itmuch.com/](http://ask.itmuch.com/),欢迎加入。 15 | 16 | 17 | 18 | 内容主要包含: 19 | 20 | | 微服务角色 | 对应的技术选型 | 21 | | --------------------- | ------------------------------------ | 22 | | 注册中心(Register Server) | Eureka | 23 | | 服务提供者 | spring mvc、spring-data-jpa、h2等 | 24 | | 服务消费者 | Ribbon消费服务提供者的接口 | 25 | | 熔断器 | Hystrix,包括Hystrix Dashboard以及Turbine | 26 | | API Gateway | Zuul | 27 | 28 | 本篇旨在使用spring-cloud和docker构建一个最为简单的运行环境,有关Spring Cloud的系统讲解,请前往 29 | 30 | http://git.oschina.net/itmuch/spring-cloud-book 31 | 32 | http://www.github.com/eacdy/spring-cloud-book 33 | 34 | 35 | 36 | # 准备 37 | 38 | ## 环境准备: 39 | 40 | | 工具 | 版本或描述 | 41 | | ------ | -------------------- | 42 | | JDK | 1.8 | 43 | | IDE | STS 或者 IntelliJ IDEA | 44 | | Maven | 3.x | 45 | | Docker | 1.12.1 | 46 | 47 | 48 | 49 | ## 主机规划: 50 | 51 | | 项目名称 | 端口 | 描述 | URL | 52 | | ---------------------------------------- | ---- | ------------------- | --------------- | 53 | | microservice-api-gateway | 8050 | API Gateway | 详见文章 | 54 | | microservice-consumer-movie-ribbon-with-hystrix | 8011 | Ribbon Hystrix Demo | /ribbon/1 | 55 | | microservice-discovery-eureka | 8761 | 注册中心 | / | 56 | | microservice-hystrix-dashboard | 8030 | hystrix监控 | /hystrix.stream | 57 | | microservice-hystrix-turbine | 8031 | turbine | /turbine.stream | 58 | | microservice-provider-user | 8000 | 服务提供者 | /1 | 59 | | | | | | 60 | 61 | -------------------------------------------------------------------------------- /microservice-provider-user/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | microservice-provider-user 7 | jar 8 | 9 | 10 | com.itmuch.cloud 11 | spring-cloud-microservice-study 12 | 0.0.1-SNAPSHOT 13 | 14 | 15 | 16 | 17 | 18 | org.springframework.cloud 19 | spring-cloud-starter-eureka 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-data-jpa 25 | 26 | 27 | 28 | com.h2database 29 | h2 30 | 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-actuator 35 | 36 | 37 | 38 | 39 | 40 | 41 | com.spotify 42 | docker-maven-plugin 43 | 44 | 45 | build-image 46 | package 47 | 48 | build 49 | 50 | 51 | 52 | 53 | ${docker.image.prefix}/${project.artifactId} 54 | java 55 | ["java", "-jar", "/${project.build.finalName}.jar"] 56 | 57 | 58 | / 59 | ${project.build.directory} 60 | ${project.build.finalName}.jar 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /microservice-consumer-movie-ribbon-with-hystrix/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | microservice-consumer-movie-ribbon-with-hystrix 7 | jar 8 | 9 | 10 | com.itmuch.cloud 11 | spring-cloud-microservice-study 12 | 0.0.1-SNAPSHOT 13 | 14 | 15 | 16 | 17 | org.springframework.cloud 18 | spring-cloud-starter-eureka 19 | 20 | 21 | 22 | 23 | org.springframework.cloud 24 | spring-cloud-starter-ribbon 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-actuator 30 | 31 | 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-starter-hystrix 36 | 37 | 38 | 39 | 40 | 41 | 42 | com.spotify 43 | docker-maven-plugin 44 | 45 | 46 | build-image 47 | package 48 | 49 | build 50 | 51 | 52 | 53 | 54 | ${docker.image.prefix}/${project.artifactId} 55 | java 56 | ["java", "-jar", "/${project.build.finalName}.jar"] 57 | 58 | 59 | / 60 | ${project.build.directory} 61 | ${project.build.finalName}.jar 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.itmuch.cloud 7 | spring-cloud-microservice-study 8 | 0.0.1-SNAPSHOT 9 | pom 10 | 11 | 12 | microservice-discovery-eureka 13 | microservice-provider-user 14 | microservice-consumer-movie-ribbon-with-hystrix 15 | microservice-hystrix-dashboard 16 | microservice-hystrix-turbine 17 | microservice-api-gateway 18 | 19 | 20 | 21 | 22 | org.springframework.boot 23 | spring-boot-starter-parent 24 | 1.4.0.RELEASE 25 | 26 | 27 | 28 | UTF-8 29 | 1.8 30 | reg.itmuch.com 31 | 32 | 33 | 34 | 35 | org.springframework.cloud 36 | spring-cloud-dependencies 37 | Brixton.SR4 38 | pom 39 | import 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | org.springframework.cloud 48 | spring-cloud-dependencies 49 | Brixton.SR4 50 | pom 51 | import 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | org.springframework.boot 60 | spring-boot-maven-plugin 61 | 62 | 63 | 64 | 65 | 66 | 67 | com.spotify 68 | docker-maven-plugin 69 | 0.4.12 70 | 71 | 72 | 73 | 74 | 75 | --------------------------------------------------------------------------------