├── .gitignore ├── LICENSE.txt ├── README.md ├── ad ├── amz-购书链接.jpg ├── catalog.doc ├── catalog.png └── jd-购书链接.png ├── additional-microservice-consumer-movie-ribbon-exception-but-no-fallback ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ ├── ConsumerMovieApplication.java │ │ └── user │ │ ├── controller │ │ └── MovieController.java │ │ ├── entity │ │ └── User.java │ │ └── service │ │ └── UserService.java │ └── resources │ └── application.yml ├── additional-microservice-consumer-movie-ribbon-hystrix-get-the-exception ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ ├── ConsumerMovieApplication.java │ │ └── user │ │ ├── controller │ │ └── MovieController.java │ │ └── entity │ │ └── User.java │ └── resources │ └── application.yml ├── eureka-rest-api-test.xml ├── microservice-config-client-authenticating ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ ├── ConfigClientApplication.java │ │ └── controller │ │ └── ConfigClientController.java │ └── resources │ ├── application.yml │ └── bootstrap.yml ├── microservice-config-client-eureka-authenticating ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ ├── ConfigClientApplication.java │ │ └── controller │ │ └── ConfigClientController.java │ └── resources │ ├── application.yml │ └── bootstrap.yml ├── microservice-config-client-eureka ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ ├── ConfigClientApplication.java │ │ └── controller │ │ └── ConfigClientController.java │ └── resources │ ├── application.yml │ └── bootstrap.yml ├── microservice-config-client-refresh-cloud-bus ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ ├── ConfigClientApplication.java │ │ └── controller │ │ └── ConfigClientController.java │ └── resources │ ├── application.yml │ └── bootstrap.yml ├── microservice-config-client-refresh ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ ├── ConfigClientApplication.java │ │ └── controller │ │ └── ConfigClientController.java │ └── resources │ ├── application.yml │ └── bootstrap.yml ├── microservice-config-client ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ ├── ConfigClientApplication.java │ │ └── controller │ │ └── ConfigClientController.java │ └── resources │ ├── application.yml │ └── bootstrap.yml ├── microservice-config-server-authenticating ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ └── ConfigServerApplication.java │ └── resources │ └── application.yml ├── microservice-config-server-encryption-rsa ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ └── ConfigServerApplication.java │ └── resources │ ├── application.yml │ └── server.jks ├── microservice-config-server-encryption ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ └── ConfigServerApplication.java │ └── resources │ └── application.yml ├── microservice-config-server-eureka-authenticating ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ └── ConfigServerApplication.java │ └── resources │ └── application.yml ├── microservice-config-server-eureka ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ └── ConfigServerApplication.java │ └── resources │ └── application.yml ├── microservice-config-server-health ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ └── ConfigServerApplication.java │ └── resources │ └── application.yml ├── microservice-config-server-refresh-cloud-bus ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ └── ConfigServerApplication.java │ └── resources │ └── application.yml ├── microservice-config-server ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ └── ConfigServerApplication.java │ └── resources │ ├── application.yml │ ├── application.yml.bak1-git地址占位符 │ ├── application.yml.bak2-模式匹配 │ ├── application.yml.bak3-子目录查询search-path │ └── application.yml.bak4-启动时clone Git仓库 ├── microservice-consumer-movie-feign-customizing ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ ├── config │ │ └── FeignConfiguration.java │ │ └── study │ │ ├── ConsumerMovieApplication.java │ │ └── user │ │ ├── controller │ │ └── MovieController.java │ │ ├── entity │ │ └── User.java │ │ └── feign │ │ └── UserFeignClient.java │ └── resources │ └── application.yml ├── microservice-consumer-movie-feign-hystrix-fallback-factory ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ ├── ConsumerMovieApplication.java │ │ └── user │ │ ├── controller │ │ └── MovieController.java │ │ ├── entity │ │ └── User.java │ │ └── feign │ │ └── UserFeignClient.java │ └── resources │ └── application.yml ├── microservice-consumer-movie-feign-hystrix-fallback-stream ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ ├── ConsumerMovieApplication.java │ │ └── user │ │ ├── controller │ │ └── MovieController.java │ │ ├── entity │ │ └── User.java │ │ └── feign │ │ └── UserFeignClient.java │ └── resources │ └── application.yml ├── microservice-consumer-movie-feign-hystrix-fallback ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ ├── ConsumerMovieApplication.java │ │ └── user │ │ ├── controller │ │ └── MovieController.java │ │ ├── entity │ │ └── User.java │ │ └── feign │ │ └── UserFeignClient.java │ └── resources │ └── application.yml ├── microservice-consumer-movie-feign-logging ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ ├── config │ │ └── FeignLogConfiguration.java │ │ └── study │ │ ├── ConsumerMovieApplication.java │ │ └── user │ │ ├── controller │ │ └── MovieController.java │ │ ├── entity │ │ └── User.java │ │ └── feign │ │ └── UserFeignClient.java │ └── resources │ └── application.yml ├── microservice-consumer-movie-feign-manual ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ ├── ConsumerMovieApplication.java │ │ └── user │ │ ├── controller │ │ └── MovieController.java │ │ ├── entity │ │ └── User.java │ │ └── feign │ │ └── UserFeignClient.java │ └── resources │ └── application.yml ├── microservice-consumer-movie-feign-multiple-params ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ ├── ConsumerMovieApplication.java │ │ └── user │ │ ├── controller │ │ └── MovieController.java │ │ ├── entity │ │ └── User.java │ │ └── feign │ │ └── UserFeignClient.java │ └── resources │ └── application.yml ├── microservice-consumer-movie-feign ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ ├── ConsumerMovieApplication.java │ │ └── user │ │ ├── controller │ │ └── MovieController.java │ │ ├── entity │ │ └── User.java │ │ └── feign │ │ └── UserFeignClient.java │ └── resources │ └── application.yml ├── microservice-consumer-movie-ribbon-customizing-properties ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ ├── ConsumerMovieApplication.java │ │ └── user │ │ ├── controller │ │ └── MovieController.java │ │ └── entity │ │ └── User.java │ └── resources │ └── application.yml ├── microservice-consumer-movie-ribbon-customizing ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ ├── config │ │ └── RibbonConfiguration.java │ │ └── study │ │ ├── ConsumerMovieApplication.java │ │ ├── config │ │ └── TestConfiguration.java │ │ └── user │ │ ├── controller │ │ └── MovieController.java │ │ └── entity │ │ └── User.java │ └── resources │ └── application.yml ├── microservice-consumer-movie-ribbon-hystrix-turbine-mq ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ ├── ConsumerMovieApplication.java │ │ └── user │ │ ├── controller │ │ └── MovieController.java │ │ └── entity │ │ └── User.java │ └── resources │ └── application.yml ├── microservice-consumer-movie-ribbon-hystrix ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ ├── ConsumerMovieApplication.java │ │ └── user │ │ ├── controller │ │ └── MovieController.java │ │ └── entity │ │ └── User.java │ └── resources │ └── application.yml ├── microservice-consumer-movie-ribbon ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ ├── ConsumerMovieApplication.java │ │ └── user │ │ ├── controller │ │ └── MovieController.java │ │ └── entity │ │ └── User.java │ └── resources │ └── application.yml ├── microservice-consumer-movie-understanding-metadata ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ ├── ConsumerMovieApplication.java │ │ └── user │ │ ├── controller │ │ └── MovieController.java │ │ └── entity │ │ └── User.java │ └── resources │ └── application.yml ├── microservice-consumer-movie-without-eureka ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ ├── ConsumerMovieApplication.java │ │ └── user │ │ ├── controller │ │ └── MovieController.java │ │ └── entity │ │ └── User.java │ └── resources │ └── application.yml ├── microservice-consumer-movie ├── .gitignore ├── .springBeans ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ ├── ConsumerMovieApplication.java │ │ └── user │ │ ├── controller │ │ └── MovieController.java │ │ └── entity │ │ └── User.java │ └── resources │ └── application.yml ├── microservice-discovery-eureka-authenticating ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ └── EurekaApplication.java │ └── resources │ └── application.yml ├── microservice-discovery-eureka-ha ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ └── EurekaApplication.java │ └── resources │ └── application.yml ├── microservice-discovery-eureka ├── .gitignore ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ └── EurekaApplication.java │ └── resources │ └── application.yml ├── microservice-file-upload ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ ├── FileUploadApplication.java │ │ └── controller │ │ └── FileUploadController.java │ └── resources │ ├── application.yml │ └── static │ └── index.html ├── microservice-gateway-zuul-aggregation ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ ├── AggregationController.java │ │ ├── AggregationService.java │ │ ├── User.java │ │ └── ZuulApplication.java │ └── resources │ └── application.yml ├── microservice-gateway-zuul-fallback ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ ├── ZuulApplication.java │ │ └── fallback │ │ └── UserFallbackProvider.java │ └── resources │ └── application.yml ├── microservice-gateway-zuul-file-upload ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ └── ZuulApplication.java │ └── resources │ └── application.yml ├── microservice-gateway-zuul-filter-groovy ├── pom.xml └── src │ └── main │ ├── filters │ ├── post │ │ └── ResponseFilter.groovy │ └── pre │ │ └── PreRequest.groovy │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ └── ZuulApplication.java │ └── resources │ └── application.yml ├── microservice-gateway-zuul-filter ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ ├── ZuulApplication.java │ │ └── filters │ │ └── pre │ │ └── PreRequestLogFilter.java │ └── resources │ └── application.yml ├── microservice-gateway-zuul-reg-exp ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ └── ZuulApplication.java │ └── resources │ └── application.yml ├── microservice-gateway-zuul ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ └── ZuulApplication.java │ └── resources │ ├── application.yml │ ├── application.yml.bak1_指定微服务路径 │ ├── application.yml.bak2_忽略指定微服务 │ ├── application.yml.bak3_忽略所有微服务,只路由指定的微服务 │ ├── application.yml.bak4_同时指定微服务的serviceId和对应路径 │ ├── application.yml.bak5_同时指定path和url │ ├── application.yml.bak6_同时指定path和URL,并且不破坏Zuul的Hystrix、Ribbon特性。 │ ├── application.yml.bak8_为Zuul添加映射前缀1 │ ├── application.yml.bak8_为Zuul添加映射前缀2 │ └── application.yml.bak9_忽略某些路径 ├── microservice-hystrix-dashboard ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ └── HystrixDashboardApplication.java │ └── resources │ └── application.yml ├── microservice-hystrix-turbine-mq ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ └── TurbineApplication.java │ └── resources │ └── application.yml ├── microservice-hystrix-turbine ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ └── TurbineApplication.java │ └── resources │ └── application.yml ├── microservice-provider-user-ip ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ ├── ProviderUserApplication.java │ │ ├── controller │ │ └── UserController.java │ │ ├── entity │ │ └── User.java │ │ └── repository │ │ └── UserRepository.java │ └── resources │ ├── application.yml │ ├── application.yml.bak1-忽略指定名称的网卡 │ ├── application.yml.bak2-正则指定使用的地址 │ ├── application.yml.bak3-使用站点本地地址 │ ├── application.yml.bak4-手动指定IP │ ├── data.sql │ └── schema.sql ├── microservice-provider-user-multiple-params ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ ├── ProviderUserApplication.java │ │ ├── controller │ │ └── UserController.java │ │ ├── entity │ │ └── User.java │ │ └── repository │ │ └── UserRepository.java │ └── resources │ ├── application-autherntication.yml.bak │ ├── application-ha.yml.bak │ ├── application.yml │ ├── data.sql │ └── schema.sql ├── microservice-provider-user-my-metadata ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ ├── ProviderUserApplication.java │ │ ├── controller │ │ └── UserController.java │ │ ├── entity │ │ └── User.java │ │ └── repository │ │ └── UserRepository.java │ └── resources │ ├── application.yml │ ├── data.sql │ └── schema.sql ├── microservice-provider-user-with-auth ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ ├── ProviderUserApplication.java │ │ ├── controller │ │ └── UserController.java │ │ ├── entity │ │ └── User.java │ │ ├── repository │ │ └── UserRepository.java │ │ └── security │ │ └── WebSecurityConfig.java │ └── resources │ ├── application.yml │ ├── data.sql │ └── schema.sql ├── microservice-provider-user ├── .gitignore ├── .springBeans ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ ├── ProviderUserApplication.java │ │ ├── controller │ │ └── UserController.java │ │ ├── entity │ │ └── User.java │ │ └── repository │ │ └── UserRepository.java │ └── resources │ ├── application-autherntication.yml.bak │ ├── application-ha.yml.bak │ ├── application.yml │ ├── data.sql │ └── schema.sql ├── microservice-sidecar-client-ribbon ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ ├── SidecarClientApplication.java │ │ └── sidecar │ │ └── controller │ │ └── SidecarClientController.java │ └── resources │ └── application.yml ├── microservice-sidecar ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ └── SidecarApplication.java │ └── resources │ └── application.yml ├── microservice-simple-consumer-movie ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ ├── ConsumerMovieApplication.java │ │ └── user │ │ ├── controller │ │ └── MovieController.java │ │ └── entity │ │ └── User.java │ └── resources │ └── application.yml ├── microservice-simple-provider-user ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ ├── ProviderUserApplication.java │ │ ├── controller │ │ └── UserController.java │ │ ├── entity │ │ └── User.java │ │ └── repository │ │ └── UserRepository.java │ └── resources │ ├── application.yml │ ├── data.sql │ └── schema.sql ├── node-service ├── README.txt ├── node-service.js └── py-app.py ├── pom.xml └── trace ├── microservice-simple-consumer-movie-trace-zipkin ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ ├── ConsumerMovieApplication.java │ │ └── user │ │ ├── controller │ │ └── MovieController.java │ │ └── entity │ │ └── User.java │ └── resources │ └── application.yml ├── microservice-simple-consumer-movie-trace ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ ├── ConsumerMovieApplication.java │ │ └── user │ │ ├── controller │ │ └── MovieController.java │ │ └── entity │ │ └── User.java │ └── resources │ └── application.yml ├── microservice-simple-provider-user-trace-elk ├── build │ ├── microservice-provider-user │ └── microservice-provider-user.json ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ ├── ProviderUserApplication.java │ │ ├── controller │ │ └── UserController.java │ │ ├── entity │ │ └── User.java │ │ └── repository │ │ └── UserRepository.java │ └── resources │ ├── application.yml │ ├── bootstrap.yml │ ├── data.sql │ ├── logback-spring.xml │ └── schema.sql ├── microservice-simple-provider-user-trace-zipkin-stream ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ ├── ProviderUserApplication.java │ │ ├── controller │ │ └── UserController.java │ │ ├── entity │ │ └── User.java │ │ └── repository │ │ └── UserRepository.java │ └── resources │ ├── application.yml │ ├── data.sql │ └── schema.sql ├── microservice-simple-provider-user-trace-zipkin ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ ├── ProviderUserApplication.java │ │ ├── controller │ │ └── UserController.java │ │ ├── entity │ │ └── User.java │ │ └── repository │ │ └── UserRepository.java │ └── resources │ ├── application.yml │ ├── data.sql │ └── schema.sql ├── microservice-simple-provider-user-trace ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ ├── ProviderUserApplication.java │ │ ├── controller │ │ └── UserController.java │ │ ├── entity │ │ └── User.java │ │ └── repository │ │ └── UserRepository.java │ └── resources │ ├── application.yml │ ├── data.sql │ └── schema.sql ├── microservice-trace-zipkin-server-stream-elasticsearch ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ └── ZipkinServerApplication.java │ └── resources │ └── application.yml ├── microservice-trace-zipkin-server-stream ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ └── ZipkinServerApplication.java │ └── resources │ └── application.yml ├── microservice-trace-zipkin-server ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── itmuch │ │ └── cloud │ │ └── study │ │ └── ZipkinServerApplication.java │ └── resources │ └── application.yml └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | target/ 3 | 4 | 5 | # Eclipse project files 6 | .classpath 7 | .project 8 | .settings 9 | 10 | # IDEA metadata and output dirs 11 | *.iml 12 | *.ipr 13 | *.iws 14 | .idea/ 15 | 16 | # gitbook 17 | _book 18 | tmp 19 | .springBeans -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 《Spring Cloud与Docker微服务架构实战》1-11章配套代码 2 | 3 | * 本Repo是《Spring Cloud与Docker微服务架构实战》的配套代码 4 | * 包含60+个DEMO 5 | * 覆盖的项目有Eureka、Ribbon、Feign、Hystrix、Zuul、Spring Cloud Config、Spring Cloud Bus、Spring Cloud Sleuth等,**其中,Sleuth一章的配套代码详见trace目录。其他代码都在根目录** 6 | * 12-14章配套代码详见: 7 | 8 | 9 | 10 | 11 | 12 | 13 | ## 购书链接 14 | 15 | * 京东购书链接 16 | 17 | ![](ad/jd-购书链接.png) 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | ## 交流 26 | 27 | * QQ群:157525002(2000人群,已满)、**564840207(2000人群,欢迎加入)** 28 | * 个人博客:[http://www.itmuch.com](http://www.itmuch.com) 29 | * Spring For All 社区: 30 | * 微信公众号:往下翻 ^_^ 31 | 32 | 33 | **敬请关注!!** 34 | 35 | 36 | 37 | 38 | 39 | 40 | ## 目录 41 | 42 | * Word版本:[目录下载](ad/catalog.doc) 43 | 44 | * 图片版本 45 | 46 | ![](ad/catalog.png) 47 | -------------------------------------------------------------------------------- /ad/amz-购书链接.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SpringForAll/spring-cloud-docker-microservice-book-code/c52d113288fa73ef06744155605889ca3553a121/ad/amz-购书链接.jpg -------------------------------------------------------------------------------- /ad/catalog.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SpringForAll/spring-cloud-docker-microservice-book-code/c52d113288fa73ef06744155605889ca3553a121/ad/catalog.doc -------------------------------------------------------------------------------- /ad/catalog.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SpringForAll/spring-cloud-docker-microservice-book-code/c52d113288fa73ef06744155605889ca3553a121/ad/catalog.png -------------------------------------------------------------------------------- /ad/jd-购书链接.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SpringForAll/spring-cloud-docker-microservice-book-code/c52d113288fa73ef06744155605889ca3553a121/ad/jd-购书链接.png -------------------------------------------------------------------------------- /additional-microservice-consumer-movie-ribbon-exception-but-no-fallback/README.md: -------------------------------------------------------------------------------- 1 | # 说明 2 | 3 | ## 简介 4 | 多数场景下,发生业务异常时,我们并不想触发fallback。此时要怎么办呢? 5 | Hystrix有个HystrixBadRequestException类,这是一种特殊的异常,当该异常发生时,并不会触发回退。 6 | 因此,我们可以用将我们自定义的业务异常集成该异常类,从而实现业务异常不回退的效果。 7 | 8 | 9 | ## Going Far 10 | 事实上,@HystrixCommand注解有个ignoreExceptions属性,我们也可借助该属性来配置不想fallback的异常类。示例: 11 | ```java 12 | @HystrixCommand(fallbackMethod = "findByIdFallback", ignoreExceptions = {IllegalArgumentException.class, MyBusinessException.class}) 13 | @GetMapping("/user/{id}") 14 | public User findById(@PathVariable Long id) { 15 | return this.userService.findById(id); 16 | } 17 | ``` -------------------------------------------------------------------------------- /additional-microservice-consumer-movie-ribbon-exception-but-no-fallback/src/main/java/com/itmuch/cloud/study/ConsumerMovieApplication.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.loadbalancer.LoadBalanced; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.web.client.RestTemplate; 9 | 10 | @SpringBootApplication 11 | @EnableCircuitBreaker 12 | public class ConsumerMovieApplication { 13 | @Bean 14 | @LoadBalanced 15 | public RestTemplate restTemplate() { 16 | return new RestTemplate(); 17 | } 18 | 19 | public static void main(String[] args) { 20 | SpringApplication.run(ConsumerMovieApplication.class, args); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /additional-microservice-consumer-movie-ribbon-exception-but-no-fallback/src/main/java/com/itmuch/cloud/study/user/controller/MovieController.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.user.controller; 2 | 3 | import com.itmuch.cloud.study.user.entity.User; 4 | import com.itmuch.cloud.study.user.service.UserService; 5 | import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.web.bind.annotation.GetMapping; 10 | import org.springframework.web.bind.annotation.PathVariable; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | @RestController 14 | public class MovieController { 15 | private static final Logger LOGGER = LoggerFactory.getLogger(MovieController.class); 16 | @Autowired 17 | private UserService userService; 18 | 19 | @HystrixCommand(fallbackMethod = "findByIdFallback") 20 | @GetMapping("/user/{id}") 21 | public User findById(@PathVariable Long id) { 22 | return this.userService.findById(id); 23 | } 24 | 25 | public User findByIdFallback(Long id, Throwable throwable) { 26 | User user = new User(); 27 | user.setId(-1L); 28 | user.setName("the default user"); 29 | return user; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /additional-microservice-consumer-movie-ribbon-exception-but-no-fallback/src/main/java/com/itmuch/cloud/study/user/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.user.entity; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class User { 6 | private Long id; 7 | private String username; 8 | private String name; 9 | private Integer age; 10 | private BigDecimal balance; 11 | 12 | public Long getId() { 13 | return this.id; 14 | } 15 | 16 | public void setId(Long id) { 17 | this.id = id; 18 | } 19 | 20 | public String getUsername() { 21 | return this.username; 22 | } 23 | 24 | public void setUsername(String username) { 25 | this.username = username; 26 | } 27 | 28 | public String getName() { 29 | return this.name; 30 | } 31 | 32 | public void setName(String name) { 33 | this.name = name; 34 | } 35 | 36 | public Integer getAge() { 37 | return this.age; 38 | } 39 | 40 | public void setAge(Integer age) { 41 | this.age = age; 42 | } 43 | 44 | public BigDecimal getBalance() { 45 | return this.balance; 46 | } 47 | 48 | public void setBalance(BigDecimal balance) { 49 | this.balance = balance; 50 | } 51 | } -------------------------------------------------------------------------------- /additional-microservice-consumer-movie-ribbon-exception-but-no-fallback/src/main/java/com/itmuch/cloud/study/user/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.user.service; 2 | 3 | import com.itmuch.cloud.study.user.entity.User; 4 | import com.netflix.hystrix.exception.HystrixBadRequestException; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | import org.springframework.web.client.RestTemplate; 8 | 9 | @Service 10 | public class UserService { 11 | @Autowired 12 | private RestTemplate restTemplate; 13 | 14 | public User findById(Long id) { 15 | throw new HystrixBadRequestException("business exception happens.", new Exception("")); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /additional-microservice-consumer-movie-ribbon-exception-but-no-fallback/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8010 3 | spring: 4 | application: 5 | name: microservice-consumer-movie -------------------------------------------------------------------------------- /additional-microservice-consumer-movie-ribbon-hystrix-get-the-exception/README.md: -------------------------------------------------------------------------------- 1 | # 说明 2 | 很多时候,我们希望获得造成fallback的原因。此时,可查看本示例。 3 | 事实上非常简单,即: 4 | ```java 5 | @HystrixCommand(fallbackMethod = "findByIdFallback") 6 | @GetMapping("/user/{id}") 7 | public User findById(@PathVariable Long id) { 8 | return this.restTemplate.getForObject("http://microservice-provider-user/" + id, User.class); 9 | } 10 | 11 | /** 12 | * 如果想要获得导致fallback的原因,只需在fallback方法上添加Throwable参数即可。 13 | * @param id ID 14 | * @param throwable 异常 15 | * @return 用户 16 | */ 17 | public User findByIdFallback(Long id, Throwable throwable) { 18 | LOGGER.error("进入回退方法,异常:", throwable); 19 | User user = new User(); 20 | user.setId(-1L); 21 | user.setName("默认用户"); 22 | return user; 23 | } 24 | ``` -------------------------------------------------------------------------------- /additional-microservice-consumer-movie-ribbon-hystrix-get-the-exception/src/main/java/com/itmuch/cloud/study/ConsumerMovieApplication.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 | @EnableDiscoveryClient 12 | @SpringBootApplication 13 | @EnableCircuitBreaker 14 | public class ConsumerMovieApplication { 15 | @Bean 16 | @LoadBalanced 17 | public RestTemplate restTemplate() { 18 | return new RestTemplate(); 19 | } 20 | 21 | public static void main(String[] args) { 22 | SpringApplication.run(ConsumerMovieApplication.class, args); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /additional-microservice-consumer-movie-ribbon-hystrix-get-the-exception/src/main/java/com/itmuch/cloud/study/user/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.user.entity; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class User { 6 | private Long id; 7 | private String username; 8 | private String name; 9 | private Integer age; 10 | private BigDecimal balance; 11 | 12 | public Long getId() { 13 | return this.id; 14 | } 15 | 16 | public void setId(Long id) { 17 | this.id = id; 18 | } 19 | 20 | public String getUsername() { 21 | return this.username; 22 | } 23 | 24 | public void setUsername(String username) { 25 | this.username = username; 26 | } 27 | 28 | public String getName() { 29 | return this.name; 30 | } 31 | 32 | public void setName(String name) { 33 | this.name = name; 34 | } 35 | 36 | public Integer getAge() { 37 | return this.age; 38 | } 39 | 40 | public void setAge(Integer age) { 41 | this.age = age; 42 | } 43 | 44 | public BigDecimal getBalance() { 45 | return this.balance; 46 | } 47 | 48 | public void setBalance(BigDecimal balance) { 49 | this.balance = balance; 50 | } 51 | } -------------------------------------------------------------------------------- /additional-microservice-consumer-movie-ribbon-hystrix-get-the-exception/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8010 3 | spring: 4 | application: 5 | name: microservice-consumer-movie 6 | eureka: 7 | client: 8 | serviceUrl: 9 | defaultZone: http://localhost:8761/eureka/ 10 | instance: 11 | prefer-ip-address: true -------------------------------------------------------------------------------- /eureka-rest-api-test.xml: -------------------------------------------------------------------------------- 1 | 2 | itmuch:rest-api-test:9000 3 | itmuch 4 | REST-API-TEST 5 | 127.0.0.1 6 | rest-api-test 7 | rest-api-test 8 | UP 9 | 9000 10 | 443 11 | http://127.0.0.1:9000/ 12 | http://127.0.0.1:9000/info 13 | http://127.0.0.1:9000/health 14 | 15 | MyOwn 16 | 17 | 18 | -------------------------------------------------------------------------------- /microservice-config-client-authenticating/src/main/java/com/itmuch/cloud/study/ConfigClientApplication.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ConfigClientApplication { 8 | public static void main(String[] args) { 9 | SpringApplication.run(ConfigClientApplication.class, args); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /microservice-config-client-authenticating/src/main/java/com/itmuch/cloud/study/controller/ConfigClientController.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | @RestController 8 | public class ConfigClientController { 9 | @Value("${profile}") 10 | private String profile; 11 | 12 | @GetMapping("/profile") 13 | public String hello() { 14 | return this.profile; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /microservice-config-client-authenticating/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8081 -------------------------------------------------------------------------------- /microservice-config-client-authenticating/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: microservice-foo # 对应config server所获取的配置文件的{application} 4 | cloud: 5 | config: 6 | uri: http://localhost:8080/ 7 | username: user 8 | password: password123 9 | profile: dev # profile对应config server所获取的配置文件中的{profile} 10 | label: master # 指定Git仓库的分支,对应config server所获取的配置文件的{label} -------------------------------------------------------------------------------- /microservice-config-client-eureka-authenticating/src/main/java/com/itmuch/cloud/study/ConfigClientApplication.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.EnableEurekaClient; 6 | 7 | @SpringBootApplication 8 | @EnableEurekaClient 9 | public class ConfigClientApplication { 10 | public static void main(String[] args) { 11 | SpringApplication.run(ConfigClientApplication.class, args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /microservice-config-client-eureka-authenticating/src/main/java/com/itmuch/cloud/study/controller/ConfigClientController.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | @RestController 8 | public class ConfigClientController { 9 | @Value("${profile}") 10 | private String profile; 11 | 12 | @GetMapping("/profile") 13 | public String hello() { 14 | return this.profile; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /microservice-config-client-eureka-authenticating/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8081 -------------------------------------------------------------------------------- /microservice-config-client-eureka-authenticating/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: microservice-foo # 对应config server所获取的配置文件的{application} 4 | cloud: 5 | config: 6 | username: user 7 | password: password123 8 | profile: dev 9 | label: master 10 | discovery: 11 | enabled: true # 表示使用服务发现的configserver配置,而不是自己配置的Config Server的uri,默认false 12 | service-id: microservice-config-server-eureka # 指定Config Server在服务发现中的serviceId,默认是configserver 13 | eureka: 14 | client: 15 | serviceUrl: 16 | defaultZone: http://localhost:8761/eureka/ 17 | 18 | # 参考文档:https://github.com/spring-cloud/spring-cloud-config/blob/master/docs/src/main/asciidoc/spring-cloud-config.adoc#discovery-first-bootstrap 19 | -------------------------------------------------------------------------------- /microservice-config-client-eureka/src/main/java/com/itmuch/cloud/study/ConfigClientApplication.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.EnableEurekaClient; 6 | 7 | @SpringBootApplication 8 | @EnableEurekaClient 9 | public class ConfigClientApplication { 10 | public static void main(String[] args) { 11 | SpringApplication.run(ConfigClientApplication.class, args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /microservice-config-client-eureka/src/main/java/com/itmuch/cloud/study/controller/ConfigClientController.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | @RestController 8 | public class ConfigClientController { 9 | @Value("${profile}") 10 | private String profile; 11 | 12 | @GetMapping("/profile") 13 | public String hello() { 14 | return this.profile; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /microservice-config-client-eureka/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8081 -------------------------------------------------------------------------------- /microservice-config-client-eureka/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: microservice-foo # 对应config server所获取的配置文件的{application} 4 | cloud: 5 | config: 6 | profile: dev 7 | label: master 8 | discovery: 9 | enabled: true # 表示使用服务发现组件中的Config Server,而不自己指定Config Server的uri,默认false 10 | service-id: microservice-config-server-eureka # 指定Config Server在服务发现中的serviceId,默认是configserver 11 | eureka: 12 | client: 13 | serviceUrl: 14 | defaultZone: http://localhost:8761/eureka/ 15 | 16 | # 参考文档:https://github.com/spring-cloud/spring-cloud-config/blob/master/docs/src/main/asciidoc/spring-cloud-config.adoc#discovery-first-bootstrap 17 | -------------------------------------------------------------------------------- /microservice-config-client-refresh-cloud-bus/src/main/java/com/itmuch/cloud/study/ConfigClientApplication.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ConfigClientApplication { 8 | public static void main(String[] args) { 9 | SpringApplication.run(ConfigClientApplication.class, args); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /microservice-config-client-refresh-cloud-bus/src/main/java/com/itmuch/cloud/study/controller/ConfigClientController.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.cloud.context.config.annotation.RefreshScope; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | @RestController 9 | @RefreshScope 10 | public class ConfigClientController { 11 | @Value("${profile}") 12 | private String profile; 13 | 14 | @GetMapping("/profile") 15 | public String hello() { 16 | return this.profile; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /microservice-config-client-refresh-cloud-bus/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8081 -------------------------------------------------------------------------------- /microservice-config-client-refresh-cloud-bus/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: microservice-foo # 对应config server所获取的配置文件的{application} 4 | cloud: 5 | config: 6 | uri: http://localhost:8080/ 7 | profile: dev # profile对应config server所获取的配置文件中的{profile} 8 | label: master # 指定Git仓库的分支,对应config server所获取的配置文件的{label} 9 | rabbitmq: 10 | host: localhost 11 | port: 5672 12 | username: guest 13 | password: guest -------------------------------------------------------------------------------- /microservice-config-client-refresh/src/main/java/com/itmuch/cloud/study/ConfigClientApplication.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ConfigClientApplication { 8 | public static void main(String[] args) { 9 | SpringApplication.run(ConfigClientApplication.class, args); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /microservice-config-client-refresh/src/main/java/com/itmuch/cloud/study/controller/ConfigClientController.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.cloud.context.config.annotation.RefreshScope; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | @RestController 9 | @RefreshScope 10 | public class ConfigClientController { 11 | @Value("${profile}") 12 | private String profile; 13 | 14 | @GetMapping("/profile") 15 | public String hello() { 16 | return this.profile; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /microservice-config-client-refresh/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8081 -------------------------------------------------------------------------------- /microservice-config-client-refresh/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: microservice-foo # 对应config server所获取的配置文件的{application} 4 | cloud: 5 | config: 6 | uri: http://localhost:8080/ 7 | profile: dev # profile对应config server所获取的配置文件中的{profile} 8 | label: master # 指定git仓库的分支,对应config server所获取的配置文件的{label} -------------------------------------------------------------------------------- /microservice-config-client/src/main/java/com/itmuch/cloud/study/ConfigClientApplication.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ConfigClientApplication { 8 | public static void main(String[] args) { 9 | SpringApplication.run(ConfigClientApplication.class, args); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /microservice-config-client/src/main/java/com/itmuch/cloud/study/controller/ConfigClientController.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | @RestController 8 | public class ConfigClientController { 9 | @Value("${profile}") 10 | private String profile; 11 | 12 | @GetMapping("/profile") 13 | public String hello() { 14 | return this.profile; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /microservice-config-client/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8081 -------------------------------------------------------------------------------- /microservice-config-client/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: microservice-foo # 对应config server所获取的配置文件的{application} 4 | cloud: 5 | config: 6 | uri: http://localhost:8080/ 7 | profile: dev # profile对应config server所获取的配置文件中的{profile} 8 | label: master # 指定Git仓库的分支,对应config server所获取的配置文件的{label} -------------------------------------------------------------------------------- /microservice-config-server-authenticating/src/main/java/com/itmuch/cloud/study/ConfigServerApplication.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.config.server.EnableConfigServer; 6 | 7 | @SpringBootApplication 8 | @EnableConfigServer 9 | public class ConfigServerApplication { 10 | public static void main(String[] args) { 11 | SpringApplication.run(ConfigServerApplication.class, args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /microservice-config-server-authenticating/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | spring: 4 | application: 5 | name: microservice-config-server 6 | cloud: 7 | config: 8 | server: 9 | git: 10 | uri: https://git.oschina.net/itmuch/spring-cloud-config-repo # 配置Git仓库的地址 11 | username: # Git仓库的账号 12 | password: # Git仓库的密码 13 | security: 14 | basic: 15 | enabled: true # 开启基于HTTP basic的认证 16 | user: 17 | name: user # 配置登录的账号是user 18 | password: password123 # 配置登录的密码是password123 -------------------------------------------------------------------------------- /microservice-config-server-encryption-rsa/src/main/java/com/itmuch/cloud/study/ConfigServerApplication.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.config.server.EnableConfigServer; 6 | 7 | @SpringBootApplication 8 | @EnableConfigServer 9 | public class ConfigServerApplication { 10 | public static void main(String[] args) { 11 | SpringApplication.run(ConfigServerApplication.class, args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /microservice-config-server-encryption-rsa/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | spring: 4 | application: 5 | name: microservice-config-server 6 | cloud: 7 | config: 8 | server: 9 | git: 10 | uri: https://git.oschina.net/itmuch/spring-cloud-config-repo # 配置Git仓库的地址 11 | username: # Git仓库的账号 12 | password: # Git仓库的密码 13 | encrypt: 14 | keyStore: 15 | location: classpath:/server.jks # jks文件的路径 16 | password: letmein # storepass 17 | alias: mytestkey # alias 18 | secret: changeme # keypass -------------------------------------------------------------------------------- /microservice-config-server-encryption-rsa/src/main/resources/server.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SpringForAll/spring-cloud-docker-microservice-book-code/c52d113288fa73ef06744155605889ca3553a121/microservice-config-server-encryption-rsa/src/main/resources/server.jks -------------------------------------------------------------------------------- /microservice-config-server-encryption/src/main/java/com/itmuch/cloud/study/ConfigServerApplication.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.config.server.EnableConfigServer; 6 | 7 | @SpringBootApplication 8 | @EnableConfigServer 9 | public class ConfigServerApplication { 10 | public static void main(String[] args) { 11 | SpringApplication.run(ConfigServerApplication.class, args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /microservice-config-server-encryption/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | spring: 4 | application: 5 | name: microservice-config-server 6 | cloud: 7 | config: 8 | server: 9 | git: 10 | uri: https://git.oschina.net/itmuch/spring-cloud-config-repo # 配置Git仓库的地址 11 | username: # Git仓库的账号 12 | password: # Git仓库的密码 13 | encrypt: 14 | key: foo # 设置对称密钥 15 | -------------------------------------------------------------------------------- /microservice-config-server-eureka-authenticating/src/main/java/com/itmuch/cloud/study/ConfigServerApplication.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.config.server.EnableConfigServer; 6 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 7 | 8 | @SpringBootApplication 9 | @EnableConfigServer 10 | @EnableEurekaClient 11 | public class ConfigServerApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(ConfigServerApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /microservice-config-server-eureka-authenticating/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | spring: 4 | application: 5 | name: microservice-config-server-eureka 6 | cloud: 7 | config: 8 | server: 9 | git: 10 | uri: https://git.oschina.net/itmuch/spring-cloud-config-repo # 配置Git仓库的地址 11 | username: # Git仓库的账号 12 | password: # Git仓库的密码 13 | eureka: 14 | client: 15 | serviceUrl: 16 | defaultZone: http://localhost:8761/eureka/ 17 | security: 18 | basic: 19 | enabled: true # 开启基于HTTP basic的认证 20 | user: 21 | name: user # 配置登录的账号是user 22 | password: password123 # 配置登录的密码是password123 -------------------------------------------------------------------------------- /microservice-config-server-eureka/src/main/java/com/itmuch/cloud/study/ConfigServerApplication.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.config.server.EnableConfigServer; 6 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 7 | 8 | @SpringBootApplication 9 | @EnableConfigServer 10 | @EnableEurekaClient 11 | public class ConfigServerApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(ConfigServerApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /microservice-config-server-eureka/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | spring: 4 | application: 5 | name: microservice-config-server-eureka 6 | cloud: 7 | config: 8 | server: 9 | git: 10 | uri: https://git.oschina.net/itmuch/spring-cloud-config-repo # 配置Git仓库的地址 11 | username: # Git仓库的账号 12 | password: # Git仓库的密码 13 | eureka: 14 | client: 15 | serviceUrl: 16 | defaultZone: http://localhost:8761/eureka/ -------------------------------------------------------------------------------- /microservice-config-server-health/src/main/java/com/itmuch/cloud/study/ConfigServerApplication.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.config.server.EnableConfigServer; 6 | 7 | @SpringBootApplication 8 | @EnableConfigServer 9 | public class ConfigServerApplication { 10 | public static void main(String[] args) { 11 | SpringApplication.run(ConfigServerApplication.class, args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /microservice-config-server-health/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | spring: 4 | application: 5 | name: microservice-config-server 6 | cloud: 7 | config: 8 | server: 9 | git: 10 | uri: https://git.oschina.net/itmuch/spring-cloud-config-repo/ # 配置Git仓库的地址 11 | username: # Git仓库的账号 12 | password: # Git仓库的密码 13 | health: 14 | repositories: 15 | a-foo: 16 | label: config-label-v2.0 17 | name: microservice-foo 18 | profiles: dev 19 | -------------------------------------------------------------------------------- /microservice-config-server-refresh-cloud-bus/src/main/java/com/itmuch/cloud/study/ConfigServerApplication.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.config.server.EnableConfigServer; 6 | 7 | @SpringBootApplication 8 | @EnableConfigServer 9 | public class ConfigServerApplication { 10 | public static void main(String[] args) { 11 | SpringApplication.run(ConfigServerApplication.class, args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /microservice-config-server-refresh-cloud-bus/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | spring: 4 | application: 5 | name: microservice-config-server 6 | cloud: 7 | config: 8 | server: 9 | git: 10 | uri: https://git.oschina.net/itmuch/spring-cloud-config-repo # 配置Git仓库的地址 11 | username: # Git仓库的账号 12 | password: # Git仓库的密码 13 | bus: 14 | trace: 15 | enabled: true # 开启cloud bus的跟踪 16 | rabbitmq: 17 | host: localhost 18 | port: 5672 19 | username: guest 20 | password: guest -------------------------------------------------------------------------------- /microservice-config-server/src/main/java/com/itmuch/cloud/study/ConfigServerApplication.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.config.server.EnableConfigServer; 6 | 7 | @SpringBootApplication 8 | @EnableConfigServer 9 | public class ConfigServerApplication { 10 | public static void main(String[] args) { 11 | SpringApplication.run(ConfigServerApplication.class, args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /microservice-config-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | spring: 4 | application: 5 | name: microservice-config-server 6 | cloud: 7 | config: 8 | server: 9 | git: 10 | uri: https://git.oschina.net/itmuch/spring-cloud-config-repo # 配置Git仓库的地址 11 | username: # Git仓库的账号 12 | password: # Git仓库的密码 -------------------------------------------------------------------------------- /microservice-config-server/src/main/resources/application.yml.bak1-git地址占位符: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | spring: 4 | application: 5 | name: microservice-config-server 6 | cloud: 7 | config: 8 | server: 9 | git: 10 | uri: https://git.oschina.net/itmuch/{application} 11 | username: # Git仓库的账号 12 | password: # Git仓库的密码 13 | logging: 14 | level: 15 | org.springframework.cloud: DEBUG 16 | org.springframework.boot: DEBUG 17 | 18 | ## 测试:可以使用http://localhost:8080/spring-cloud-config-repo-default.yml 获取到http://localhost:8080/spring-cloud-config-repo下的application.properties -------------------------------------------------------------------------------- /microservice-config-server/src/main/resources/application.yml.bak2-模式匹配: -------------------------------------------------------------------------------- 1 | spring: 2 | cloud: 3 | config: 4 | server: 5 | git: 6 | uri: https://github.com/spring-cloud-samples/config-repo 7 | repos: 8 | simple: https://github.com/simple/config-repo 9 | special: 10 | pattern: special*/dev*,*special*/dev* 11 | uri: https://github.com/special/config-repo 12 | local: 13 | pattern: local* 14 | uri: file:/home/configsvc/config-repo 15 | logging: 16 | level: 17 | org.springframework.cloud: DEBUG 18 | org.springframework.boot: DEBUG 19 | 20 | # 测试: 21 | # 使用http://localhost:8080/foo-default.yml,可以访问到https://github.com/spring-cloud-samples/config-repo 22 | # 使用http://localhost:8080/special/dev,观察日志及返回结果 -------------------------------------------------------------------------------- /microservice-config-server/src/main/resources/application.yml.bak3-子目录查询search-path: -------------------------------------------------------------------------------- 1 | spring: 2 | cloud: 3 | config: 4 | server: 5 | git: 6 | uri: http://git.oschina.net/itmuch/spring-cloud-config-repo 7 | search-paths: foo,bar* 8 | logging: 9 | level: 10 | org.springframework.cloud: DEBUG 11 | org.springframework.boot: DEBUG 12 | 13 | # 测试:访问http://localhost:8080/application/default -------------------------------------------------------------------------------- /microservice-config-server/src/main/resources/application.yml.bak4-启动时clone Git仓库: -------------------------------------------------------------------------------- 1 | spring: 2 | cloud: 3 | config: 4 | server: 5 | git: 6 | uri: https://github.com/spring-cloud-samples/config-repo 7 | repos: 8 | team-a: 9 | pattern: microservice-* 10 | clone-on-start: true 11 | uri: http://git.oschina.net/itmuch/spring-cloud-config-repo 12 | logging: 13 | level: 14 | org.springframework.cloud: DEBUG 15 | org.springframework.boot: DEBUG 16 | 17 | # 测试: 18 | # 1.观察启动日志 19 | # 2.访问http://localhost:8080/microservice-foo/dev -------------------------------------------------------------------------------- /microservice-consumer-movie-feign-customizing/src/main/java/com/itmuch/cloud/config/FeignConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | import feign.Contract; 7 | 8 | /** 9 | * 该类为Feign的配置类 10 | * 注意:该不应该在主应用程序上下文的@ComponentScan中。 11 | * @author 周立 12 | */ 13 | @Configuration 14 | public class FeignConfiguration { 15 | /** 16 | * 将契约改为feign原生的默认契约。这样就可以使用feign自带的注解了。 17 | * @return 默认的feign契约 18 | */ 19 | @Bean 20 | public Contract feignContract() { 21 | return new feign.Contract.Default(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /microservice-consumer-movie-feign-customizing/src/main/java/com/itmuch/cloud/study/ConsumerMovieApplication.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 | import org.springframework.cloud.netflix.feign.EnableFeignClients; 7 | 8 | @EnableDiscoveryClient 9 | @SpringBootApplication 10 | @EnableFeignClients 11 | public class ConsumerMovieApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(ConsumerMovieApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /microservice-consumer-movie-feign-customizing/src/main/java/com/itmuch/cloud/study/user/controller/MovieController.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.feign.UserFeignClient; 10 | 11 | @RestController 12 | public class MovieController { 13 | @Autowired 14 | private UserFeignClient userFeignClient; 15 | 16 | @GetMapping("/user/{id}") 17 | public User findById(@PathVariable Long id) { 18 | return this.userFeignClient.findById(id); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /microservice-consumer-movie-feign-customizing/src/main/java/com/itmuch/cloud/study/user/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.user.entity; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class User { 6 | private Long id; 7 | private String username; 8 | private String name; 9 | private Integer age; 10 | private BigDecimal balance; 11 | 12 | public Long getId() { 13 | return this.id; 14 | } 15 | 16 | public void setId(Long id) { 17 | this.id = id; 18 | } 19 | 20 | public String getUsername() { 21 | return this.username; 22 | } 23 | 24 | public void setUsername(String username) { 25 | this.username = username; 26 | } 27 | 28 | public String getName() { 29 | return this.name; 30 | } 31 | 32 | public void setName(String name) { 33 | this.name = name; 34 | } 35 | 36 | public Integer getAge() { 37 | return this.age; 38 | } 39 | 40 | public void setAge(Integer age) { 41 | this.age = age; 42 | } 43 | 44 | public BigDecimal getBalance() { 45 | return this.balance; 46 | } 47 | 48 | public void setBalance(BigDecimal balance) { 49 | this.balance = balance; 50 | } 51 | } -------------------------------------------------------------------------------- /microservice-consumer-movie-feign-customizing/src/main/java/com/itmuch/cloud/study/user/feign/UserFeignClient.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.user.feign; 2 | 3 | import org.springframework.cloud.netflix.feign.FeignClient; 4 | 5 | import com.itmuch.cloud.config.FeignConfiguration; 6 | import com.itmuch.cloud.study.user.entity.User; 7 | 8 | import feign.Param; 9 | import feign.RequestLine; 10 | 11 | /** 12 | * 使用@FeignClient的configuration属性,指定feign的配置类。 13 | * @author 周立 14 | */ 15 | @FeignClient(name = "microservice-provider-user", configuration = FeignConfiguration.class) 16 | public interface UserFeignClient { 17 | /** 18 | * 使用feign自带的注解@RequestLine 19 | * @see https://github.com/OpenFeign/feign 20 | * @param id 用户id 21 | * @return 用户信息 22 | */ 23 | @RequestLine("GET /{id}") 24 | public User findById(@Param("id") Long id); 25 | } 26 | -------------------------------------------------------------------------------- /microservice-consumer-movie-feign-customizing/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8010 3 | spring: 4 | application: 5 | name: microservice-consumer-movie 6 | eureka: 7 | client: 8 | serviceUrl: 9 | defaultZone: http://localhost:8761/eureka/ 10 | instance: 11 | prefer-ip-address: true -------------------------------------------------------------------------------- /microservice-consumer-movie-feign-hystrix-fallback-factory/src/main/java/com/itmuch/cloud/study/ConsumerMovieApplication.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 | import org.springframework.cloud.netflix.feign.EnableFeignClients; 7 | 8 | @EnableDiscoveryClient 9 | @SpringBootApplication 10 | @EnableFeignClients 11 | public class ConsumerMovieApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(ConsumerMovieApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /microservice-consumer-movie-feign-hystrix-fallback-factory/src/main/java/com/itmuch/cloud/study/user/controller/MovieController.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.feign.UserFeignClient; 10 | 11 | @RestController 12 | public class MovieController { 13 | @Autowired 14 | private UserFeignClient userFeignClient; 15 | 16 | @GetMapping("/user/{id}") 17 | public User findById(@PathVariable Long id) { 18 | return this.userFeignClient.findById(id); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /microservice-consumer-movie-feign-hystrix-fallback-factory/src/main/java/com/itmuch/cloud/study/user/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.user.entity; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class User { 6 | private Long id; 7 | private String username; 8 | private String name; 9 | private Integer age; 10 | private BigDecimal balance; 11 | 12 | public Long getId() { 13 | return this.id; 14 | } 15 | 16 | public void setId(Long id) { 17 | this.id = id; 18 | } 19 | 20 | public String getUsername() { 21 | return this.username; 22 | } 23 | 24 | public void setUsername(String username) { 25 | this.username = username; 26 | } 27 | 28 | public String getName() { 29 | return this.name; 30 | } 31 | 32 | public void setName(String name) { 33 | this.name = name; 34 | } 35 | 36 | public Integer getAge() { 37 | return this.age; 38 | } 39 | 40 | public void setAge(Integer age) { 41 | this.age = age; 42 | } 43 | 44 | public BigDecimal getBalance() { 45 | return this.balance; 46 | } 47 | 48 | public void setBalance(BigDecimal balance) { 49 | this.balance = balance; 50 | } 51 | } -------------------------------------------------------------------------------- /microservice-consumer-movie-feign-hystrix-fallback-factory/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8010 3 | spring: 4 | application: 5 | name: microservice-consumer-movie 6 | eureka: 7 | client: 8 | serviceUrl: 9 | defaultZone: http://localhost:8761/eureka/ 10 | instance: 11 | prefer-ip-address: true 12 | logging: 13 | level: 14 | feign: DEBUG 15 | 16 | # 说明:请务必注意,在Spring Cloud Dalston中,Feign默认是不开启Hystrix的。 17 | # 因此,如使用Dalston请务必额外设置属性:feign.hystrix.enabled=true,否则断路器不会生效。 18 | # 而,Spring Cloud Angel/Brixton/Camden中,Feign默认都是开启Hystrix的。无需设置该属性。 -------------------------------------------------------------------------------- /microservice-consumer-movie-feign-hystrix-fallback-stream/src/main/java/com/itmuch/cloud/study/ConsumerMovieApplication.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.netflix.feign.EnableFeignClients; 8 | 9 | @EnableDiscoveryClient 10 | @SpringBootApplication 11 | @EnableFeignClients 12 | @EnableCircuitBreaker 13 | public class ConsumerMovieApplication { 14 | public static void main(String[] args) { 15 | SpringApplication.run(ConsumerMovieApplication.class, args); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /microservice-consumer-movie-feign-hystrix-fallback-stream/src/main/java/com/itmuch/cloud/study/user/controller/MovieController.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.feign.UserFeignClient; 10 | 11 | @RestController 12 | public class MovieController { 13 | @Autowired 14 | private UserFeignClient userFeignClient; 15 | 16 | @GetMapping("/user/{id}") 17 | public User findById(@PathVariable Long id) { 18 | return this.userFeignClient.findById(id); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /microservice-consumer-movie-feign-hystrix-fallback-stream/src/main/java/com/itmuch/cloud/study/user/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.user.entity; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class User { 6 | private Long id; 7 | private String username; 8 | private String name; 9 | private Integer age; 10 | private BigDecimal balance; 11 | 12 | public Long getId() { 13 | return this.id; 14 | } 15 | 16 | public void setId(Long id) { 17 | this.id = id; 18 | } 19 | 20 | public String getUsername() { 21 | return this.username; 22 | } 23 | 24 | public void setUsername(String username) { 25 | this.username = username; 26 | } 27 | 28 | public String getName() { 29 | return this.name; 30 | } 31 | 32 | public void setName(String name) { 33 | this.name = name; 34 | } 35 | 36 | public Integer getAge() { 37 | return this.age; 38 | } 39 | 40 | public void setAge(Integer age) { 41 | this.age = age; 42 | } 43 | 44 | public BigDecimal getBalance() { 45 | return this.balance; 46 | } 47 | 48 | public void setBalance(BigDecimal balance) { 49 | this.balance = balance; 50 | } 51 | } -------------------------------------------------------------------------------- /microservice-consumer-movie-feign-hystrix-fallback-stream/src/main/java/com/itmuch/cloud/study/user/feign/UserFeignClient.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.user.feign; 2 | 3 | import org.springframework.cloud.netflix.feign.FeignClient; 4 | import org.springframework.stereotype.Component; 5 | import org.springframework.web.bind.annotation.PathVariable; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RequestMethod; 8 | 9 | import com.itmuch.cloud.study.user.entity.User; 10 | 11 | /** 12 | * Feign的fallback测试 13 | * 使用@FeignClient的fallback属性指定回退类 14 | * @author 周立 15 | */ 16 | @FeignClient(name = "microservice-provider-user", fallback = FeignClientFallback.class) 17 | public interface UserFeignClient { 18 | @RequestMapping(value = "/{id}", method = RequestMethod.GET) 19 | public User findById(@PathVariable("id") Long id); 20 | 21 | } 22 | 23 | /** 24 | * 回退类FeignClientFallback需实现Feign Client接口 25 | * FeignClientFallback也可以是public class,没有区别 26 | * @author 周立 27 | */ 28 | @Component 29 | class FeignClientFallback implements UserFeignClient { 30 | @Override 31 | public User findById(Long id) { 32 | User user = new User(); 33 | user.setId(-1L); 34 | user.setUsername("默认用户"); 35 | return user; 36 | } 37 | } -------------------------------------------------------------------------------- /microservice-consumer-movie-feign-hystrix-fallback-stream/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8020 3 | spring: 4 | application: 5 | name: microservice-consumer-movie-feign-hystrix-fallback-stream 6 | eureka: 7 | client: 8 | serviceUrl: 9 | defaultZone: http://localhost:8761/eureka/ 10 | instance: 11 | prefer-ip-address: true 12 | 13 | 14 | 15 | 16 | 17 | # 说明:请务必注意,在Spring Cloud Dalston中,Feign默认是不开启Hystrix的。 18 | # 因此,如使用Dalston请务必额外设置属性:feign.hystrix.enabled=true,否则断路器不会生效。 19 | # 而,Spring Cloud Angel/Brixton/Camden中,Feign默认都是开启Hystrix的。无需设置该属性。 -------------------------------------------------------------------------------- /microservice-consumer-movie-feign-hystrix-fallback/src/main/java/com/itmuch/cloud/study/ConsumerMovieApplication.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 | import org.springframework.cloud.netflix.feign.EnableFeignClients; 7 | 8 | @EnableDiscoveryClient 9 | @SpringBootApplication 10 | @EnableFeignClients 11 | public class ConsumerMovieApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(ConsumerMovieApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /microservice-consumer-movie-feign-hystrix-fallback/src/main/java/com/itmuch/cloud/study/user/controller/MovieController.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.feign.UserFeignClient; 10 | 11 | @RestController 12 | public class MovieController { 13 | @Autowired 14 | private UserFeignClient userFeignClient; 15 | 16 | @GetMapping("/user/{id}") 17 | public User findById(@PathVariable Long id) { 18 | return this.userFeignClient.findById(id); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /microservice-consumer-movie-feign-hystrix-fallback/src/main/java/com/itmuch/cloud/study/user/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.user.entity; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class User { 6 | private Long id; 7 | private String username; 8 | private String name; 9 | private Integer age; 10 | private BigDecimal balance; 11 | 12 | public Long getId() { 13 | return this.id; 14 | } 15 | 16 | public void setId(Long id) { 17 | this.id = id; 18 | } 19 | 20 | public String getUsername() { 21 | return this.username; 22 | } 23 | 24 | public void setUsername(String username) { 25 | this.username = username; 26 | } 27 | 28 | public String getName() { 29 | return this.name; 30 | } 31 | 32 | public void setName(String name) { 33 | this.name = name; 34 | } 35 | 36 | public Integer getAge() { 37 | return this.age; 38 | } 39 | 40 | public void setAge(Integer age) { 41 | this.age = age; 42 | } 43 | 44 | public BigDecimal getBalance() { 45 | return this.balance; 46 | } 47 | 48 | public void setBalance(BigDecimal balance) { 49 | this.balance = balance; 50 | } 51 | } -------------------------------------------------------------------------------- /microservice-consumer-movie-feign-hystrix-fallback/src/main/java/com/itmuch/cloud/study/user/feign/UserFeignClient.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.user.feign; 2 | 3 | import org.springframework.cloud.netflix.feign.FeignClient; 4 | import org.springframework.stereotype.Component; 5 | import org.springframework.web.bind.annotation.PathVariable; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RequestMethod; 8 | 9 | import com.itmuch.cloud.study.user.entity.User; 10 | 11 | /** 12 | * Feign的fallback测试 13 | * 使用@FeignClient的fallback属性指定回退类 14 | * @author 周立 15 | */ 16 | @FeignClient(name = "microservice-provider-user", fallback = FeignClientFallback.class) 17 | public interface UserFeignClient { 18 | @RequestMapping(value = "/{id}", method = RequestMethod.GET) 19 | public User findById(@PathVariable("id") Long id); 20 | 21 | } 22 | 23 | /** 24 | * 回退类FeignClientFallback需实现Feign Client接口 25 | * FeignClientFallback也可以是public class,没有区别 26 | * @author 周立 27 | */ 28 | @Component 29 | class FeignClientFallback implements UserFeignClient { 30 | @Override 31 | public User findById(Long id) { 32 | User user = new User(); 33 | user.setId(-1L); 34 | user.setUsername("默认用户"); 35 | return user; 36 | } 37 | } -------------------------------------------------------------------------------- /microservice-consumer-movie-feign-hystrix-fallback/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8010 3 | spring: 4 | application: 5 | name: microservice-consumer-movie 6 | eureka: 7 | client: 8 | serviceUrl: 9 | defaultZone: http://localhost:8761/eureka/ 10 | instance: 11 | prefer-ip-address: true 12 | 13 | 14 | # 说明:请务必注意,在Spring Cloud Dalston中,Feign默认是不开启Hystrix的。 15 | # 因此,如使用Dalston请务必额外设置属性:feign.hystrix.enabled=true,否则断路器不会生效。 16 | # 而,Spring Cloud Angel/Brixton/Camden中,Feign默认都是开启Hystrix的。无需设置该属性。 -------------------------------------------------------------------------------- /microservice-consumer-movie-feign-logging/src/main/java/com/itmuch/cloud/config/FeignLogConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | import feign.Logger; 7 | 8 | @Configuration 9 | public class FeignLogConfiguration { 10 | @Bean 11 | Logger.Level feignLoggerLevel() { 12 | return Logger.Level.BASIC; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /microservice-consumer-movie-feign-logging/src/main/java/com/itmuch/cloud/study/ConsumerMovieApplication.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 | import org.springframework.cloud.netflix.feign.EnableFeignClients; 7 | 8 | @EnableDiscoveryClient 9 | @SpringBootApplication 10 | @EnableFeignClients 11 | public class ConsumerMovieApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(ConsumerMovieApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /microservice-consumer-movie-feign-logging/src/main/java/com/itmuch/cloud/study/user/controller/MovieController.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.feign.UserFeignClient; 10 | 11 | @RestController 12 | public class MovieController { 13 | @Autowired 14 | private UserFeignClient userFeignClient; 15 | 16 | @GetMapping("/user/{id}") 17 | public User findById(@PathVariable Long id) { 18 | return this.userFeignClient.findById(id); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /microservice-consumer-movie-feign-logging/src/main/java/com/itmuch/cloud/study/user/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.user.entity; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class User { 6 | private Long id; 7 | private String username; 8 | private String name; 9 | private Integer age; 10 | private BigDecimal balance; 11 | 12 | public Long getId() { 13 | return this.id; 14 | } 15 | 16 | public void setId(Long id) { 17 | this.id = id; 18 | } 19 | 20 | public String getUsername() { 21 | return this.username; 22 | } 23 | 24 | public void setUsername(String username) { 25 | this.username = username; 26 | } 27 | 28 | public String getName() { 29 | return this.name; 30 | } 31 | 32 | public void setName(String name) { 33 | this.name = name; 34 | } 35 | 36 | public Integer getAge() { 37 | return this.age; 38 | } 39 | 40 | public void setAge(Integer age) { 41 | this.age = age; 42 | } 43 | 44 | public BigDecimal getBalance() { 45 | return this.balance; 46 | } 47 | 48 | public void setBalance(BigDecimal balance) { 49 | this.balance = balance; 50 | } 51 | } -------------------------------------------------------------------------------- /microservice-consumer-movie-feign-logging/src/main/java/com/itmuch/cloud/study/user/feign/UserFeignClient.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.user.feign; 2 | 3 | import org.springframework.cloud.netflix.feign.FeignClient; 4 | import org.springframework.web.bind.annotation.PathVariable; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RequestMethod; 7 | 8 | import com.itmuch.cloud.config.FeignLogConfiguration; 9 | import com.itmuch.cloud.study.user.entity.User; 10 | 11 | @FeignClient(name = "microservice-provider-user", configuration = FeignLogConfiguration.class) 12 | public interface UserFeignClient { 13 | @RequestMapping(value = "/{id}", method = RequestMethod.GET) 14 | public User findById(@PathVariable("id") Long id); 15 | } 16 | -------------------------------------------------------------------------------- /microservice-consumer-movie-feign-logging/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8010 3 | spring: 4 | application: 5 | name: microservice-consumer-movie 6 | eureka: 7 | client: 8 | serviceUrl: 9 | defaultZone: http://localhost:8761/eureka/ 10 | instance: 11 | prefer-ip-address: true 12 | logging: 13 | level: 14 | com.itmuch.cloud.study.user.feign.UserFeignClient: DEBUG # 将Feign接口的日志级别设置成DEBUG,因为Feign的Logger.Level只对DEBUG作出响应。 -------------------------------------------------------------------------------- /microservice-consumer-movie-feign-manual/src/main/java/com/itmuch/cloud/study/ConsumerMovieApplication.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 | @EnableDiscoveryClient 8 | @SpringBootApplication 9 | public class ConsumerMovieApplication { 10 | public static void main(String[] args) { 11 | SpringApplication.run(ConsumerMovieApplication.class, args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /microservice-consumer-movie-feign-manual/src/main/java/com/itmuch/cloud/study/user/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.user.entity; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class User { 6 | private Long id; 7 | private String username; 8 | private String name; 9 | private Integer age; 10 | private BigDecimal balance; 11 | 12 | public Long getId() { 13 | return this.id; 14 | } 15 | 16 | public void setId(Long id) { 17 | this.id = id; 18 | } 19 | 20 | public String getUsername() { 21 | return this.username; 22 | } 23 | 24 | public void setUsername(String username) { 25 | this.username = username; 26 | } 27 | 28 | public String getName() { 29 | return this.name; 30 | } 31 | 32 | public void setName(String name) { 33 | this.name = name; 34 | } 35 | 36 | public Integer getAge() { 37 | return this.age; 38 | } 39 | 40 | public void setAge(Integer age) { 41 | this.age = age; 42 | } 43 | 44 | public BigDecimal getBalance() { 45 | return this.balance; 46 | } 47 | 48 | public void setBalance(BigDecimal balance) { 49 | this.balance = balance; 50 | } 51 | } -------------------------------------------------------------------------------- /microservice-consumer-movie-feign-manual/src/main/java/com/itmuch/cloud/study/user/feign/UserFeignClient.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.user.feign; 2 | 3 | import org.springframework.web.bind.annotation.PathVariable; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RequestMethod; 6 | 7 | import com.itmuch.cloud.study.user.entity.User; 8 | 9 | public interface UserFeignClient { 10 | @RequestMapping(value = "/{id}", method = RequestMethod.GET) 11 | public User findById(@PathVariable("id") Long id); 12 | } 13 | -------------------------------------------------------------------------------- /microservice-consumer-movie-feign-manual/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8010 3 | spring: 4 | application: 5 | name: microservice-consumer-movie 6 | eureka: 7 | client: 8 | serviceUrl: 9 | defaultZone: http://localhost:8761/eureka/ 10 | instance: 11 | prefer-ip-address: true -------------------------------------------------------------------------------- /microservice-consumer-movie-feign-multiple-params/src/main/java/com/itmuch/cloud/study/ConsumerMovieApplication.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 | import org.springframework.cloud.netflix.feign.EnableFeignClients; 7 | 8 | @EnableDiscoveryClient 9 | @SpringBootApplication 10 | @EnableFeignClients 11 | public class ConsumerMovieApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(ConsumerMovieApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /microservice-consumer-movie-feign-multiple-params/src/main/java/com/itmuch/cloud/study/user/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.user.entity; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class User { 6 | private Long id; 7 | private String username; 8 | private String name; 9 | private Integer age; 10 | private BigDecimal balance; 11 | 12 | public Long getId() { 13 | return this.id; 14 | } 15 | 16 | public void setId(Long id) { 17 | this.id = id; 18 | } 19 | 20 | public String getUsername() { 21 | return this.username; 22 | } 23 | 24 | public void setUsername(String username) { 25 | this.username = username; 26 | } 27 | 28 | public String getName() { 29 | return this.name; 30 | } 31 | 32 | public void setName(String name) { 33 | this.name = name; 34 | } 35 | 36 | public Integer getAge() { 37 | return this.age; 38 | } 39 | 40 | public void setAge(Integer age) { 41 | this.age = age; 42 | } 43 | 44 | public BigDecimal getBalance() { 45 | return this.balance; 46 | } 47 | 48 | public void setBalance(BigDecimal balance) { 49 | this.balance = balance; 50 | } 51 | } -------------------------------------------------------------------------------- /microservice-consumer-movie-feign-multiple-params/src/main/java/com/itmuch/cloud/study/user/feign/UserFeignClient.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.user.feign; 2 | 3 | import com.itmuch.cloud.study.user.entity.User; 4 | import org.springframework.cloud.netflix.feign.FeignClient; 5 | import org.springframework.web.bind.annotation.*; 6 | 7 | import java.util.Map; 8 | 9 | @FeignClient(name = "microservice-provider-user") 10 | public interface UserFeignClient { 11 | @RequestMapping(value = "/{id}", method = RequestMethod.GET) 12 | public User findById(@PathVariable("id") Long id); 13 | 14 | // 该请求不会成功 15 | @RequestMapping(value = "/get", method = RequestMethod.GET) 16 | public User get0(User user); 17 | 18 | @RequestMapping(value = "/get", method = RequestMethod.GET) 19 | public User get1(@RequestParam("id") Long id, @RequestParam("username") String username); 20 | 21 | @RequestMapping(value = "/get", method = RequestMethod.GET) 22 | public User get2(@RequestParam Map map); 23 | 24 | @RequestMapping(value = "/post", method = RequestMethod.POST) 25 | public User post(@RequestBody User user); 26 | } 27 | -------------------------------------------------------------------------------- /microservice-consumer-movie-feign-multiple-params/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8010 3 | spring: 4 | application: 5 | name: microservice-consumer-movie 6 | eureka: 7 | client: 8 | serviceUrl: 9 | defaultZone: http://localhost:8761/eureka/ 10 | instance: 11 | prefer-ip-address: true -------------------------------------------------------------------------------- /microservice-consumer-movie-feign/src/main/java/com/itmuch/cloud/study/ConsumerMovieApplication.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 | import org.springframework.cloud.netflix.feign.EnableFeignClients; 7 | 8 | @EnableDiscoveryClient 9 | @SpringBootApplication 10 | @EnableFeignClients 11 | public class ConsumerMovieApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(ConsumerMovieApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /microservice-consumer-movie-feign/src/main/java/com/itmuch/cloud/study/user/controller/MovieController.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.feign.UserFeignClient; 10 | 11 | @RestController 12 | public class MovieController { 13 | @Autowired 14 | private UserFeignClient userFeignClient; 15 | 16 | @GetMapping("/user/{id}") 17 | public User findById(@PathVariable Long id) { 18 | return this.userFeignClient.findById(id); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /microservice-consumer-movie-feign/src/main/java/com/itmuch/cloud/study/user/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.user.entity; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class User { 6 | private Long id; 7 | private String username; 8 | private String name; 9 | private Integer age; 10 | private BigDecimal balance; 11 | 12 | public Long getId() { 13 | return this.id; 14 | } 15 | 16 | public void setId(Long id) { 17 | this.id = id; 18 | } 19 | 20 | public String getUsername() { 21 | return this.username; 22 | } 23 | 24 | public void setUsername(String username) { 25 | this.username = username; 26 | } 27 | 28 | public String getName() { 29 | return this.name; 30 | } 31 | 32 | public void setName(String name) { 33 | this.name = name; 34 | } 35 | 36 | public Integer getAge() { 37 | return this.age; 38 | } 39 | 40 | public void setAge(Integer age) { 41 | this.age = age; 42 | } 43 | 44 | public BigDecimal getBalance() { 45 | return this.balance; 46 | } 47 | 48 | public void setBalance(BigDecimal balance) { 49 | this.balance = balance; 50 | } 51 | } -------------------------------------------------------------------------------- /microservice-consumer-movie-feign/src/main/java/com/itmuch/cloud/study/user/feign/UserFeignClient.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.user.feign; 2 | 3 | import org.springframework.cloud.netflix.feign.FeignClient; 4 | import org.springframework.web.bind.annotation.PathVariable; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RequestMethod; 7 | 8 | import com.itmuch.cloud.study.user.entity.User; 9 | 10 | @FeignClient(name = "microservice-provider-user") 11 | public interface UserFeignClient { 12 | @RequestMapping(value = "/{id}", method = RequestMethod.GET) 13 | public User findById(@PathVariable("id") Long id); 14 | } 15 | -------------------------------------------------------------------------------- /microservice-consumer-movie-feign/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8010 3 | spring: 4 | application: 5 | name: microservice-consumer-movie 6 | eureka: 7 | client: 8 | serviceUrl: 9 | defaultZone: http://localhost:8761/eureka/ 10 | instance: 11 | prefer-ip-address: true -------------------------------------------------------------------------------- /microservice-consumer-movie-ribbon-customizing-properties/src/main/java/com/itmuch/cloud/study/ConsumerMovieApplication.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 | import org.springframework.cloud.client.loadbalancer.LoadBalanced; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.web.client.RestTemplate; 9 | 10 | @EnableDiscoveryClient 11 | @SpringBootApplication 12 | public class ConsumerMovieApplication { 13 | @Bean 14 | @LoadBalanced 15 | public RestTemplate restTemplate() { 16 | return new RestTemplate(); 17 | } 18 | 19 | public static void main(String[] args) { 20 | SpringApplication.run(ConsumerMovieApplication.class, args); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /microservice-consumer-movie-ribbon-customizing-properties/src/main/java/com/itmuch/cloud/study/user/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.user.entity; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class User { 6 | private Long id; 7 | private String username; 8 | private String name; 9 | private Integer age; 10 | private BigDecimal balance; 11 | 12 | public Long getId() { 13 | return this.id; 14 | } 15 | 16 | public void setId(Long id) { 17 | this.id = id; 18 | } 19 | 20 | public String getUsername() { 21 | return this.username; 22 | } 23 | 24 | public void setUsername(String username) { 25 | this.username = username; 26 | } 27 | 28 | public String getName() { 29 | return this.name; 30 | } 31 | 32 | public void setName(String name) { 33 | this.name = name; 34 | } 35 | 36 | public Integer getAge() { 37 | return this.age; 38 | } 39 | 40 | public void setAge(Integer age) { 41 | this.age = age; 42 | } 43 | 44 | public BigDecimal getBalance() { 45 | return this.balance; 46 | } 47 | 48 | public void setBalance(BigDecimal balance) { 49 | this.balance = balance; 50 | } 51 | } -------------------------------------------------------------------------------- /microservice-consumer-movie-ribbon-customizing-properties/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8010 3 | spring: 4 | application: 5 | name: microservice-consumer-movie 6 | eureka: 7 | client: 8 | serviceUrl: 9 | defaultZone: http://localhost:8761/eureka/ 10 | instance: 11 | prefer-ip-address: true 12 | 13 | microservice-provider-user: 14 | ribbon: 15 | NFLoadBalancerRuleClassName: com.netflix.loadbalancer.RandomRule -------------------------------------------------------------------------------- /microservice-consumer-movie-ribbon-customizing/src/main/java/com/itmuch/cloud/config/RibbonConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | import com.netflix.loadbalancer.IRule; 7 | import com.netflix.loadbalancer.RandomRule; 8 | 9 | /** 10 | * 该类为Ribbon的配置类 11 | * 注意:该类不应该在主应用程序上下文的@ComponentScan 中。 12 | * @author 周立 13 | */ 14 | @Configuration 15 | public class RibbonConfiguration { 16 | @Bean 17 | public IRule ribbonRule() { 18 | // 负载均衡规则,改为随机 19 | return new RandomRule(); 20 | } 21 | } -------------------------------------------------------------------------------- /microservice-consumer-movie-ribbon-customizing/src/main/java/com/itmuch/cloud/study/ConsumerMovieApplication.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 | import org.springframework.cloud.client.loadbalancer.LoadBalanced; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.web.client.RestTemplate; 9 | 10 | @EnableDiscoveryClient 11 | @SpringBootApplication 12 | public class ConsumerMovieApplication { 13 | @Bean 14 | @LoadBalanced 15 | public RestTemplate restTemplate() { 16 | return new RestTemplate(); 17 | } 18 | 19 | public static void main(String[] args) { 20 | SpringApplication.run(ConsumerMovieApplication.class, args); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /microservice-consumer-movie-ribbon-customizing/src/main/java/com/itmuch/cloud/study/config/TestConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.config; 2 | 3 | import org.springframework.cloud.netflix.ribbon.RibbonClient; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | import com.itmuch.cloud.config.RibbonConfiguration; 7 | 8 | /** 9 | * 使用RibbonClient,为特定name的Ribbon Client自定义配置. 10 | * 使用@RibbonClient的configuration属性,指定Ribbon的配置类. 11 | * 可参考的示例: 12 | * http://spring.io/guides/gs/client-side-load-balancing/ 13 | * @author 周立 14 | */ 15 | @Configuration 16 | @RibbonClient(name = "microservice-provider-user", configuration = RibbonConfiguration.class) 17 | public class TestConfiguration { 18 | } -------------------------------------------------------------------------------- /microservice-consumer-movie-ribbon-customizing/src/main/java/com/itmuch/cloud/study/user/controller/MovieController.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.user.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.cloud.client.ServiceInstance; 7 | import org.springframework.cloud.client.loadbalancer.LoadBalancerClient; 8 | import org.springframework.web.bind.annotation.GetMapping; 9 | import org.springframework.web.bind.annotation.PathVariable; 10 | import org.springframework.web.bind.annotation.RestController; 11 | import org.springframework.web.client.RestTemplate; 12 | 13 | import com.itmuch.cloud.study.user.entity.User; 14 | 15 | @RestController 16 | public class MovieController { 17 | private static final Logger LOGGER = LoggerFactory.getLogger(MovieController.class); 18 | @Autowired 19 | private RestTemplate restTemplate; 20 | @Autowired 21 | private LoadBalancerClient loadBalancerClient; 22 | 23 | @GetMapping("/user/{id}") 24 | public User findById(@PathVariable Long id) { 25 | return this.restTemplate.getForObject("http://microservice-provider-user/" + id, User.class); 26 | } 27 | 28 | @GetMapping("/log-user-instance") 29 | public void logUserInstance() { 30 | ServiceInstance serviceInstance = this.loadBalancerClient.choose("microservice-provider-user"); 31 | // 打印当前选择的是哪个节点 32 | MovieController.LOGGER.info("{}:{}:{}", serviceInstance.getServiceId(), serviceInstance.getHost(), serviceInstance.getPort()); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /microservice-consumer-movie-ribbon-customizing/src/main/java/com/itmuch/cloud/study/user/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.user.entity; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class User { 6 | private Long id; 7 | private String username; 8 | private String name; 9 | private Integer age; 10 | private BigDecimal balance; 11 | 12 | public Long getId() { 13 | return this.id; 14 | } 15 | 16 | public void setId(Long id) { 17 | this.id = id; 18 | } 19 | 20 | public String getUsername() { 21 | return this.username; 22 | } 23 | 24 | public void setUsername(String username) { 25 | this.username = username; 26 | } 27 | 28 | public String getName() { 29 | return this.name; 30 | } 31 | 32 | public void setName(String name) { 33 | this.name = name; 34 | } 35 | 36 | public Integer getAge() { 37 | return this.age; 38 | } 39 | 40 | public void setAge(Integer age) { 41 | this.age = age; 42 | } 43 | 44 | public BigDecimal getBalance() { 45 | return this.balance; 46 | } 47 | 48 | public void setBalance(BigDecimal balance) { 49 | this.balance = balance; 50 | } 51 | } -------------------------------------------------------------------------------- /microservice-consumer-movie-ribbon-customizing/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8010 3 | spring: 4 | application: 5 | name: microservice-consumer-movie 6 | eureka: 7 | client: 8 | serviceUrl: 9 | defaultZone: http://localhost:8761/eureka/ 10 | instance: 11 | prefer-ip-address: true -------------------------------------------------------------------------------- /microservice-consumer-movie-ribbon-hystrix-turbine-mq/src/main/java/com/itmuch/cloud/study/ConsumerMovieApplication.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 | @EnableDiscoveryClient 12 | @SpringBootApplication 13 | @EnableCircuitBreaker 14 | public class ConsumerMovieApplication { 15 | @Bean 16 | @LoadBalanced 17 | public RestTemplate restTemplate() { 18 | return new RestTemplate(); 19 | } 20 | 21 | public static void main(String[] args) { 22 | SpringApplication.run(ConsumerMovieApplication.class, args); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /microservice-consumer-movie-ribbon-hystrix-turbine-mq/src/main/java/com/itmuch/cloud/study/user/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.user.entity; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class User { 6 | private Long id; 7 | private String username; 8 | private String name; 9 | private Integer age; 10 | private BigDecimal balance; 11 | 12 | public Long getId() { 13 | return this.id; 14 | } 15 | 16 | public void setId(Long id) { 17 | this.id = id; 18 | } 19 | 20 | public String getUsername() { 21 | return this.username; 22 | } 23 | 24 | public void setUsername(String username) { 25 | this.username = username; 26 | } 27 | 28 | public String getName() { 29 | return this.name; 30 | } 31 | 32 | public void setName(String name) { 33 | this.name = name; 34 | } 35 | 36 | public Integer getAge() { 37 | return this.age; 38 | } 39 | 40 | public void setAge(Integer age) { 41 | this.age = age; 42 | } 43 | 44 | public BigDecimal getBalance() { 45 | return this.balance; 46 | } 47 | 48 | public void setBalance(BigDecimal balance) { 49 | this.balance = balance; 50 | } 51 | } -------------------------------------------------------------------------------- /microservice-consumer-movie-ribbon-hystrix-turbine-mq/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8010 3 | spring: 4 | application: 5 | name: microservice-consumer-movie 6 | rabbitmq: 7 | host: localhost 8 | port: 5672 9 | username: guest 10 | password: guest 11 | eureka: 12 | client: 13 | serviceUrl: 14 | defaultZone: http://localhost:8761/eureka/ 15 | instance: 16 | prefer-ip-address: true 17 | -------------------------------------------------------------------------------- /microservice-consumer-movie-ribbon-hystrix/src/main/java/com/itmuch/cloud/study/ConsumerMovieApplication.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 | @EnableDiscoveryClient 12 | @SpringBootApplication 13 | @EnableCircuitBreaker 14 | public class ConsumerMovieApplication { 15 | @Bean 16 | @LoadBalanced 17 | public RestTemplate restTemplate() { 18 | return new RestTemplate(); 19 | } 20 | 21 | public static void main(String[] args) { 22 | SpringApplication.run(ConsumerMovieApplication.class, args); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /microservice-consumer-movie-ribbon-hystrix/src/main/java/com/itmuch/cloud/study/user/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.user.entity; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class User { 6 | private Long id; 7 | private String username; 8 | private String name; 9 | private Integer age; 10 | private BigDecimal balance; 11 | 12 | public Long getId() { 13 | return this.id; 14 | } 15 | 16 | public void setId(Long id) { 17 | this.id = id; 18 | } 19 | 20 | public String getUsername() { 21 | return this.username; 22 | } 23 | 24 | public void setUsername(String username) { 25 | this.username = username; 26 | } 27 | 28 | public String getName() { 29 | return this.name; 30 | } 31 | 32 | public void setName(String name) { 33 | this.name = name; 34 | } 35 | 36 | public Integer getAge() { 37 | return this.age; 38 | } 39 | 40 | public void setAge(Integer age) { 41 | this.age = age; 42 | } 43 | 44 | public BigDecimal getBalance() { 45 | return this.balance; 46 | } 47 | 48 | public void setBalance(BigDecimal balance) { 49 | this.balance = balance; 50 | } 51 | } -------------------------------------------------------------------------------- /microservice-consumer-movie-ribbon-hystrix/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8010 3 | spring: 4 | application: 5 | name: microservice-consumer-movie 6 | eureka: 7 | client: 8 | serviceUrl: 9 | defaultZone: http://localhost:8761/eureka/ 10 | instance: 11 | prefer-ip-address: true -------------------------------------------------------------------------------- /microservice-consumer-movie-ribbon/src/main/java/com/itmuch/cloud/study/ConsumerMovieApplication.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 | import org.springframework.cloud.client.loadbalancer.LoadBalanced; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.web.client.RestTemplate; 9 | 10 | @EnableDiscoveryClient 11 | @SpringBootApplication 12 | public class ConsumerMovieApplication { 13 | @Bean 14 | @LoadBalanced 15 | public RestTemplate restTemplate() { 16 | return new RestTemplate(); 17 | } 18 | 19 | public static void main(String[] args) { 20 | SpringApplication.run(ConsumerMovieApplication.class, args); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /microservice-consumer-movie-ribbon/src/main/java/com/itmuch/cloud/study/user/controller/MovieController.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.user.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.cloud.client.ServiceInstance; 7 | import org.springframework.cloud.client.loadbalancer.LoadBalancerClient; 8 | import org.springframework.web.bind.annotation.GetMapping; 9 | import org.springframework.web.bind.annotation.PathVariable; 10 | import org.springframework.web.bind.annotation.RestController; 11 | import org.springframework.web.client.RestTemplate; 12 | 13 | import com.itmuch.cloud.study.user.entity.User; 14 | 15 | @RestController 16 | public class MovieController { 17 | private static final Logger LOGGER = LoggerFactory.getLogger(MovieController.class); 18 | @Autowired 19 | private RestTemplate restTemplate; 20 | @Autowired 21 | private LoadBalancerClient loadBalancerClient; 22 | 23 | @GetMapping("/user/{id}") 24 | public User findById(@PathVariable Long id) { 25 | return this.restTemplate.getForObject("http://microservice-provider-user/" + id, User.class); 26 | } 27 | 28 | @GetMapping("/log-user-instance") 29 | public void logUserInstance() { 30 | ServiceInstance serviceInstance = this.loadBalancerClient.choose("microservice-provider-user"); 31 | // 打印当前选择的是哪个节点 32 | MovieController.LOGGER.info("{}:{}:{}", serviceInstance.getServiceId(), serviceInstance.getHost(), serviceInstance.getPort()); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /microservice-consumer-movie-ribbon/src/main/java/com/itmuch/cloud/study/user/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.user.entity; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class User { 6 | private Long id; 7 | private String username; 8 | private String name; 9 | private Integer age; 10 | private BigDecimal balance; 11 | 12 | public Long getId() { 13 | return this.id; 14 | } 15 | 16 | public void setId(Long id) { 17 | this.id = id; 18 | } 19 | 20 | public String getUsername() { 21 | return this.username; 22 | } 23 | 24 | public void setUsername(String username) { 25 | this.username = username; 26 | } 27 | 28 | public String getName() { 29 | return this.name; 30 | } 31 | 32 | public void setName(String name) { 33 | this.name = name; 34 | } 35 | 36 | public Integer getAge() { 37 | return this.age; 38 | } 39 | 40 | public void setAge(Integer age) { 41 | this.age = age; 42 | } 43 | 44 | public BigDecimal getBalance() { 45 | return this.balance; 46 | } 47 | 48 | public void setBalance(BigDecimal balance) { 49 | this.balance = balance; 50 | } 51 | } -------------------------------------------------------------------------------- /microservice-consumer-movie-ribbon/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8010 3 | spring: 4 | application: 5 | name: microservice-consumer-movie 6 | eureka: 7 | client: 8 | serviceUrl: 9 | defaultZone: http://localhost:8761/eureka/ 10 | instance: 11 | prefer-ip-address: true -------------------------------------------------------------------------------- /microservice-consumer-movie-understanding-metadata/src/main/java/com/itmuch/cloud/study/ConsumerMovieApplication.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 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.web.client.RestTemplate; 8 | 9 | @EnableDiscoveryClient 10 | @SpringBootApplication 11 | public class ConsumerMovieApplication { 12 | @Bean 13 | public RestTemplate restTemplate() { 14 | return new RestTemplate(); 15 | } 16 | 17 | public static void main(String[] args) { 18 | SpringApplication.run(ConsumerMovieApplication.class, args); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /microservice-consumer-movie-understanding-metadata/src/main/java/com/itmuch/cloud/study/user/controller/MovieController.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.user.controller; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.cloud.client.ServiceInstance; 7 | import org.springframework.cloud.client.discovery.DiscoveryClient; 8 | import org.springframework.web.bind.annotation.GetMapping; 9 | import org.springframework.web.bind.annotation.PathVariable; 10 | import org.springframework.web.bind.annotation.RestController; 11 | import org.springframework.web.client.RestTemplate; 12 | 13 | import com.itmuch.cloud.study.user.entity.User; 14 | 15 | @RestController 16 | public class MovieController { 17 | @Autowired 18 | private RestTemplate restTemplate; 19 | 20 | @Autowired 21 | private DiscoveryClient discoveryClient; 22 | 23 | @GetMapping("/user/{id}") 24 | public User findById(@PathVariable Long id) { 25 | return this.restTemplate.getForObject("http://localhost:8000/" + id, User.class); 26 | } 27 | 28 | /** 29 | * 查询microservice-provider-user服务的信息并返回 30 | * @return microservice-provider-user服务的信息 31 | */ 32 | @GetMapping("/user-instance") 33 | public List showInfo() { 34 | return this.discoveryClient.getInstances("microservice-provider-user"); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /microservice-consumer-movie-understanding-metadata/src/main/java/com/itmuch/cloud/study/user/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.user.entity; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class User { 6 | private Long id; 7 | private String username; 8 | private String name; 9 | private Integer age; 10 | private BigDecimal balance; 11 | 12 | public Long getId() { 13 | return this.id; 14 | } 15 | 16 | public void setId(Long id) { 17 | this.id = id; 18 | } 19 | 20 | public String getUsername() { 21 | return this.username; 22 | } 23 | 24 | public void setUsername(String username) { 25 | this.username = username; 26 | } 27 | 28 | public String getName() { 29 | return this.name; 30 | } 31 | 32 | public void setName(String name) { 33 | this.name = name; 34 | } 35 | 36 | public Integer getAge() { 37 | return this.age; 38 | } 39 | 40 | public void setAge(Integer age) { 41 | this.age = age; 42 | } 43 | 44 | public BigDecimal getBalance() { 45 | return this.balance; 46 | } 47 | 48 | public void setBalance(BigDecimal balance) { 49 | this.balance = balance; 50 | } 51 | } -------------------------------------------------------------------------------- /microservice-consumer-movie-understanding-metadata/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8010 3 | spring: 4 | application: 5 | name: microservice-consumer-movie 6 | eureka: 7 | client: 8 | serviceUrl: 9 | defaultZone: http://localhost:8761/eureka/ 10 | instance: 11 | prefer-ip-address: true -------------------------------------------------------------------------------- /microservice-consumer-movie-without-eureka/src/main/java/com/itmuch/cloud/study/ConsumerMovieApplication.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.loadbalancer.LoadBalanced; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.web.client.RestTemplate; 8 | 9 | @SpringBootApplication 10 | public class ConsumerMovieApplication { 11 | @Bean 12 | @LoadBalanced 13 | public RestTemplate restTemplate() { 14 | return new RestTemplate(); 15 | } 16 | 17 | public static void main(String[] args) { 18 | SpringApplication.run(ConsumerMovieApplication.class, args); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /microservice-consumer-movie-without-eureka/src/main/java/com/itmuch/cloud/study/user/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.user.entity; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class User { 6 | private Long id; 7 | private String username; 8 | private String name; 9 | private Integer age; 10 | private BigDecimal balance; 11 | 12 | public Long getId() { 13 | return this.id; 14 | } 15 | 16 | public void setId(Long id) { 17 | this.id = id; 18 | } 19 | 20 | public String getUsername() { 21 | return this.username; 22 | } 23 | 24 | public void setUsername(String username) { 25 | this.username = username; 26 | } 27 | 28 | public String getName() { 29 | return this.name; 30 | } 31 | 32 | public void setName(String name) { 33 | this.name = name; 34 | } 35 | 36 | public Integer getAge() { 37 | return this.age; 38 | } 39 | 40 | public void setAge(Integer age) { 41 | this.age = age; 42 | } 43 | 44 | public BigDecimal getBalance() { 45 | return this.balance; 46 | } 47 | 48 | public void setBalance(BigDecimal balance) { 49 | this.balance = balance; 50 | } 51 | } -------------------------------------------------------------------------------- /microservice-consumer-movie-without-eureka/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8010 3 | spring: 4 | application: 5 | name: microservice-consumer-movie 6 | microservice-provider-user: 7 | ribbon: 8 | listOfServers: localhost:8000,localhost:8001 9 | -------------------------------------------------------------------------------- /microservice-consumer-movie/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /microservice-consumer-movie/.springBeans: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1 4 | 5 | 6 | 7 | 8 | 9 | 10 | java:com.itmuch.cloud.study.ConsumerMovieApplication 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /microservice-consumer-movie/src/main/java/com/itmuch/cloud/study/ConsumerMovieApplication.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 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.web.client.RestTemplate; 8 | 9 | @EnableDiscoveryClient 10 | @SpringBootApplication 11 | public class ConsumerMovieApplication { 12 | @Bean 13 | public RestTemplate restTemplate() { 14 | return new RestTemplate(); 15 | } 16 | 17 | public static void main(String[] args) { 18 | SpringApplication.run(ConsumerMovieApplication.class, args); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /microservice-consumer-movie/src/main/java/com/itmuch/cloud/study/user/controller/MovieController.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 | import org.springframework.web.client.RestTemplate; 8 | 9 | import com.itmuch.cloud.study.user.entity.User; 10 | 11 | @RestController 12 | public class MovieController { 13 | @Autowired 14 | private RestTemplate restTemplate; 15 | 16 | @GetMapping("/user/{id}") 17 | public User findById(@PathVariable Long id) { 18 | return this.restTemplate.getForObject("http://localhost:8000/" + id, User.class); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /microservice-consumer-movie/src/main/java/com/itmuch/cloud/study/user/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.user.entity; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class User { 6 | private Long id; 7 | private String username; 8 | private String name; 9 | private Integer age; 10 | private BigDecimal balance; 11 | 12 | public Long getId() { 13 | return this.id; 14 | } 15 | 16 | public void setId(Long id) { 17 | this.id = id; 18 | } 19 | 20 | public String getUsername() { 21 | return this.username; 22 | } 23 | 24 | public void setUsername(String username) { 25 | this.username = username; 26 | } 27 | 28 | public String getName() { 29 | return this.name; 30 | } 31 | 32 | public void setName(String name) { 33 | this.name = name; 34 | } 35 | 36 | public Integer getAge() { 37 | return this.age; 38 | } 39 | 40 | public void setAge(Integer age) { 41 | this.age = age; 42 | } 43 | 44 | public BigDecimal getBalance() { 45 | return this.balance; 46 | } 47 | 48 | public void setBalance(BigDecimal balance) { 49 | this.balance = balance; 50 | } 51 | } -------------------------------------------------------------------------------- /microservice-consumer-movie/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8010 3 | spring: 4 | application: 5 | name: microservice-consumer-movie 6 | eureka: 7 | client: 8 | serviceUrl: 9 | defaultZone: http://localhost:8761/eureka/ 10 | instance: 11 | prefer-ip-address: true -------------------------------------------------------------------------------- /microservice-discovery-eureka-authenticating/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 周立 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-discovery-eureka-authenticating/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | security: 2 | basic: 3 | enabled: true # 开启基于HTTP basic的认证 4 | user: 5 | name: user # 配置登录的账号是user 6 | password: password123 # 配置登录的密码是password123 7 | server: 8 | port: 8761 # 指定该Eureka实例的端口 9 | eureka: 10 | client: 11 | registerWithEureka: false 12 | fetchRegistry: false 13 | serviceUrl: 14 | defaultZone: http://localhost:8761/eureka/ 15 | 16 | # 参考文档:http://projects.spring.io/spring-cloud/docs/1.0.3/spring-cloud.html#_standalone_mode 17 | # 参考文档:http://my.oschina.net/buwei/blog/618756 -------------------------------------------------------------------------------- /microservice-discovery-eureka-ha/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 周立 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-discovery-eureka-ha/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: microservice-discovery-eureka-ha 4 | --- 5 | spring: 6 | profiles: peer1 # 指定profile=peer1 7 | server: 8 | port: 8761 9 | eureka: 10 | instance: 11 | hostname: peer1 # 指定当profile=peer1时,主机名是peer1 12 | client: 13 | serviceUrl: 14 | defaultZone: http://peer2:8762/eureka/ # 将自己注册到peer2这个Eureka上面去 15 | 16 | --- 17 | spring: 18 | profiles: peer2 19 | server: 20 | port: 8762 21 | eureka: 22 | instance: 23 | hostname: peer2 24 | client: 25 | serviceUrl: 26 | defaultZone: http://peer1:8761/eureka/ -------------------------------------------------------------------------------- /microservice-discovery-eureka/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /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 周立 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-discovery-eureka/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8761 # 指定该Eureka实例的端口 3 | eureka: 4 | client: 5 | registerWithEureka: false 6 | fetchRegistry: false 7 | serviceUrl: 8 | defaultZone: http://localhost:8761/eureka/ 9 | 10 | # 参考文档:http://projects.spring.io/spring-cloud/docs/1.0.3/spring-cloud.html#_standalone_mode 11 | # 参考文档:http://my.oschina.net/buwei/blog/618756 -------------------------------------------------------------------------------- /microservice-file-upload/src/main/java/com/itmuch/cloud/study/FileUploadApplication.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.EnableEurekaClient; 6 | 7 | @SpringBootApplication 8 | @EnableEurekaClient 9 | public class FileUploadApplication { 10 | public static void main(String[] args) { 11 | SpringApplication.run(FileUploadApplication.class, args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /microservice-file-upload/src/main/java/com/itmuch/cloud/study/controller/FileUploadController.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.controller; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | 6 | import org.springframework.stereotype.Controller; 7 | import org.springframework.util.FileCopyUtils; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RequestMethod; 10 | import org.springframework.web.bind.annotation.RequestParam; 11 | import org.springframework.web.bind.annotation.ResponseBody; 12 | import org.springframework.web.multipart.MultipartFile; 13 | 14 | @Controller 15 | public class FileUploadController { 16 | /** 17 | * 上传文件 18 | * 测试方法: 19 | * 有界面的测试:http://localhost:8050/index.html 20 | * 使用命令:curl -F "file=@文件全名" localhost:8050/upload 21 | * ps.该示例比较简单,没有做IO异常、文件大小、文件非空等处理 22 | * @param file 待上传的文件 23 | * @return 文件在服务器上的绝对路径 24 | * @throws IOException IO异常 25 | */ 26 | @RequestMapping(value = "/upload", method = RequestMethod.POST) 27 | public @ResponseBody String handleFileUpload(@RequestParam(value = "file", required = true) MultipartFile file) throws IOException { 28 | byte[] bytes = file.getBytes(); 29 | File fileToSave = new File(file.getOriginalFilename()); 30 | FileCopyUtils.copy(bytes, fileToSave); 31 | return fileToSave.getAbsolutePath(); 32 | } 33 | } -------------------------------------------------------------------------------- /microservice-file-upload/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8050 3 | eureka: 4 | client: 5 | serviceUrl: 6 | defaultZone: http://localhost:8761/eureka/ 7 | instance: 8 | prefer-ip-address: true 9 | spring: 10 | application: 11 | name: microservice-file-upload 12 | http: 13 | multipart: 14 | max-file-size: 2000Mb # Max file size,默认1M 15 | max-request-size: 2500Mb # Max request size,默认10M 16 | -------------------------------------------------------------------------------- /microservice-file-upload/src/main/resources/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 |
9 | File to upload: 10 | 11 | 12 |
13 | 14 | -------------------------------------------------------------------------------- /microservice-gateway-zuul-aggregation/src/main/java/com/itmuch/cloud/study/AggregationService.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study; 2 | 3 | import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Service; 6 | import org.springframework.web.client.RestTemplate; 7 | import rx.Observable; 8 | 9 | @Service 10 | public class AggregationService { 11 | @Autowired 12 | private RestTemplate restTemplate; 13 | 14 | @HystrixCommand(fallbackMethod = "fallback") 15 | public Observable getUserById(Long id) { 16 | // 创建一个被观察者 17 | return Observable.create(observer -> { 18 | // 请求用户微服务的/{id}端点 19 | User user = restTemplate.getForObject("http://microservice-provider-user/{id}", User.class, id); 20 | observer.onNext(user); 21 | observer.onCompleted(); 22 | }); 23 | } 24 | 25 | @HystrixCommand(fallbackMethod = "fallback") 26 | public Observable getMovieUserByUserId(Long id) { 27 | return Observable.create(observer -> { 28 | // 请求电影微服务的/user/{id}端点 29 | User movieUser = restTemplate.getForObject("http://microservice-consumer-movie/user/{id}", User.class, id); 30 | observer.onNext(movieUser); 31 | observer.onCompleted(); 32 | }); 33 | } 34 | 35 | public User fallback(Long id) { 36 | User user = new User(); 37 | user.setId(-1L); 38 | return user; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /microservice-gateway-zuul-aggregation/src/main/java/com/itmuch/cloud/study/User.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class User { 6 | private Long id; 7 | private String username; 8 | private String name; 9 | private Integer age; 10 | private BigDecimal balance; 11 | 12 | public Long getId() { 13 | return id; 14 | } 15 | 16 | public void setId(Long id) { 17 | this.id = id; 18 | } 19 | 20 | public String getUsername() { 21 | return username; 22 | } 23 | 24 | public void setUsername(String username) { 25 | this.username = username; 26 | } 27 | 28 | public String getName() { 29 | return name; 30 | } 31 | 32 | public void setName(String name) { 33 | this.name = name; 34 | } 35 | 36 | public Integer getAge() { 37 | return age; 38 | } 39 | 40 | public void setAge(Integer age) { 41 | this.age = age; 42 | } 43 | 44 | public BigDecimal getBalance() { 45 | return balance; 46 | } 47 | 48 | public void setBalance(BigDecimal balance) { 49 | this.balance = balance; 50 | } 51 | } -------------------------------------------------------------------------------- /microservice-gateway-zuul-aggregation/src/main/java/com/itmuch/cloud/study/ZuulApplication.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.loadbalancer.LoadBalanced; 6 | import org.springframework.cloud.netflix.zuul.EnableZuulProxy; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.web.client.RestTemplate; 9 | 10 | @SpringBootApplication 11 | @EnableZuulProxy 12 | public class ZuulApplication { 13 | public static void main(String[] args) { 14 | SpringApplication.run(ZuulApplication.class, args); 15 | } 16 | 17 | @Bean 18 | @LoadBalanced 19 | public RestTemplate restTemplate() { 20 | return new RestTemplate(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /microservice-gateway-zuul-aggregation/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8040 3 | spring: 4 | application: 5 | name: microservice-gateway-zuul 6 | eureka: 7 | client: 8 | service-url: 9 | defaultZone: http://localhost:8761/eureka/ 10 | instance: 11 | prefer-ip-address: true -------------------------------------------------------------------------------- /microservice-gateway-zuul-fallback/src/main/java/com/itmuch/cloud/study/ZuulApplication.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 | @SpringBootApplication 8 | @EnableZuulProxy 9 | public class ZuulApplication { 10 | public static void main(String[] args) { 11 | SpringApplication.run(ZuulApplication.class, args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /microservice-gateway-zuul-fallback/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8040 3 | spring: 4 | application: 5 | name: microservice-gateway-zuul 6 | eureka: 7 | client: 8 | service-url: 9 | defaultZone: http://localhost:8761/eureka/ 10 | instance: 11 | prefer-ip-address: true -------------------------------------------------------------------------------- /microservice-gateway-zuul-file-upload/src/main/java/com/itmuch/cloud/study/ZuulApplication.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 | @SpringBootApplication 8 | @EnableZuulProxy 9 | public class ZuulApplication { 10 | public static void main(String[] args) { 11 | SpringApplication.run(ZuulApplication.class, args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /microservice-gateway-zuul-file-upload/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8040 3 | spring: 4 | application: 5 | name: microservice-gateway-zuul 6 | eureka: 7 | client: 8 | service-url: 9 | defaultZone: http://localhost:8761/eureka/ 10 | instance: 11 | prefer-ip-address: true 12 | # 上传大文件得将超时时间设置长一些,否则会报超时异常。以下几行超时设置来自http://cloud.spring.io/spring-cloud-static/Camden.SR3/#_uploading_files_through_zuul 13 | hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 60000 14 | ribbon: 15 | ConnectTimeout: 3000 16 | ReadTimeout: 60000 -------------------------------------------------------------------------------- /microservice-gateway-zuul-filter-groovy/src/main/filters/post/ResponseFilter.groovy: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.post 2 | 3 | import org.slf4j.LoggerFactory 4 | 5 | import com.netflix.zuul.ZuulFilter 6 | import com.netflix.zuul.context.RequestContext 7 | 8 | class ResponseFilter extends ZuulFilter{ 9 | @Override 10 | String filterType() { 11 | return "post" 12 | } 13 | 14 | @Override 15 | int filterOrder() { 16 | return 2000 17 | } 18 | 19 | @Override 20 | boolean shouldFilter() { 21 | return true 22 | } 23 | 24 | @Override 25 | Object run() { 26 | print ("response code is : " + RequestContext.currentContext().response().status()); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /microservice-gateway-zuul-filter-groovy/src/main/filters/pre/PreRequest.groovy: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.pre; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | 5 | import com.netflix.zuul.ZuulFilter; 6 | import com.netflix.zuul.context.RequestContext; 7 | 8 | class PreRequest extends ZuulFilter { 9 | @Override 10 | String filterType() { 11 | return "pre" 12 | } 13 | 14 | @Override 15 | int filterOrder() { 16 | return 1000 17 | } 18 | 19 | @Override 20 | boolean shouldFilter() { 21 | return true 22 | } 23 | 24 | @Override 25 | Object run() { 26 | HttpServletRequest request = RequestContext.currentContext().request(); 27 | print(String.format("send %s request to %s", request.getMethod(), request.getRequestURL().toString())); 28 | return null 29 | } 30 | } -------------------------------------------------------------------------------- /microservice-gateway-zuul-filter-groovy/src/main/java/com/itmuch/cloud/study/ZuulApplication.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study; 2 | 3 | import org.springframework.boot.CommandLineRunner; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.cloud.netflix.zuul.EnableZuulProxy; 7 | import org.springframework.stereotype.Component; 8 | 9 | import com.netflix.zuul.FilterFileManager; 10 | import com.netflix.zuul.FilterLoader; 11 | import com.netflix.zuul.groovy.GroovyCompiler; 12 | import com.netflix.zuul.groovy.GroovyFileFilter; 13 | import com.netflix.zuul.monitoring.MonitoringHelper; 14 | 15 | @SpringBootApplication 16 | @EnableZuulProxy 17 | public class ZuulApplication { 18 | public static void main(String[] args) { 19 | SpringApplication.run(ZuulApplication.class, args); 20 | } 21 | 22 | @Component 23 | public static class MyCommandLineRunner implements CommandLineRunner { 24 | @Override 25 | public void run(String... args) throws Exception { 26 | MonitoringHelper.initMocks(); 27 | FilterLoader.getInstance().setCompiler(new GroovyCompiler()); 28 | try { 29 | FilterFileManager.setFilenameFilter(new GroovyFileFilter()); 30 | 31 | String basePath = "D:/写书/code/microservice-gateway-zuul-filter-groovy/src/main/filters/"; 32 | 33 | FilterFileManager.init(1, basePath + "pre", basePath + "post"); 34 | } catch (Exception e) { 35 | throw new RuntimeException(e); 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /microservice-gateway-zuul-filter-groovy/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8040 3 | spring: 4 | application: 5 | name: microservice-gateway-zuul 6 | eureka: 7 | client: 8 | service-url: 9 | defaultZone: http://localhost:8761/eureka/ 10 | instance: 11 | prefer-ip-address: true -------------------------------------------------------------------------------- /microservice-gateway-zuul-filter/src/main/java/com/itmuch/cloud/study/ZuulApplication.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 | import org.springframework.context.annotation.Bean; 7 | 8 | import com.itmuch.cloud.study.filters.pre.PreRequestLogFilter; 9 | 10 | @SpringBootApplication 11 | @EnableZuulProxy 12 | public class ZuulApplication { 13 | public static void main(String[] args) { 14 | SpringApplication.run(ZuulApplication.class, args); 15 | } 16 | 17 | @Bean 18 | public PreRequestLogFilter preRequestLogFilter() { 19 | return new PreRequestLogFilter(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /microservice-gateway-zuul-filter/src/main/java/com/itmuch/cloud/study/filters/pre/PreRequestLogFilter.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.filters.pre; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import com.netflix.zuul.ZuulFilter; 9 | import com.netflix.zuul.context.RequestContext; 10 | 11 | public class PreRequestLogFilter extends ZuulFilter { 12 | private static final Logger LOGGER = LoggerFactory.getLogger(PreRequestLogFilter.class); 13 | 14 | @Override 15 | public String filterType() { 16 | return "pre"; 17 | } 18 | 19 | @Override 20 | public int filterOrder() { 21 | return 1; 22 | } 23 | 24 | @Override 25 | public boolean shouldFilter() { 26 | return true; 27 | } 28 | 29 | @Override 30 | public Object run() { 31 | RequestContext ctx = RequestContext.getCurrentContext(); 32 | HttpServletRequest request = ctx.getRequest(); 33 | PreRequestLogFilter.LOGGER.info(String.format("send %s request to %s", request.getMethod(), request.getRequestURL().toString())); 34 | return null; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /microservice-gateway-zuul-filter/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8040 3 | spring: 4 | application: 5 | name: microservice-gateway-zuul 6 | eureka: 7 | client: 8 | service-url: 9 | defaultZone: http://localhost:8761/eureka/ 10 | instance: 11 | prefer-ip-address: true -------------------------------------------------------------------------------- /microservice-gateway-zuul-reg-exp/src/main/java/com/itmuch/cloud/study/ZuulApplication.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 | import org.springframework.cloud.netflix.zuul.filters.discovery.PatternServiceRouteMapper; 7 | import org.springframework.context.annotation.Bean; 8 | 9 | @SpringBootApplication 10 | @EnableZuulProxy 11 | public class ZuulApplication { 12 | 13 | @Bean 14 | public PatternServiceRouteMapper serviceRouteMapper() { 15 | // 调用构造函数PatternServiceRouteMapper(String servicePattern, String routePattern) 16 | // servicePattern指定微服务的正则 17 | // routePattern指定路由正则 18 | return new PatternServiceRouteMapper("(?^.+)-(?v.+$)", "${version}/${name}"); 19 | } 20 | 21 | public static void main(String[] args) { 22 | SpringApplication.run(ZuulApplication.class, args); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /microservice-gateway-zuul-reg-exp/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8040 3 | spring: 4 | application: 5 | name: microservice-gateway-zuul 6 | eureka: 7 | client: 8 | service-url: 9 | defaultZone: http://localhost:8761/eureka/ 10 | instance: 11 | prefer-ip-address: true -------------------------------------------------------------------------------- /microservice-gateway-zuul/src/main/java/com/itmuch/cloud/study/ZuulApplication.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 | @SpringBootApplication 8 | @EnableZuulProxy 9 | public class ZuulApplication { 10 | public static void main(String[] args) { 11 | SpringApplication.run(ZuulApplication.class, args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /microservice-gateway-zuul/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8040 3 | spring: 4 | application: 5 | name: microservice-gateway-zuul 6 | eureka: 7 | client: 8 | service-url: 9 | defaultZone: http://localhost:8761/eureka/ 10 | instance: 11 | prefer-ip-address: true -------------------------------------------------------------------------------- /microservice-gateway-zuul/src/main/resources/application.yml.bak1_指定微服务路径: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8040 3 | spring: 4 | application: 5 | name: microservice-gateway-zuul 6 | eureka: 7 | client: 8 | service-url: 9 | defaultZone: http://localhost:8761/eureka/ 10 | instance: 11 | prefer-ip-address: true 12 | zuul: 13 | routes: 14 | microservice-provider-user: /user/** 15 | -------------------------------------------------------------------------------- /microservice-gateway-zuul/src/main/resources/application.yml.bak2_忽略指定微服务: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8040 3 | spring: 4 | application: 5 | name: microservice-gateway-zuul 6 | eureka: 7 | client: 8 | service-url: 9 | defaultZone: http://localhost:8761/eureka/ 10 | instance: 11 | prefer-ip-address: true 12 | zuul: 13 | ignored-services: microservice-provider-user,microservice-consumer-movie 14 | -------------------------------------------------------------------------------- /microservice-gateway-zuul/src/main/resources/application.yml.bak3_忽略所有微服务,只路由指定的微服务: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8040 3 | spring: 4 | application: 5 | name: microservice-gateway-zuul 6 | eureka: 7 | client: 8 | service-url: 9 | defaultZone: http://localhost:8761/eureka/ 10 | instance: 11 | prefer-ip-address: true 12 | zuul: 13 | ignored-services: '*' # 使用'*'可忽略所有微服务 14 | routes: 15 | microservice-provider-user: /user/** 16 | -------------------------------------------------------------------------------- /microservice-gateway-zuul/src/main/resources/application.yml.bak4_同时指定微服务的serviceId和对应路径: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8040 3 | spring: 4 | application: 5 | name: microservice-gateway-zuul 6 | eureka: 7 | client: 8 | service-url: 9 | defaultZone: http://localhost:8761/eureka/ 10 | instance: 11 | prefer-ip-address: true 12 | zuul: 13 | routes: 14 | user-route: # 该配置方式中,user-route只是给路由一个名称,可以任意起名。 15 | service-id: microservice-provider-user 16 | path: /user/** # service-id对应的路径 17 | -------------------------------------------------------------------------------- /microservice-gateway-zuul/src/main/resources/application.yml.bak5_同时指定path和url: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8040 3 | spring: 4 | application: 5 | name: microservice-gateway-zuul 6 | eureka: 7 | client: 8 | service-url: 9 | defaultZone: http://localhost:8761/eureka/ 10 | instance: 11 | prefer-ip-address: true 12 | zuul: 13 | routes: 14 | user-route: # 该配置方式中,user-route只是给路由一个名称,可以任意起名。 15 | url: http://localhost:8000/ # 指定的url 16 | path: /user/** # url对应的路径。 17 | -------------------------------------------------------------------------------- /microservice-gateway-zuul/src/main/resources/application.yml.bak6_同时指定path和URL,并且不破坏Zuul的Hystrix、Ribbon特性。: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8040 3 | spring: 4 | application: 5 | name: microservice-gateway-zuul 6 | eureka: 7 | client: 8 | service-url: 9 | defaultZone: http://localhost:8761/eureka/ 10 | instance: 11 | prefer-ip-address: true 12 | zuul: 13 | routes: 14 | user-route: 15 | path: /user/** 16 | service-id: microservice-provider-user 17 | ribbon: 18 | eureka: 19 | enabled: false # 禁用掉ribbon的eureka使用。详见:http://cloud.spring.io/spring-cloud-static/Camden.SR3/#_example_disable_eureka_use_in_ribbon 20 | microservice-provider-user: 21 | ribbon: 22 | listOfServers: localhost:8000,localhost:8001 23 | -------------------------------------------------------------------------------- /microservice-gateway-zuul/src/main/resources/application.yml.bak8_为Zuul添加映射前缀1: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8040 3 | spring: 4 | application: 5 | name: microservice-gateway-zuul 6 | eureka: 7 | client: 8 | service-url: 9 | defaultZone: http://localhost:8761/eureka/ 10 | instance: 11 | prefer-ip-address: true 12 | zuul: 13 | prefix: /api 14 | strip-prefix: false 15 | routes: 16 | microservice-provider-user: /user/** 17 | logging: 18 | level: 19 | com.netflix: DEBUG 20 | 21 | # 访问Zuul的/api/microservice-provider-user/1路径,请求将会被转发到microservice-provider-user的/api/1,,可以查看日志打印,有助于理解。 -------------------------------------------------------------------------------- /microservice-gateway-zuul/src/main/resources/application.yml.bak8_为Zuul添加映射前缀2: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8040 3 | spring: 4 | application: 5 | name: microservice-gateway-zuul 6 | eureka: 7 | client: 8 | service-url: 9 | defaultZone: http://localhost:8761/eureka/ 10 | instance: 11 | prefer-ip-address: true 12 | zuul: 13 | routes: 14 | microservice-provider-user: 15 | path: /user/** 16 | strip-prefix: false 17 | logging: 18 | level: 19 | com.netflix: DEBUG 20 | 21 | # 这样访问Zuul的/user/1路径,请求将会被转发到microservice-provider-user的/user/1,可以查看日志打印,有助于理解。 -------------------------------------------------------------------------------- /microservice-gateway-zuul/src/main/resources/application.yml.bak9_忽略某些路径: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8040 3 | spring: 4 | application: 5 | name: microservice-gateway-zuul 6 | eureka: 7 | client: 8 | service-url: 9 | defaultZone: http://localhost:8761/eureka/ 10 | instance: 11 | prefer-ip-address: true 12 | zuul: 13 | ignoredPatterns: /**/admin/** # 忽略所有包括/admin/的路径 14 | routes: 15 | microservice-provider-user: /user/** 16 | -------------------------------------------------------------------------------- /microservice-hystrix-dashboard/src/main/java/com/itmuch/cloud/study/HystrixDashboardApplication.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.hystrix.dashboard.EnableHystrixDashboard; 6 | 7 | @SpringBootApplication 8 | @EnableHystrixDashboard 9 | public class HystrixDashboardApplication { 10 | public static void main(String[] args) { 11 | SpringApplication.run(HystrixDashboardApplication.class, args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /microservice-hystrix-dashboard/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8030 3 | -------------------------------------------------------------------------------- /microservice-hystrix-turbine-mq/src/main/java/com/itmuch/cloud/study/TurbineApplication.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.turbine.stream.EnableTurbineStream; 6 | 7 | @SpringBootApplication 8 | @EnableTurbineStream 9 | public class TurbineApplication { 10 | public static void main(String[] args) { 11 | SpringApplication.run(TurbineApplication.class, args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /microservice-hystrix-turbine-mq/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8031 3 | spring: 4 | application: 5 | name: microservice-hystrix-turbine 6 | rabbitmq: 7 | host: localhost 8 | port: 5672 9 | username: guest 10 | password: guest 11 | eureka: 12 | client: 13 | service-url: 14 | defaultZone: http://localhost:8761/eureka/ 15 | instance: 16 | prefer-ip-address: true 17 | -------------------------------------------------------------------------------- /microservice-hystrix-turbine/src/main/java/com/itmuch/cloud/study/TurbineApplication.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.turbine.EnableTurbine; 6 | 7 | @SpringBootApplication 8 | @EnableTurbine 9 | public class TurbineApplication { 10 | public static void main(String[] args) { 11 | SpringApplication.run(TurbineApplication.class, args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /microservice-hystrix-turbine/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8031 3 | spring: 4 | application: 5 | name: microservice-hystrix-turbine 6 | eureka: 7 | client: 8 | service-url: 9 | defaultZone: http://localhost:8761/eureka/ 10 | instance: 11 | prefer-ip-address: true 12 | turbine: 13 | appConfig: microservice-consumer-movie,microservice-consumer-movie-feign-hystrix-fallback-stream 14 | clusterNameExpression: "'default'" -------------------------------------------------------------------------------- /microservice-provider-user-ip/src/main/java/com/itmuch/cloud/study/ProviderUserApplication.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 | @EnableDiscoveryClient 8 | @SpringBootApplication 9 | public class ProviderUserApplication { 10 | public static void main(String[] args) { 11 | SpringApplication.run(ProviderUserApplication.class, args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /microservice-provider-user-ip/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.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.entity.User; 9 | import com.itmuch.cloud.study.repository.UserRepository; 10 | 11 | @RestController 12 | public class UserController { 13 | @Autowired 14 | private UserRepository userRepository; 15 | 16 | @GetMapping("/{id}") 17 | public User findById(@PathVariable Long id) { 18 | User findOne = this.userRepository.findOne(id); 19 | return findOne; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /microservice-provider-user-ip/src/main/java/com/itmuch/cloud/study/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.entity; 2 | 3 | import java.math.BigDecimal; 4 | 5 | import javax.persistence.Column; 6 | import javax.persistence.Entity; 7 | import javax.persistence.GeneratedValue; 8 | import javax.persistence.GenerationType; 9 | import javax.persistence.Id; 10 | 11 | @Entity 12 | public class User { 13 | @Id 14 | @GeneratedValue(strategy = GenerationType.AUTO) 15 | private Long id; 16 | @Column 17 | private String username; 18 | @Column 19 | private String name; 20 | @Column 21 | private Integer age; 22 | @Column 23 | private BigDecimal balance; 24 | 25 | public Long getId() { 26 | return this.id; 27 | } 28 | 29 | public void setId(Long id) { 30 | this.id = id; 31 | } 32 | 33 | public String getUsername() { 34 | return this.username; 35 | } 36 | 37 | public void setUsername(String username) { 38 | this.username = username; 39 | } 40 | 41 | public String getName() { 42 | return this.name; 43 | } 44 | 45 | public void setName(String name) { 46 | this.name = name; 47 | } 48 | 49 | public Integer getAge() { 50 | return this.age; 51 | } 52 | 53 | public void setAge(Integer age) { 54 | this.age = age; 55 | } 56 | 57 | public BigDecimal getBalance() { 58 | return this.balance; 59 | } 60 | 61 | public void setBalance(BigDecimal balance) { 62 | this.balance = balance; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /microservice-provider-user-ip/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.entity.User; 7 | 8 | @Repository 9 | public interface UserRepository extends JpaRepository { 10 | } 11 | -------------------------------------------------------------------------------- /microservice-provider-user-ip/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8000 3 | spring: 4 | cloud: 5 | inetutils: 6 | ignored-interfaces: 7 | - docker0 8 | - veth.* 9 | application: 10 | name: microservice-provider-user 11 | jpa: 12 | generate-ddl: false 13 | show-sql: true 14 | hibernate: 15 | ddl-auto: none 16 | datasource: # 指定数据源 17 | platform: h2 # 指定数据源类型 18 | schema: classpath:schema.sql # 指定h2数据库的建表脚本 19 | data: classpath:data.sql # 指定h2数据库的数据脚本 20 | logging: # 配置日志级别,让hibernate打印出执行的SQL 21 | level: 22 | root: INFO 23 | org.hibernate: INFO 24 | org.hibernate.type.descriptor.sql.BasicBinder: TRACE 25 | org.hibernate.type.descriptor.sql.BasicExtractor: TRACE 26 | org.springframework.cloud.commons.util.InetUtils: TRACE # 开启这边的日志,可以打印出Spring查找网卡的过程 27 | eureka: 28 | client: 29 | serviceUrl: 30 | defaultZone: http://localhost:8761/eureka/ 31 | instance: 32 | prefer-ip-address: true -------------------------------------------------------------------------------- /microservice-provider-user-ip/src/main/resources/application.yml.bak1-忽略指定名称的网卡: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8000 3 | spring: 4 | cloud: 5 | inetutils: 6 | ignored-interfaces: 7 | - docker0 8 | - veth.* 9 | application: 10 | name: microservice-provider-user 11 | jpa: 12 | generate-ddl: false 13 | show-sql: true 14 | hibernate: 15 | ddl-auto: none 16 | datasource: # 指定数据源 17 | platform: h2 # 指定数据源类型 18 | schema: classpath:schema.sql # 指定h2数据库的建表脚本 19 | data: classpath:data.sql # 指定h2数据库的数据脚本 20 | logging: # 配置日志级别,让hibernate打印出执行的SQL 21 | level: 22 | root: INFO 23 | org.hibernate: INFO 24 | org.hibernate.type.descriptor.sql.BasicBinder: TRACE 25 | org.hibernate.type.descriptor.sql.BasicExtractor: TRACE 26 | org.springframework.cloud.commons.util.InetUtils: TRACE # 开启这边的日志,可以打印出Spring查找网卡的过程 27 | eureka: 28 | client: 29 | serviceUrl: 30 | defaultZone: http://localhost:8761/eureka/ 31 | instance: 32 | prefer-ip-address: true -------------------------------------------------------------------------------- /microservice-provider-user-ip/src/main/resources/application.yml.bak2-正则指定使用的地址: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8000 3 | spring: 4 | cloud: 5 | inetutils: 6 | preferredNetworks: 7 | - 192.168 8 | - 10.0 9 | application: 10 | name: microservice-provider-user 11 | jpa: 12 | generate-ddl: false 13 | show-sql: true 14 | hibernate: 15 | ddl-auto: none 16 | datasource: # 指定数据源 17 | platform: h2 # 指定数据源类型 18 | schema: classpath:schema.sql # 指定h2数据库的建表脚本 19 | data: classpath:data.sql # 指定h2数据库的数据脚本 20 | logging: # 配置日志级别,让hibernate打印出执行的SQL 21 | level: 22 | root: INFO 23 | org.hibernate: INFO 24 | org.hibernate.type.descriptor.sql.BasicBinder: TRACE 25 | org.hibernate.type.descriptor.sql.BasicExtractor: TRACE 26 | org.springframework.cloud.commons.util.InetUtils: TRACE # 开启这边的日志,可以打印出Spring查找网卡的过程 27 | eureka: 28 | client: 29 | serviceUrl: 30 | defaultZone: http://localhost:8761/eureka/ 31 | instance: 32 | prefer-ip-address: true -------------------------------------------------------------------------------- /microservice-provider-user-ip/src/main/resources/application.yml.bak3-使用站点本地地址: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8000 3 | spring: 4 | cloud: 5 | inetutils: 6 | useOnlySiteLocalInterfaces: true 7 | application: 8 | name: microservice-provider-user 9 | jpa: 10 | generate-ddl: false 11 | show-sql: true 12 | hibernate: 13 | ddl-auto: none 14 | datasource: # 指定数据源 15 | platform: h2 # 指定数据源类型 16 | schema: classpath:schema.sql # 指定h2数据库的建表脚本 17 | data: classpath:data.sql # 指定h2数据库的数据脚本 18 | logging: # 配置日志级别,让hibernate打印出执行的SQL 19 | level: 20 | root: INFO 21 | org.hibernate: INFO 22 | org.hibernate.type.descriptor.sql.BasicBinder: TRACE 23 | org.hibernate.type.descriptor.sql.BasicExtractor: TRACE 24 | org.springframework.cloud.commons.util.InetUtils: TRACE # 开启这边的日志,可以打印出Spring查找网卡的过程 25 | eureka: 26 | client: 27 | serviceUrl: 28 | defaultZone: http://localhost:8761/eureka/ 29 | instance: 30 | prefer-ip-address: true -------------------------------------------------------------------------------- /microservice-provider-user-ip/src/main/resources/application.yml.bak4-手动指定IP: -------------------------------------------------------------------------------- 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数据库的数据脚本 15 | logging: # 配置日志级别,让hibernate打印出执行的SQL 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 | org.springframework.cloud.commons.util.InetUtils: TRACE # 开启这边的日志,可以打印出Spring查找网卡的过程 22 | eureka: 23 | client: 24 | serviceUrl: 25 | defaultZone: http://localhost:8761/eureka/ 26 | instance: 27 | prefer-ip-address: true 28 | ip-address: 127.0.0.1 -------------------------------------------------------------------------------- /microservice-provider-user-ip/src/main/resources/data.sql: -------------------------------------------------------------------------------- 1 | insert into user (id, username, name, age, balance) values (1, 'account1', '张三', 20, 100.00); 2 | insert into user (id, username, name, age, balance) values (2, 'account2', '李四', 28, 180.00); 3 | insert into user (id, username, name, age, balance) values (3, 'account3', '王五', 32, 280.00); -------------------------------------------------------------------------------- /microservice-provider-user-ip/src/main/resources/schema.sql: -------------------------------------------------------------------------------- 1 | drop table user if exists; 2 | create table user (id bigint generated by default as identity, username varchar(40), name varchar(20), age int(3), balance decimal(10,2), primary key (id)); -------------------------------------------------------------------------------- /microservice-provider-user-multiple-params/src/main/java/com/itmuch/cloud/study/ProviderUserApplication.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 | @EnableDiscoveryClient 8 | @SpringBootApplication 9 | public class ProviderUserApplication { 10 | public static void main(String[] args) { 11 | SpringApplication.run(ProviderUserApplication.class, args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /microservice-provider-user-multiple-params/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.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.PathVariable; 6 | import org.springframework.web.bind.annotation.PostMapping; 7 | import org.springframework.web.bind.annotation.RequestBody; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | import com.itmuch.cloud.study.entity.User; 11 | import com.itmuch.cloud.study.repository.UserRepository; 12 | 13 | @RestController 14 | public class UserController { 15 | @Autowired 16 | private UserRepository userRepository; 17 | 18 | @GetMapping("/{id}") 19 | public User findById(@PathVariable Long id) { 20 | User findOne = this.userRepository.findOne(id); 21 | return findOne; 22 | } 23 | 24 | @GetMapping("/get") 25 | public User get(User user) { 26 | return user; 27 | } 28 | 29 | @PostMapping("/post") 30 | public User post(@RequestBody User user) { 31 | return user; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /microservice-provider-user-multiple-params/src/main/java/com/itmuch/cloud/study/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.entity; 2 | 3 | import java.math.BigDecimal; 4 | 5 | import javax.persistence.Column; 6 | import javax.persistence.Entity; 7 | import javax.persistence.GeneratedValue; 8 | import javax.persistence.GenerationType; 9 | import javax.persistence.Id; 10 | 11 | @Entity 12 | public class User { 13 | @Id 14 | @GeneratedValue(strategy = GenerationType.AUTO) 15 | private Long id; 16 | @Column 17 | private String username; 18 | @Column 19 | private String name; 20 | @Column 21 | private Integer age; 22 | @Column 23 | private BigDecimal balance; 24 | 25 | public Long getId() { 26 | return this.id; 27 | } 28 | 29 | public void setId(Long id) { 30 | this.id = id; 31 | } 32 | 33 | public String getUsername() { 34 | return this.username; 35 | } 36 | 37 | public void setUsername(String username) { 38 | this.username = username; 39 | } 40 | 41 | public String getName() { 42 | return this.name; 43 | } 44 | 45 | public void setName(String name) { 46 | this.name = name; 47 | } 48 | 49 | public Integer getAge() { 50 | return this.age; 51 | } 52 | 53 | public void setAge(Integer age) { 54 | this.age = age; 55 | } 56 | 57 | public BigDecimal getBalance() { 58 | return this.balance; 59 | } 60 | 61 | public void setBalance(BigDecimal balance) { 62 | this.balance = balance; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /microservice-provider-user-multiple-params/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.entity.User; 7 | 8 | @Repository 9 | public interface UserRepository extends JpaRepository { 10 | } 11 | -------------------------------------------------------------------------------- /microservice-provider-user-multiple-params/src/main/resources/application-autherntication.yml.bak: -------------------------------------------------------------------------------- 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数据库的数据脚本 15 | logging: # 配置日志级别,让hibernate打印出执行的SQL 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 | eureka: 22 | client: 23 | serviceUrl: 24 | defaultZone: http://user:password123@localhost:8761/eureka/ 25 | instance: 26 | prefer-ip-address: true -------------------------------------------------------------------------------- /microservice-provider-user-multiple-params/src/main/resources/application-ha.yml.bak: -------------------------------------------------------------------------------- 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数据库的数据脚本 15 | logging: # 配置日志级别,让hibernate打印出执行的SQL 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 | eureka: 22 | client: 23 | serviceUrl: 24 | defaultZone: http://peer1:8761/eureka/,http://peer2:8762/eureka/ 25 | instance: 26 | prefer-ip-address: true -------------------------------------------------------------------------------- /microservice-provider-user-multiple-params/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数据库的数据脚本 15 | logging: # 配置日志级别,让hibernate打印出执行的SQL 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 | eureka: 22 | client: 23 | serviceUrl: 24 | defaultZone: http://localhost:8761/eureka/ 25 | instance: 26 | prefer-ip-address: true -------------------------------------------------------------------------------- /microservice-provider-user-multiple-params/src/main/resources/data.sql: -------------------------------------------------------------------------------- 1 | insert into user (id, username, name, age, balance) values (1, 'account1', '张三', 20, 100.00); 2 | insert into user (id, username, name, age, balance) values (2, 'account2', '李四', 28, 180.00); 3 | insert into user (id, username, name, age, balance) values (3, 'account3', '王五', 32, 280.00); -------------------------------------------------------------------------------- /microservice-provider-user-multiple-params/src/main/resources/schema.sql: -------------------------------------------------------------------------------- 1 | drop table user if exists; 2 | create table user (id bigint generated by default as identity, username varchar(40), name varchar(20), age int(3), balance decimal(10,2), primary key (id)); -------------------------------------------------------------------------------- /microservice-provider-user-my-metadata/src/main/java/com/itmuch/cloud/study/ProviderUserApplication.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 | @EnableDiscoveryClient 8 | @SpringBootApplication 9 | public class ProviderUserApplication { 10 | public static void main(String[] args) { 11 | SpringApplication.run(ProviderUserApplication.class, args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /microservice-provider-user-my-metadata/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.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.entity.User; 9 | import com.itmuch.cloud.study.repository.UserRepository; 10 | 11 | @RestController 12 | public class UserController { 13 | @Autowired 14 | private UserRepository userRepository; 15 | 16 | @GetMapping("/{id}") 17 | public User findById(@PathVariable Long id) { 18 | User findOne = this.userRepository.findOne(id); 19 | return findOne; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /microservice-provider-user-my-metadata/src/main/java/com/itmuch/cloud/study/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.entity; 2 | 3 | import java.math.BigDecimal; 4 | 5 | import javax.persistence.Column; 6 | import javax.persistence.Entity; 7 | import javax.persistence.GeneratedValue; 8 | import javax.persistence.GenerationType; 9 | import javax.persistence.Id; 10 | 11 | @Entity 12 | public class User { 13 | @Id 14 | @GeneratedValue(strategy = GenerationType.AUTO) 15 | private Long id; 16 | @Column 17 | private String username; 18 | @Column 19 | private String name; 20 | @Column 21 | private Integer age; 22 | @Column 23 | private BigDecimal balance; 24 | 25 | public Long getId() { 26 | return this.id; 27 | } 28 | 29 | public void setId(Long id) { 30 | this.id = id; 31 | } 32 | 33 | public String getUsername() { 34 | return this.username; 35 | } 36 | 37 | public void setUsername(String username) { 38 | this.username = username; 39 | } 40 | 41 | public String getName() { 42 | return this.name; 43 | } 44 | 45 | public void setName(String name) { 46 | this.name = name; 47 | } 48 | 49 | public Integer getAge() { 50 | return this.age; 51 | } 52 | 53 | public void setAge(Integer age) { 54 | this.age = age; 55 | } 56 | 57 | public BigDecimal getBalance() { 58 | return this.balance; 59 | } 60 | 61 | public void setBalance(BigDecimal balance) { 62 | this.balance = balance; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /microservice-provider-user-my-metadata/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.entity.User; 7 | 8 | @Repository 9 | public interface UserRepository extends JpaRepository { 10 | } 11 | -------------------------------------------------------------------------------- /microservice-provider-user-my-metadata/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数据库的数据脚本 15 | logging: # 配置日志级别,让hibernate打印出执行的SQL 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 | eureka: 22 | client: 23 | serviceUrl: 24 | defaultZone: http://localhost:8761/eureka/ 25 | instance: 26 | prefer-ip-address: true 27 | metadata-map: 28 | my-metadata: 我自定义的元数据 # 自定义的元数据,key/value都可以随便写。 -------------------------------------------------------------------------------- /microservice-provider-user-my-metadata/src/main/resources/data.sql: -------------------------------------------------------------------------------- 1 | insert into user (id, username, name, age, balance) values (1, 'account1', '张三', 20, 100.00); 2 | insert into user (id, username, name, age, balance) values (2, 'account2', '李四', 28, 180.00); 3 | insert into user (id, username, name, age, balance) values (3, 'account3', '王五', 32, 280.00); -------------------------------------------------------------------------------- /microservice-provider-user-my-metadata/src/main/resources/schema.sql: -------------------------------------------------------------------------------- 1 | drop table user if exists; 2 | create table user (id bigint generated by default as identity, username varchar(40), name varchar(20), age int(3), balance decimal(10,2), primary key (id)); -------------------------------------------------------------------------------- /microservice-provider-user-with-auth/src/main/java/com/itmuch/cloud/study/ProviderUserApplication.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 | @EnableDiscoveryClient 8 | @SpringBootApplication 9 | public class ProviderUserApplication { 10 | public static void main(String[] args) { 11 | SpringApplication.run(ProviderUserApplication.class, args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /microservice-provider-user-with-auth/src/main/java/com/itmuch/cloud/study/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.entity; 2 | 3 | import java.math.BigDecimal; 4 | 5 | import javax.persistence.Column; 6 | import javax.persistence.Entity; 7 | import javax.persistence.GeneratedValue; 8 | import javax.persistence.GenerationType; 9 | import javax.persistence.Id; 10 | 11 | @Entity 12 | public class User { 13 | @Id 14 | @GeneratedValue(strategy = GenerationType.AUTO) 15 | private Long id; 16 | @Column 17 | private String username; 18 | @Column 19 | private String name; 20 | @Column 21 | private Integer age; 22 | @Column 23 | private BigDecimal balance; 24 | 25 | public Long getId() { 26 | return this.id; 27 | } 28 | 29 | public void setId(Long id) { 30 | this.id = id; 31 | } 32 | 33 | public String getUsername() { 34 | return this.username; 35 | } 36 | 37 | public void setUsername(String username) { 38 | this.username = username; 39 | } 40 | 41 | public String getName() { 42 | return this.name; 43 | } 44 | 45 | public void setName(String name) { 46 | this.name = name; 47 | } 48 | 49 | public Integer getAge() { 50 | return this.age; 51 | } 52 | 53 | public void setAge(Integer age) { 54 | this.age = age; 55 | } 56 | 57 | public BigDecimal getBalance() { 58 | return this.balance; 59 | } 60 | 61 | public void setBalance(BigDecimal balance) { 62 | this.balance = balance; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /microservice-provider-user-with-auth/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.entity.User; 7 | 8 | @Repository 9 | public interface UserRepository extends JpaRepository { 10 | } 11 | -------------------------------------------------------------------------------- /microservice-provider-user-with-auth/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数据库的数据脚本 15 | logging: # 配置日志级别,让hibernate打印出执行的SQL 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 | eureka: 22 | client: 23 | serviceUrl: 24 | defaultZone: http://localhost:8761/eureka/ 25 | instance: 26 | prefer-ip-address: true -------------------------------------------------------------------------------- /microservice-provider-user-with-auth/src/main/resources/data.sql: -------------------------------------------------------------------------------- 1 | insert into user (id, username, name, age, balance) values (1, 'account1', '张三', 20, 100.00); 2 | insert into user (id, username, name, age, balance) values (2, 'account2', '李四', 28, 180.00); 3 | insert into user (id, username, name, age, balance) values (3, 'account3', '王五', 32, 280.00); -------------------------------------------------------------------------------- /microservice-provider-user-with-auth/src/main/resources/schema.sql: -------------------------------------------------------------------------------- 1 | drop table user if exists; 2 | create table user (id bigint generated by default as identity, username varchar(40), name varchar(20), age int(3), balance decimal(10,2), primary key (id)); -------------------------------------------------------------------------------- /microservice-provider-user/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /microservice-provider-user/.springBeans: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1 4 | 5 | 6 | 7 | 8 | 9 | 10 | java:com.itmuch.cloud.study.ProviderUserApplication 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /microservice-provider-user/src/main/java/com/itmuch/cloud/study/ProviderUserApplication.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 | @EnableDiscoveryClient 8 | @SpringBootApplication 9 | public class ProviderUserApplication { 10 | public static void main(String[] args) { 11 | SpringApplication.run(ProviderUserApplication.class, args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /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.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.entity.User; 9 | import com.itmuch.cloud.study.repository.UserRepository; 10 | 11 | @RestController 12 | public class UserController { 13 | @Autowired 14 | private UserRepository userRepository; 15 | 16 | @GetMapping("/{id}") 17 | public User findById(@PathVariable Long id) { 18 | User findOne = this.userRepository.findOne(id); 19 | return findOne; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /microservice-provider-user/src/main/java/com/itmuch/cloud/study/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.entity; 2 | 3 | import java.math.BigDecimal; 4 | 5 | import javax.persistence.Column; 6 | import javax.persistence.Entity; 7 | import javax.persistence.GeneratedValue; 8 | import javax.persistence.GenerationType; 9 | import javax.persistence.Id; 10 | 11 | @Entity 12 | public class User { 13 | @Id 14 | @GeneratedValue(strategy = GenerationType.AUTO) 15 | private Long id; 16 | @Column 17 | private String username; 18 | @Column 19 | private String name; 20 | @Column 21 | private Integer age; 22 | @Column 23 | private BigDecimal balance; 24 | 25 | public Long getId() { 26 | return this.id; 27 | } 28 | 29 | public void setId(Long id) { 30 | this.id = id; 31 | } 32 | 33 | public String getUsername() { 34 | return this.username; 35 | } 36 | 37 | public void setUsername(String username) { 38 | this.username = username; 39 | } 40 | 41 | public String getName() { 42 | return this.name; 43 | } 44 | 45 | public void setName(String name) { 46 | this.name = name; 47 | } 48 | 49 | public Integer getAge() { 50 | return this.age; 51 | } 52 | 53 | public void setAge(Integer age) { 54 | this.age = age; 55 | } 56 | 57 | public BigDecimal getBalance() { 58 | return this.balance; 59 | } 60 | 61 | public void setBalance(BigDecimal balance) { 62 | this.balance = balance; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /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.entity.User; 7 | 8 | @Repository 9 | public interface UserRepository extends JpaRepository { 10 | } 11 | -------------------------------------------------------------------------------- /microservice-provider-user/src/main/resources/application-autherntication.yml.bak: -------------------------------------------------------------------------------- 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数据库的数据脚本 15 | logging: # 配置日志级别,让hibernate打印出执行的SQL 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 | eureka: 22 | client: 23 | serviceUrl: 24 | defaultZone: http://user:password123@localhost:8761/eureka/ 25 | instance: 26 | prefer-ip-address: true -------------------------------------------------------------------------------- /microservice-provider-user/src/main/resources/application-ha.yml.bak: -------------------------------------------------------------------------------- 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数据库的数据脚本 15 | logging: # 配置日志级别,让hibernate打印出执行的SQL 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 | eureka: 22 | client: 23 | serviceUrl: 24 | defaultZone: http://peer1:8761/eureka/,http://peer2:8762/eureka/ 25 | instance: 26 | prefer-ip-address: true -------------------------------------------------------------------------------- /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数据库的数据脚本 15 | logging: # 配置日志级别,让hibernate打印出执行的SQL 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 | eureka: 22 | client: 23 | serviceUrl: 24 | defaultZone: http://localhost:8761/eureka/ 25 | instance: 26 | prefer-ip-address: true -------------------------------------------------------------------------------- /microservice-provider-user/src/main/resources/data.sql: -------------------------------------------------------------------------------- 1 | insert into user (id, username, name, age, balance) values (1, 'account1', '张三', 20, 100.00); 2 | insert into user (id, username, name, age, balance) values (2, 'account2', '李四', 28, 180.00); 3 | insert into user (id, username, name, age, balance) values (3, 'account3', '王五', 32, 280.00); -------------------------------------------------------------------------------- /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(40), name varchar(20), age int(3), balance decimal(10,2), primary key (id)); -------------------------------------------------------------------------------- /microservice-sidecar-client-ribbon/src/main/java/com/itmuch/cloud/study/SidecarClientApplication.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 | import org.springframework.cloud.client.loadbalancer.LoadBalanced; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.web.client.RestTemplate; 9 | 10 | @EnableDiscoveryClient 11 | @SpringBootApplication 12 | public class SidecarClientApplication { 13 | @Bean 14 | @LoadBalanced 15 | public RestTemplate restTemplate() { 16 | return new RestTemplate(); 17 | } 18 | 19 | public static void main(String[] args) { 20 | SpringApplication.run(SidecarClientApplication.class, args); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /microservice-sidecar-client-ribbon/src/main/java/com/itmuch/cloud/study/sidecar/controller/SidecarClientController.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.sidecar.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.RestController; 6 | import org.springframework.web.client.RestTemplate; 7 | 8 | @RestController 9 | public class SidecarClientController { 10 | @Autowired 11 | private RestTemplate restTemplate; 12 | 13 | @GetMapping("/test") 14 | public String findById() { 15 | // 将会请求到:http://localhost:8060/,返回结果:{"index":"欢迎来到首页"} 16 | return this.restTemplate.getForObject("http://microservice-sidecar-node-service/", String.class); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /microservice-sidecar-client-ribbon/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8071 3 | spring: 4 | application: 5 | name: microservice-consumer-movie 6 | eureka: 7 | client: 8 | serviceUrl: 9 | defaultZone: http://localhost:8761/eureka/ 10 | instance: 11 | prefer-ip-address: true -------------------------------------------------------------------------------- /microservice-sidecar/src/main/java/com/itmuch/cloud/study/SidecarApplication.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.sidecar.EnableSidecar; 6 | 7 | @SpringBootApplication 8 | @EnableSidecar 9 | public class SidecarApplication { 10 | public static void main(String[] args) { 11 | SpringApplication.run(SidecarApplication.class, args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /microservice-sidecar/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8070 3 | spring: 4 | application: 5 | name: microservice-sidecar-node-service 6 | eureka: 7 | client: 8 | service-url: 9 | defaultZone: http://localhost:8761/eureka/ 10 | instance: 11 | prefer-ip-address: true 12 | sidecar: 13 | port: 8060 # Node.js微服务的端口 14 | health-uri: http://localhost:8060/health.json # Node.js微服务的健康检查URL -------------------------------------------------------------------------------- /microservice-simple-consumer-movie/src/main/java/com/itmuch/cloud/study/ConsumerMovieApplication.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.context.annotation.Bean; 6 | import org.springframework.web.client.RestTemplate; 7 | 8 | @SpringBootApplication 9 | public class ConsumerMovieApplication { 10 | @Bean 11 | public RestTemplate restTemplate() { 12 | return new RestTemplate(); 13 | } 14 | 15 | public static void main(String[] args) { 16 | SpringApplication.run(ConsumerMovieApplication.class, args); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /microservice-simple-consumer-movie/src/main/java/com/itmuch/cloud/study/user/controller/MovieController.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 | import org.springframework.web.client.RestTemplate; 8 | 9 | import com.itmuch.cloud.study.user.entity.User; 10 | 11 | @RestController 12 | public class MovieController { 13 | @Autowired 14 | private RestTemplate restTemplate; 15 | 16 | @GetMapping("/user/{id}") 17 | public User findById(@PathVariable Long id) { 18 | return this.restTemplate.getForObject("http://localhost:8000/" + id, User.class); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /microservice-simple-consumer-movie/src/main/java/com/itmuch/cloud/study/user/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.user.entity; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class User { 6 | private Long id; 7 | private String username; 8 | private String name; 9 | private Integer age; 10 | private BigDecimal balance; 11 | 12 | public Long getId() { 13 | return this.id; 14 | } 15 | 16 | public void setId(Long id) { 17 | this.id = id; 18 | } 19 | 20 | public String getUsername() { 21 | return this.username; 22 | } 23 | 24 | public void setUsername(String username) { 25 | this.username = username; 26 | } 27 | 28 | public String getName() { 29 | return this.name; 30 | } 31 | 32 | public void setName(String name) { 33 | this.name = name; 34 | } 35 | 36 | public Integer getAge() { 37 | return this.age; 38 | } 39 | 40 | public void setAge(Integer age) { 41 | this.age = age; 42 | } 43 | 44 | public BigDecimal getBalance() { 45 | return this.balance; 46 | } 47 | 48 | public void setBalance(BigDecimal balance) { 49 | this.balance = balance; 50 | } 51 | } -------------------------------------------------------------------------------- /microservice-simple-consumer-movie/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8010 3 | -------------------------------------------------------------------------------- /microservice-simple-provider-user/src/main/java/com/itmuch/cloud/study/ProviderUserApplication.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ProviderUserApplication { 8 | public static void main(String[] args) { 9 | SpringApplication.run(ProviderUserApplication.class, args); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /microservice-simple-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.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.entity.User; 9 | import com.itmuch.cloud.study.repository.UserRepository; 10 | 11 | @RestController 12 | public class UserController { 13 | @Autowired 14 | private UserRepository userRepository; 15 | 16 | @GetMapping("/{id}") 17 | public User findById(@PathVariable Long id) { 18 | User findOne = this.userRepository.findOne(id); 19 | return findOne; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /microservice-simple-provider-user/src/main/java/com/itmuch/cloud/study/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.entity; 2 | 3 | import java.math.BigDecimal; 4 | 5 | import javax.persistence.Column; 6 | import javax.persistence.Entity; 7 | import javax.persistence.GeneratedValue; 8 | import javax.persistence.GenerationType; 9 | import javax.persistence.Id; 10 | 11 | @Entity 12 | public class User { 13 | @Id 14 | @GeneratedValue(strategy = GenerationType.AUTO) 15 | private Long id; 16 | @Column 17 | private String username; 18 | @Column 19 | private String name; 20 | @Column 21 | private Integer age; 22 | @Column 23 | private BigDecimal balance; 24 | 25 | public Long getId() { 26 | return this.id; 27 | } 28 | 29 | public void setId(Long id) { 30 | this.id = id; 31 | } 32 | 33 | public String getUsername() { 34 | return this.username; 35 | } 36 | 37 | public void setUsername(String username) { 38 | this.username = username; 39 | } 40 | 41 | public String getName() { 42 | return this.name; 43 | } 44 | 45 | public void setName(String name) { 46 | this.name = name; 47 | } 48 | 49 | public Integer getAge() { 50 | return this.age; 51 | } 52 | 53 | public void setAge(Integer age) { 54 | this.age = age; 55 | } 56 | 57 | public BigDecimal getBalance() { 58 | return this.balance; 59 | } 60 | 61 | public void setBalance(BigDecimal balance) { 62 | this.balance = balance; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /microservice-simple-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.entity.User; 7 | 8 | @Repository 9 | public interface UserRepository extends JpaRepository { 10 | } 11 | -------------------------------------------------------------------------------- /microservice-simple-provider-user/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8000 3 | spring: 4 | jpa: 5 | generate-ddl: false 6 | show-sql: true 7 | hibernate: 8 | ddl-auto: none 9 | datasource: # 指定数据源 10 | platform: h2 # 指定数据源类型 11 | schema: classpath:schema.sql # 指定h2数据库的建表脚本 12 | data: classpath:data.sql # 指定h2数据库的数据脚本 13 | logging: # 配置日志级别,让hibernate打印出执行的SQL 14 | level: 15 | root: INFO 16 | org.hibernate: INFO 17 | org.hibernate.type.descriptor.sql.BasicBinder: TRACE 18 | org.hibernate.type.descriptor.sql.BasicExtractor: TRACE 19 | 20 | ## INFO 21 | info: 22 | app: 23 | name: @project.artifactId@ 24 | encoding: @project.build.sourceEncoding@ 25 | java: 26 | source: @java.version@ 27 | target: @java.version@ -------------------------------------------------------------------------------- /microservice-simple-provider-user/src/main/resources/data.sql: -------------------------------------------------------------------------------- 1 | insert into user (id, username, name, age, balance) values (1, 'account1', '张三', 20, 100.00); 2 | insert into user (id, username, name, age, balance) values (2, 'account2', '李四', 28, 180.00); 3 | insert into user (id, username, name, age, balance) values (3, 'account3', '王五', 32, 280.00); -------------------------------------------------------------------------------- /microservice-simple-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(40), name varchar(20), age int(3), balance decimal(10,2), primary key (id)); -------------------------------------------------------------------------------- /node-service/README.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SpringForAll/spring-cloud-docker-microservice-book-code/c52d113288fa73ef06744155605889ca3553a121/node-service/README.txt -------------------------------------------------------------------------------- /node-service/node-service.js: -------------------------------------------------------------------------------- 1 | var http = require('http'); 2 | var url = require("url"); 3 | var path = require('path'); 4 | 5 | // 创建server 6 | var server = http.createServer(function(req, res) { 7 | // 获得请求的路径 8 | var pathname = url.parse(req.url).pathname; 9 | res.writeHead(200, { 'Content-Type' : 'application/json; charset=utf-8' }); 10 | // 访问http://localhost:8060/,将会返回{"index":"欢迎来到首页"} 11 | if (pathname === '/') { 12 | res.end(JSON.stringify({ "index" : "欢迎来到首页" })); 13 | } 14 | // 访问http://localhost:8060/health,将会返回{"status":"UP"} 15 | else if (pathname === '/health.json') { 16 | res.end(JSON.stringify({ "status" : "UP" })); 17 | } 18 | // 其他情况返回404 19 | else { 20 | res.end("404"); 21 | } 22 | }); 23 | // 创建监听,并打印日志 24 | server.listen(8060, function() { 25 | console.log('listening on localhost:8060'); 26 | }); -------------------------------------------------------------------------------- /node-service/py-app.py: -------------------------------------------------------------------------------- 1 | import httplib 2 | 3 | from twisted.web import server, resource 4 | from twisted.internet import reactor, endpoints 5 | 6 | class Health(resource.Resource): 7 | isLeaf = True 8 | 9 | def render_GET(self, request): 10 | request.setHeader("content-type", "application/json") 11 | return '{"status":"UP"}\n' 12 | 13 | class Fortune(resource.Resource): 14 | isLeaf = True 15 | 16 | def render_GET(self, request): 17 | conn = httplib.HTTPConnection('localhost', 5678) 18 | conn.request("GET", "/fortunes") 19 | res = conn.getresponse() 20 | fortune = res.read() 21 | request.setHeader("content-type", "text/plain") 22 | return fortune 23 | 24 | 25 | root = resource.Resource() 26 | root.putChild('health', Health()) 27 | root.putChild('', Fortune()) 28 | endpoints.serverFromString(reactor, "tcp:5680").listen(server.Site(root)) 29 | reactor.run() 30 | 31 | # FROM: https://gist.github.com/spencergibb/4f4b56c0e31c300531e9 32 | # FROM: https://github.com/spencergibb/oscon2015 -------------------------------------------------------------------------------- /trace/microservice-simple-consumer-movie-trace-zipkin/src/main/java/com/itmuch/cloud/study/ConsumerMovieApplication.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.context.annotation.Bean; 6 | import org.springframework.web.client.RestTemplate; 7 | 8 | @SpringBootApplication 9 | public class ConsumerMovieApplication { 10 | @Bean 11 | public RestTemplate restTemplate() { 12 | return new RestTemplate(); 13 | } 14 | 15 | public static void main(String[] args) { 16 | SpringApplication.run(ConsumerMovieApplication.class, args); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /trace/microservice-simple-consumer-movie-trace-zipkin/src/main/java/com/itmuch/cloud/study/user/controller/MovieController.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 | import org.springframework.web.client.RestTemplate; 8 | 9 | import com.itmuch.cloud.study.user.entity.User; 10 | 11 | @RestController 12 | public class MovieController { 13 | @Autowired 14 | private RestTemplate restTemplate; 15 | 16 | @GetMapping("/user/{id}") 17 | public User findById(@PathVariable Long id) { 18 | return this.restTemplate.getForObject("http://localhost:8000/" + id, User.class); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /trace/microservice-simple-consumer-movie-trace-zipkin/src/main/java/com/itmuch/cloud/study/user/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.user.entity; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class User { 6 | private Long id; 7 | private String username; 8 | private String name; 9 | private Integer age; 10 | private BigDecimal balance; 11 | 12 | public Long getId() { 13 | return this.id; 14 | } 15 | 16 | public void setId(Long id) { 17 | this.id = id; 18 | } 19 | 20 | public String getUsername() { 21 | return this.username; 22 | } 23 | 24 | public void setUsername(String username) { 25 | this.username = username; 26 | } 27 | 28 | public String getName() { 29 | return this.name; 30 | } 31 | 32 | public void setName(String name) { 33 | this.name = name; 34 | } 35 | 36 | public Integer getAge() { 37 | return this.age; 38 | } 39 | 40 | public void setAge(Integer age) { 41 | this.age = age; 42 | } 43 | 44 | public BigDecimal getBalance() { 45 | return this.balance; 46 | } 47 | 48 | public void setBalance(BigDecimal balance) { 49 | this.balance = balance; 50 | } 51 | } -------------------------------------------------------------------------------- /trace/microservice-simple-consumer-movie-trace-zipkin/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8010 3 | spring: 4 | application: 5 | name: microservice-consumer-movie 6 | zipkin: 7 | base-url: http://localhost:9411 8 | sleuth: 9 | sampler: 10 | percentage: 1.0 -------------------------------------------------------------------------------- /trace/microservice-simple-consumer-movie-trace/src/main/java/com/itmuch/cloud/study/ConsumerMovieApplication.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.context.annotation.Bean; 6 | import org.springframework.web.client.RestTemplate; 7 | 8 | @SpringBootApplication 9 | public class ConsumerMovieApplication { 10 | @Bean 11 | public RestTemplate restTemplate() { 12 | return new RestTemplate(); 13 | } 14 | 15 | public static void main(String[] args) { 16 | SpringApplication.run(ConsumerMovieApplication.class, args); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /trace/microservice-simple-consumer-movie-trace/src/main/java/com/itmuch/cloud/study/user/controller/MovieController.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 | import org.springframework.web.client.RestTemplate; 8 | 9 | import com.itmuch.cloud.study.user.entity.User; 10 | 11 | @RestController 12 | public class MovieController { 13 | @Autowired 14 | private RestTemplate restTemplate; 15 | 16 | @GetMapping("/user/{id}") 17 | public User findById(@PathVariable Long id) { 18 | return this.restTemplate.getForObject("http://localhost:8000/" + id, User.class); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /trace/microservice-simple-consumer-movie-trace/src/main/java/com/itmuch/cloud/study/user/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.user.entity; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class User { 6 | private Long id; 7 | private String username; 8 | private String name; 9 | private Integer age; 10 | private BigDecimal balance; 11 | 12 | public Long getId() { 13 | return this.id; 14 | } 15 | 16 | public void setId(Long id) { 17 | this.id = id; 18 | } 19 | 20 | public String getUsername() { 21 | return this.username; 22 | } 23 | 24 | public void setUsername(String username) { 25 | this.username = username; 26 | } 27 | 28 | public String getName() { 29 | return this.name; 30 | } 31 | 32 | public void setName(String name) { 33 | this.name = name; 34 | } 35 | 36 | public Integer getAge() { 37 | return this.age; 38 | } 39 | 40 | public void setAge(Integer age) { 41 | this.age = age; 42 | } 43 | 44 | public BigDecimal getBalance() { 45 | return this.balance; 46 | } 47 | 48 | public void setBalance(BigDecimal balance) { 49 | this.balance = balance; 50 | } 51 | } -------------------------------------------------------------------------------- /trace/microservice-simple-consumer-movie-trace/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8010 3 | spring: 4 | application: 5 | name: microservice-consumer-movie 6 | logging: 7 | level: 8 | org.springframework.cloud.sleuth: DEBUG -------------------------------------------------------------------------------- /trace/microservice-simple-provider-user-trace-elk/build/microservice-provider-user: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SpringForAll/spring-cloud-docker-microservice-book-code/c52d113288fa73ef06744155605889ca3553a121/trace/microservice-simple-provider-user-trace-elk/build/microservice-provider-user -------------------------------------------------------------------------------- /trace/microservice-simple-provider-user-trace-elk/src/main/java/com/itmuch/cloud/study/ProviderUserApplication.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ProviderUserApplication { 8 | public static void main(String[] args) { 9 | SpringApplication.run(ProviderUserApplication.class, args); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /trace/microservice-simple-provider-user-trace-elk/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.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.entity.User; 9 | import com.itmuch.cloud.study.repository.UserRepository; 10 | 11 | @RestController 12 | public class UserController { 13 | @Autowired 14 | private UserRepository userRepository; 15 | 16 | @GetMapping("/{id}") 17 | public User findById(@PathVariable Long id) { 18 | User findOne = this.userRepository.findOne(id); 19 | return findOne; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /trace/microservice-simple-provider-user-trace-elk/src/main/java/com/itmuch/cloud/study/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.entity; 2 | 3 | import java.math.BigDecimal; 4 | 5 | import javax.persistence.Column; 6 | import javax.persistence.Entity; 7 | import javax.persistence.GeneratedValue; 8 | import javax.persistence.GenerationType; 9 | import javax.persistence.Id; 10 | 11 | @Entity 12 | public class User { 13 | @Id 14 | @GeneratedValue(strategy = GenerationType.AUTO) 15 | private Long id; 16 | @Column 17 | private String username; 18 | @Column 19 | private String name; 20 | @Column 21 | private Integer age; 22 | @Column 23 | private BigDecimal balance; 24 | 25 | public Long getId() { 26 | return this.id; 27 | } 28 | 29 | public void setId(Long id) { 30 | this.id = id; 31 | } 32 | 33 | public String getUsername() { 34 | return this.username; 35 | } 36 | 37 | public void setUsername(String username) { 38 | this.username = username; 39 | } 40 | 41 | public String getName() { 42 | return this.name; 43 | } 44 | 45 | public void setName(String name) { 46 | this.name = name; 47 | } 48 | 49 | public Integer getAge() { 50 | return this.age; 51 | } 52 | 53 | public void setAge(Integer age) { 54 | this.age = age; 55 | } 56 | 57 | public BigDecimal getBalance() { 58 | return this.balance; 59 | } 60 | 61 | public void setBalance(BigDecimal balance) { 62 | this.balance = balance; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /trace/microservice-simple-provider-user-trace-elk/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.entity.User; 7 | 8 | @Repository 9 | public interface UserRepository extends JpaRepository { 10 | } 11 | -------------------------------------------------------------------------------- /trace/microservice-simple-provider-user-trace-elk/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8000 3 | spring: 4 | jpa: 5 | generate-ddl: false 6 | show-sql: true 7 | hibernate: 8 | ddl-auto: none 9 | datasource: # 指定数据源 10 | platform: h2 # 指定数据源类型 11 | schema: classpath:schema.sql # 指定h2数据库的建表脚本 12 | data: classpath:data.sql # 指定h2数据库的数据脚本 13 | logging: 14 | level: 15 | root: INFO 16 | org.springframework.cloud.sleuth: DEBUG 17 | # org.springframework.web.servlet.DispatcherServlet: DEBUG -------------------------------------------------------------------------------- /trace/microservice-simple-provider-user-trace-elk/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: microservice-provider-user 4 | 5 | # 注意:本例中的spring.application.name只能放在bootstrap.*文件中,不能放在application.*文件中,因为我们使用了自定义的logback-spring.xml。 6 | # 如果放在application.*文件中,自定义的logback文件将无法正确读取属性。 7 | # 详见:http://cloud.spring.io/spring-cloud-static/spring-cloud-sleuth/1.1.1.RELEASE/#_adding_to_the_project 上方的NOTE,内容如下: 8 | # If you’re using a custom logback-spring.xml then you have to pass the spring.application.name in bootstrap instead of application property file. Otherwise your custom logback file won’t read the property properly. -------------------------------------------------------------------------------- /trace/microservice-simple-provider-user-trace-elk/src/main/resources/data.sql: -------------------------------------------------------------------------------- 1 | insert into user (id, username, name, age, balance) values (1, 'account1', '张三', 20, 100.00); 2 | insert into user (id, username, name, age, balance) values (2, 'account2', '李四', 28, 180.00); 3 | insert into user (id, username, name, age, balance) values (3, 'account3', '王五', 32, 280.00); -------------------------------------------------------------------------------- /trace/microservice-simple-provider-user-trace-elk/src/main/resources/schema.sql: -------------------------------------------------------------------------------- 1 | drop table user if exists; 2 | create table user (id bigint generated by default as identity, username varchar(40), name varchar(20), age int(3), balance decimal(10,2), primary key (id)); -------------------------------------------------------------------------------- /trace/microservice-simple-provider-user-trace-zipkin-stream/src/main/java/com/itmuch/cloud/study/ProviderUserApplication.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ProviderUserApplication { 8 | public static void main(String[] args) { 9 | SpringApplication.run(ProviderUserApplication.class, args); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /trace/microservice-simple-provider-user-trace-zipkin-stream/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.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.entity.User; 9 | import com.itmuch.cloud.study.repository.UserRepository; 10 | 11 | @RestController 12 | public class UserController { 13 | @Autowired 14 | private UserRepository userRepository; 15 | 16 | @GetMapping("/{id}") 17 | public User findById(@PathVariable Long id) { 18 | User findOne = this.userRepository.findOne(id); 19 | return findOne; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /trace/microservice-simple-provider-user-trace-zipkin-stream/src/main/java/com/itmuch/cloud/study/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.entity; 2 | 3 | import java.math.BigDecimal; 4 | 5 | import javax.persistence.Column; 6 | import javax.persistence.Entity; 7 | import javax.persistence.GeneratedValue; 8 | import javax.persistence.GenerationType; 9 | import javax.persistence.Id; 10 | 11 | @Entity 12 | public class User { 13 | @Id 14 | @GeneratedValue(strategy = GenerationType.AUTO) 15 | private Long id; 16 | @Column 17 | private String username; 18 | @Column 19 | private String name; 20 | @Column 21 | private Integer age; 22 | @Column 23 | private BigDecimal balance; 24 | 25 | public Long getId() { 26 | return this.id; 27 | } 28 | 29 | public void setId(Long id) { 30 | this.id = id; 31 | } 32 | 33 | public String getUsername() { 34 | return this.username; 35 | } 36 | 37 | public void setUsername(String username) { 38 | this.username = username; 39 | } 40 | 41 | public String getName() { 42 | return this.name; 43 | } 44 | 45 | public void setName(String name) { 46 | this.name = name; 47 | } 48 | 49 | public Integer getAge() { 50 | return this.age; 51 | } 52 | 53 | public void setAge(Integer age) { 54 | this.age = age; 55 | } 56 | 57 | public BigDecimal getBalance() { 58 | return this.balance; 59 | } 60 | 61 | public void setBalance(BigDecimal balance) { 62 | this.balance = balance; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /trace/microservice-simple-provider-user-trace-zipkin-stream/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.entity.User; 7 | 8 | @Repository 9 | public interface UserRepository extends JpaRepository { 10 | } 11 | -------------------------------------------------------------------------------- /trace/microservice-simple-provider-user-trace-zipkin-stream/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8000 3 | spring: 4 | jpa: 5 | generate-ddl: false 6 | show-sql: true 7 | hibernate: 8 | ddl-auto: none 9 | datasource: # 指定数据源 10 | platform: h2 # 指定数据源类型 11 | schema: classpath:schema.sql # 指定h2数据库的建表脚本 12 | data: classpath:data.sql # 指定h2数据库的数据脚本 13 | application: 14 | name: microservice-provider-user 15 | sleuth: 16 | sampler: 17 | percentage: 1.0 18 | rabbitmq: 19 | host: localhost 20 | port: 5672 21 | username: guest 22 | password: guest -------------------------------------------------------------------------------- /trace/microservice-simple-provider-user-trace-zipkin-stream/src/main/resources/data.sql: -------------------------------------------------------------------------------- 1 | insert into user (id, username, name, age, balance) values (1, 'account1', '张三', 20, 100.00); 2 | insert into user (id, username, name, age, balance) values (2, 'account2', '李四', 28, 180.00); 3 | insert into user (id, username, name, age, balance) values (3, 'account3', '王五', 32, 280.00); -------------------------------------------------------------------------------- /trace/microservice-simple-provider-user-trace-zipkin-stream/src/main/resources/schema.sql: -------------------------------------------------------------------------------- 1 | drop table user if exists; 2 | create table user (id bigint generated by default as identity, username varchar(40), name varchar(20), age int(3), balance decimal(10,2), primary key (id)); -------------------------------------------------------------------------------- /trace/microservice-simple-provider-user-trace-zipkin/src/main/java/com/itmuch/cloud/study/ProviderUserApplication.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ProviderUserApplication { 8 | public static void main(String[] args) { 9 | SpringApplication.run(ProviderUserApplication.class, args); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /trace/microservice-simple-provider-user-trace-zipkin/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.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.entity.User; 9 | import com.itmuch.cloud.study.repository.UserRepository; 10 | 11 | @RestController 12 | public class UserController { 13 | @Autowired 14 | private UserRepository userRepository; 15 | 16 | @GetMapping("/{id}") 17 | public User findById(@PathVariable Long id) { 18 | User findOne = this.userRepository.findOne(id); 19 | return findOne; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /trace/microservice-simple-provider-user-trace-zipkin/src/main/java/com/itmuch/cloud/study/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.entity; 2 | 3 | import java.math.BigDecimal; 4 | 5 | import javax.persistence.Column; 6 | import javax.persistence.Entity; 7 | import javax.persistence.GeneratedValue; 8 | import javax.persistence.GenerationType; 9 | import javax.persistence.Id; 10 | 11 | @Entity 12 | public class User { 13 | @Id 14 | @GeneratedValue(strategy = GenerationType.AUTO) 15 | private Long id; 16 | @Column 17 | private String username; 18 | @Column 19 | private String name; 20 | @Column 21 | private Integer age; 22 | @Column 23 | private BigDecimal balance; 24 | 25 | public Long getId() { 26 | return this.id; 27 | } 28 | 29 | public void setId(Long id) { 30 | this.id = id; 31 | } 32 | 33 | public String getUsername() { 34 | return this.username; 35 | } 36 | 37 | public void setUsername(String username) { 38 | this.username = username; 39 | } 40 | 41 | public String getName() { 42 | return this.name; 43 | } 44 | 45 | public void setName(String name) { 46 | this.name = name; 47 | } 48 | 49 | public Integer getAge() { 50 | return this.age; 51 | } 52 | 53 | public void setAge(Integer age) { 54 | this.age = age; 55 | } 56 | 57 | public BigDecimal getBalance() { 58 | return this.balance; 59 | } 60 | 61 | public void setBalance(BigDecimal balance) { 62 | this.balance = balance; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /trace/microservice-simple-provider-user-trace-zipkin/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.entity.User; 7 | 8 | @Repository 9 | public interface UserRepository extends JpaRepository { 10 | } 11 | -------------------------------------------------------------------------------- /trace/microservice-simple-provider-user-trace-zipkin/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8000 3 | spring: 4 | jpa: 5 | generate-ddl: false 6 | show-sql: true 7 | hibernate: 8 | ddl-auto: none 9 | datasource: # 指定数据源 10 | platform: h2 # 指定数据源类型 11 | schema: classpath:schema.sql # 指定h2数据库的建表脚本 12 | data: classpath:data.sql # 指定h2数据库的数据脚本 13 | application: 14 | name: microservice-provider-user 15 | zipkin: 16 | base-url: http://localhost:9411 17 | sleuth: 18 | sampler: 19 | percentage: 1.0 -------------------------------------------------------------------------------- /trace/microservice-simple-provider-user-trace-zipkin/src/main/resources/data.sql: -------------------------------------------------------------------------------- 1 | insert into user (id, username, name, age, balance) values (1, 'account1', '张三', 20, 100.00); 2 | insert into user (id, username, name, age, balance) values (2, 'account2', '李四', 28, 180.00); 3 | insert into user (id, username, name, age, balance) values (3, 'account3', '王五', 32, 280.00); -------------------------------------------------------------------------------- /trace/microservice-simple-provider-user-trace-zipkin/src/main/resources/schema.sql: -------------------------------------------------------------------------------- 1 | drop table user if exists; 2 | create table user (id bigint generated by default as identity, username varchar(40), name varchar(20), age int(3), balance decimal(10,2), primary key (id)); -------------------------------------------------------------------------------- /trace/microservice-simple-provider-user-trace/src/main/java/com/itmuch/cloud/study/ProviderUserApplication.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ProviderUserApplication { 8 | public static void main(String[] args) { 9 | SpringApplication.run(ProviderUserApplication.class, args); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /trace/microservice-simple-provider-user-trace/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.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.entity.User; 9 | import com.itmuch.cloud.study.repository.UserRepository; 10 | 11 | @RestController 12 | public class UserController { 13 | @Autowired 14 | private UserRepository userRepository; 15 | 16 | @GetMapping("/{id}") 17 | public User findById(@PathVariable Long id) { 18 | User findOne = this.userRepository.findOne(id); 19 | return findOne; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /trace/microservice-simple-provider-user-trace/src/main/java/com/itmuch/cloud/study/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study.entity; 2 | 3 | import java.math.BigDecimal; 4 | 5 | import javax.persistence.Column; 6 | import javax.persistence.Entity; 7 | import javax.persistence.GeneratedValue; 8 | import javax.persistence.GenerationType; 9 | import javax.persistence.Id; 10 | 11 | @Entity 12 | public class User { 13 | @Id 14 | @GeneratedValue(strategy = GenerationType.AUTO) 15 | private Long id; 16 | @Column 17 | private String username; 18 | @Column 19 | private String name; 20 | @Column 21 | private Integer age; 22 | @Column 23 | private BigDecimal balance; 24 | 25 | public Long getId() { 26 | return this.id; 27 | } 28 | 29 | public void setId(Long id) { 30 | this.id = id; 31 | } 32 | 33 | public String getUsername() { 34 | return this.username; 35 | } 36 | 37 | public void setUsername(String username) { 38 | this.username = username; 39 | } 40 | 41 | public String getName() { 42 | return this.name; 43 | } 44 | 45 | public void setName(String name) { 46 | this.name = name; 47 | } 48 | 49 | public Integer getAge() { 50 | return this.age; 51 | } 52 | 53 | public void setAge(Integer age) { 54 | this.age = age; 55 | } 56 | 57 | public BigDecimal getBalance() { 58 | return this.balance; 59 | } 60 | 61 | public void setBalance(BigDecimal balance) { 62 | this.balance = balance; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /trace/microservice-simple-provider-user-trace/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.entity.User; 7 | 8 | @Repository 9 | public interface UserRepository extends JpaRepository { 10 | } 11 | -------------------------------------------------------------------------------- /trace/microservice-simple-provider-user-trace/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8000 3 | spring: 4 | jpa: 5 | generate-ddl: false 6 | show-sql: true 7 | hibernate: 8 | ddl-auto: none 9 | datasource: # 指定数据源 10 | platform: h2 # 指定数据源类型 11 | schema: classpath:schema.sql # 指定h2数据库的建表脚本 12 | data: classpath:data.sql # 指定h2数据库的数据脚本 13 | application: 14 | name: microservice-provider-user 15 | logging: 16 | level: 17 | root: INFO 18 | org.springframework.cloud.sleuth: DEBUG 19 | # org.springframework.web.servlet.DispatcherServlet: DEBUG -------------------------------------------------------------------------------- /trace/microservice-simple-provider-user-trace/src/main/resources/data.sql: -------------------------------------------------------------------------------- 1 | insert into user (id, username, name, age, balance) values (1, 'account1', '张三', 20, 100.00); 2 | insert into user (id, username, name, age, balance) values (2, 'account2', '李四', 28, 180.00); 3 | insert into user (id, username, name, age, balance) values (3, 'account3', '王五', 32, 280.00); -------------------------------------------------------------------------------- /trace/microservice-simple-provider-user-trace/src/main/resources/schema.sql: -------------------------------------------------------------------------------- 1 | drop table user if exists; 2 | create table user (id bigint generated by default as identity, username varchar(40), name varchar(20), age int(3), balance decimal(10,2), primary key (id)); -------------------------------------------------------------------------------- /trace/microservice-trace-zipkin-server-stream-elasticsearch/src/main/java/com/itmuch/cloud/study/ZipkinServerApplication.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.sleuth.zipkin.stream.EnableZipkinStreamServer; 6 | 7 | @SpringBootApplication 8 | @EnableZipkinStreamServer 9 | public class ZipkinServerApplication { 10 | public static void main(String[] args) { 11 | SpringApplication.run(ZipkinServerApplication.class, args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /trace/microservice-trace-zipkin-server-stream-elasticsearch/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9411 3 | spring: 4 | rabbitmq: 5 | host: localhost 6 | port: 5672 7 | username: guest 8 | password: guest 9 | zipkin: 10 | storage: 11 | type: elasticsearch 12 | elasticsearch: 13 | cluster: elasticsearch 14 | hosts: http://localhost:9200 15 | index: zipkin 16 | index-shards: 5 17 | index-replicas: 1 -------------------------------------------------------------------------------- /trace/microservice-trace-zipkin-server-stream/src/main/java/com/itmuch/cloud/study/ZipkinServerApplication.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.sleuth.zipkin.stream.EnableZipkinStreamServer; 6 | 7 | @SpringBootApplication 8 | @EnableZipkinStreamServer 9 | public class ZipkinServerApplication { 10 | public static void main(String[] args) { 11 | SpringApplication.run(ZipkinServerApplication.class, args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /trace/microservice-trace-zipkin-server-stream/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9411 3 | spring: 4 | rabbitmq: 5 | host: localhost 6 | port: 5672 7 | username: guest 8 | password: guest -------------------------------------------------------------------------------- /trace/microservice-trace-zipkin-server/src/main/java/com/itmuch/cloud/study/ZipkinServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.itmuch.cloud.study; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | import zipkin.server.EnableZipkinServer; 7 | 8 | @SpringBootApplication 9 | @EnableZipkinServer 10 | public class ZipkinServerApplication { 11 | public static void main(String[] args) { 12 | SpringApplication.run(ZipkinServerApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /trace/microservice-trace-zipkin-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9411 -------------------------------------------------------------------------------- /trace/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | com.itmuch.cloud 6 | microservice-trace-parent 7 | 0.0.1-SNAPSHOT 8 | pom 9 | 10 | 11 | 12 | microservice-simple-consumer-movie-trace 13 | microservice-simple-consumer-movie-trace-zipkin 14 | microservice-simple-provider-user-trace 15 | microservice-simple-provider-user-trace-elk 16 | microservice-simple-provider-user-trace-zipkin 17 | microservice-simple-provider-user-trace-zipkin-stream 18 | microservice-trace-zipkin-server 19 | microservice-trace-zipkin-server-stream 20 | microservice-trace-zipkin-server-stream-elasticsearch 21 | 22 | --------------------------------------------------------------------------------