├── section-01 └── order-service │ ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── microbucks │ │ │ └── orderservice │ │ │ ├── repository │ │ │ └── OrderRepository.java │ │ │ ├── OrderServiceApplication.java │ │ │ ├── model │ │ │ └── Order.java │ │ │ ├── runner │ │ │ └── DataInitializerRunner.java │ │ │ └── service │ │ │ └── OrderServiceController.java │ └── test │ │ └── java │ │ └── microbucks │ │ └── orderservice │ │ └── OrderServiceApplicationTests.java │ ├── .gitignore │ └── pom.xml ├── section-10 ├── hystrix-dashboard │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ └── application.properties │ │ │ └── java │ │ │ │ └── microbucks │ │ │ │ └── hystrixdashboard │ │ │ │ └── HystrixDashboardApplication.java │ │ └── test │ │ │ └── java │ │ │ └── microbucks │ │ │ └── hystrixdashboard │ │ │ └── HystrixDashboardApplicationTests.java │ ├── .gitignore │ └── pom.xml └── customer-service │ ├── src │ ├── main │ │ ├── resources │ │ │ ├── bootstrap.properties │ │ │ └── application.properties │ │ └── java │ │ │ └── microbucks │ │ │ └── customerservice │ │ │ ├── controller │ │ │ └── CustomerController.java │ │ │ ├── model │ │ │ └── Order.java │ │ │ └── CustomerServiceApplication.java │ └── test │ │ └── java │ │ └── microbucks │ │ └── customerservice │ │ └── CustomerServiceApplicationTests.java │ └── .gitignore ├── section-08 ├── order-service │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ ├── bootstrap.properties │ │ │ │ └── application.properties │ │ │ └── java │ │ │ │ └── microbucks │ │ │ │ └── orderservice │ │ │ │ ├── repository │ │ │ │ └── OrderRepository.java │ │ │ │ ├── model │ │ │ │ ├── Status.java │ │ │ │ └── Order.java │ │ │ │ └── OrderServiceApplication.java │ │ └── test │ │ │ └── java │ │ │ └── microbucks │ │ │ └── orderservice │ │ │ └── OrderServiceApplicationTests.java │ └── .gitignore ├── customer-service │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ ├── bootstrap.properties │ │ │ │ └── application.properties │ │ │ └── java │ │ │ │ └── microbucks │ │ │ │ └── customerservice │ │ │ │ ├── model │ │ │ │ └── Order.java │ │ │ │ └── CustomerServiceApplication.java │ │ └── test │ │ │ └── java │ │ │ └── microbucks │ │ │ └── customerservice │ │ │ └── CustomerServiceApplicationTests.java │ ├── .gitignore │ └── pom.xml └── eureka-server │ ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── microbucks │ │ │ └── eurekaserver │ │ │ └── EurekaServerApplication.java │ └── test │ │ └── java │ │ └── microbucks │ │ └── eurekaserver │ │ └── EurekaServerApplicationTests.java │ ├── .gitignore │ └── pom.xml ├── section-09 ├── order-service │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ ├── bootstrap.properties │ │ │ │ └── application.properties │ │ │ └── java │ │ │ │ └── microbucks │ │ │ │ └── orderservice │ │ │ │ ├── repository │ │ │ │ └── OrderRepository.java │ │ │ │ ├── model │ │ │ │ ├── Status.java │ │ │ │ └── Order.java │ │ │ │ └── OrderServiceApplication.java │ │ └── test │ │ │ └── java │ │ │ └── microbucks │ │ │ └── orderservice │ │ │ └── OrderServiceApplicationTests.java │ └── .gitignore └── customer-service │ ├── src │ ├── main │ │ ├── resources │ │ │ ├── bootstrap.properties │ │ │ └── application.properties │ │ └── java │ │ │ └── microbucks │ │ │ └── customerservice │ │ │ ├── model │ │ │ └── Order.java │ │ │ └── CustomerServiceApplication.java │ └── test │ │ └── java │ │ └── microbucks │ │ └── customerservice │ │ └── CustomerServiceApplicationTests.java │ └── .gitignore ├── section-14 ├── order-service │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ ├── bootstrap.properties │ │ │ │ └── application.properties │ │ │ └── java │ │ │ │ └── microbucks │ │ │ │ └── orderservice │ │ │ │ ├── repository │ │ │ │ └── OrderRepository.java │ │ │ │ ├── model │ │ │ │ ├── Status.java │ │ │ │ └── Order.java │ │ │ │ ├── stream │ │ │ │ ├── OrderStream.java │ │ │ │ └── StreamProcessor.java │ │ │ │ └── OrderServiceApplication.java │ │ └── test │ │ │ └── java │ │ │ └── microbucks │ │ │ └── orderservice │ │ │ └── OrderServiceApplicationTests.java │ └── .gitignore └── barista-service │ ├── .gitignore │ ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── microbucks │ │ │ ├── baristaservice │ │ │ ├── stream │ │ │ │ ├── BaristaStream.java │ │ │ │ └── StreamProcessor.java │ │ │ └── BaristaServiceApplication.java │ │ │ └── orderservice │ │ │ └── model │ │ │ └── Order.java │ └── test │ │ └── java │ │ └── microbucks │ │ └── baristaservice │ │ └── BaristaServiceApplicationTests.java │ └── pom.xml ├── section-15 ├── order-service │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ ├── bootstrap.properties │ │ │ │ └── application.properties │ │ │ └── java │ │ │ │ └── microbucks │ │ │ │ └── orderservice │ │ │ │ ├── repository │ │ │ │ └── OrderRepository.java │ │ │ │ ├── model │ │ │ │ ├── Status.java │ │ │ │ └── Order.java │ │ │ │ ├── stream │ │ │ │ ├── OrderStream.java │ │ │ │ └── StreamProcessor.java │ │ │ │ └── OrderServiceApplication.java │ │ └── test │ │ │ └── java │ │ │ └── microbucks │ │ │ └── orderservice │ │ │ └── OrderServiceApplicationTests.java │ └── .gitignore ├── customer-service │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ ├── bootstrap.properties │ │ │ │ └── application.properties │ │ │ └── java │ │ │ │ └── microbucks │ │ │ │ └── customerservice │ │ │ │ ├── controller │ │ │ │ └── CustomerController.java │ │ │ │ ├── model │ │ │ │ └── Order.java │ │ │ │ └── CustomerServiceApplication.java │ │ └── test │ │ │ └── java │ │ │ └── microbucks │ │ │ └── customerservice │ │ │ └── CustomerServiceApplicationTests.java │ └── .gitignore ├── zipkin-service │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ └── application.properties │ │ │ └── java │ │ │ │ └── microbucks │ │ │ │ └── zipkinservice │ │ │ │ └── ZipkinServiceApplication.java │ │ └── test │ │ │ └── java │ │ │ └── microbucks │ │ │ └── zipkinservice │ │ │ └── ZipkinServiceApplicationTests.java │ └── .gitignore └── barista-service │ ├── .gitignore │ └── src │ ├── test │ └── java │ │ └── microbucks │ │ └── baristaservice │ │ └── BaristaServiceApplicationTests.java │ └── main │ ├── resources │ └── application.properties │ └── java │ └── microbucks │ ├── baristaservice │ ├── stream │ │ ├── BaristaStream.java │ │ └── StreamProcessor.java │ └── BaristaServiceApplication.java │ └── orderservice │ └── model │ └── Order.java ├── section-16 ├── order-service │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ ├── bootstrap.properties │ │ │ │ └── application.properties │ │ │ └── java │ │ │ │ └── microbucks │ │ │ │ └── orderservice │ │ │ │ ├── repository │ │ │ │ └── OrderRepository.java │ │ │ │ ├── model │ │ │ │ ├── Status.java │ │ │ │ └── Order.java │ │ │ │ ├── stream │ │ │ │ ├── OrderStream.java │ │ │ │ └── StreamProcessor.java │ │ │ │ └── OrderServiceApplication.java │ │ └── test │ │ │ └── java │ │ │ └── microbucks │ │ │ └── orderservice │ │ │ └── OrderServiceApplicationTests.java │ └── .gitignore ├── customer-service │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ ├── bootstrap.properties │ │ │ │ └── application.properties │ │ │ └── java │ │ │ │ └── microbucks │ │ │ │ └── customerservice │ │ │ │ ├── controller │ │ │ │ └── CustomerController.java │ │ │ │ └── model │ │ │ │ └── Order.java │ │ └── test │ │ │ └── java │ │ │ └── microbucks │ │ │ └── customerservice │ │ │ └── CustomerServiceApplicationTests.java │ └── .gitignore └── oauth-service │ ├── .gitignore │ └── src │ ├── main │ ├── resources │ │ └── application.properties │ └── java │ │ └── microbucks │ │ └── oauthservice │ │ ├── OauthServiceApplication.java │ │ └── AuthorizationServerConfiguration.java │ └── test │ └── java │ └── microbucks │ └── oauthservice │ └── OauthServiceApplicationTests.java ├── section-11 └── customer-service │ ├── src │ ├── main │ │ ├── resources │ │ │ ├── bootstrap.properties │ │ │ └── application.properties │ │ └── java │ │ │ └── microbucks │ │ │ └── customerservice │ │ │ ├── CustomerServiceApplication.java │ │ │ ├── model │ │ │ └── Order.java │ │ │ └── OrderService.java │ └── test │ │ └── java │ │ └── microbucks │ │ └── customerservice │ │ └── CustomerServiceApplicationTests.java │ └── .gitignore ├── section-05 ├── customer-service │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ ├── application.properties │ │ │ │ └── META-INF │ │ │ │ │ └── spring │ │ │ │ │ └── applicationContext.xml │ │ │ └── java │ │ │ │ └── microbucks │ │ │ │ ├── orderservice │ │ │ │ ├── service │ │ │ │ │ └── OrderServiceFacade.java │ │ │ │ └── model │ │ │ │ │ └── Order.java │ │ │ │ └── customerservice │ │ │ │ ├── CustomerServiceApplication.java │ │ │ │ └── runner │ │ │ │ └── OrderServiceGetRunner.java │ │ └── test │ │ │ └── java │ │ │ └── microbucks │ │ │ └── customerservice │ │ │ └── CustomerServiceApplicationTests.java │ ├── .gitignore │ └── pom.xml └── order-service │ ├── src │ ├── main │ │ ├── resources │ │ │ ├── application.properties │ │ │ └── META-INF │ │ │ │ └── spring │ │ │ │ └── applicationContext.xml │ │ └── java │ │ │ └── microbucks │ │ │ └── orderservice │ │ │ ├── repository │ │ │ └── OrderRepository.java │ │ │ ├── service │ │ │ ├── OrderServiceFacade.java │ │ │ ├── OrderServiceImpl.java │ │ │ └── OrderServiceController.java │ │ │ ├── OrderServiceApplication.java │ │ │ ├── health │ │ │ └── OrderHealthIndicator.java │ │ │ ├── model │ │ │ └── Order.java │ │ │ └── runner │ │ │ └── DataInitializerRunner.java │ └── test │ │ └── java │ │ └── microbucks │ │ └── orderservice │ │ └── OrderServiceApplicationTests.java │ └── .gitignore ├── section-06 ├── customer-service │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ └── application.properties │ │ │ ├── proto │ │ │ │ ├── order_model.proto │ │ │ │ └── order_service.proto │ │ │ └── java │ │ │ │ └── microbucks │ │ │ │ └── customerservice │ │ │ │ ├── CustomerServiceApplication.java │ │ │ │ └── runner │ │ │ │ └── OrderServiceGetRunner.java │ │ └── test │ │ │ └── java │ │ │ └── microbucks │ │ │ └── customerservice │ │ │ └── CustomerServiceApplicationTests.java │ └── .gitignore └── order-service │ ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ ├── java │ │ │ └── microbucks │ │ │ │ └── orderservice │ │ │ │ ├── repository │ │ │ │ └── OrderRepository.java │ │ │ │ ├── OrderServiceApplication.java │ │ │ │ ├── runner │ │ │ │ ├── GrpcServerRunner.java │ │ │ │ └── DataInitializerRunner.java │ │ │ │ ├── model │ │ │ │ └── Order.java │ │ │ │ └── service │ │ │ │ └── OrderServiceImpl.java │ │ └── proto │ │ │ ├── order_model.proto │ │ │ └── order_service.proto │ └── test │ │ └── java │ │ └── microbucks │ │ └── orderservice │ │ └── OrderServiceApplicationTests.java │ └── .gitignore ├── section-07 ├── customer-service │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ └── application.properties │ │ │ └── java │ │ │ │ └── microbucks │ │ │ │ └── customerservice │ │ │ │ ├── CustomerServiceApplication.java │ │ │ │ └── model │ │ │ │ └── Order.java │ │ └── test │ │ │ └── java │ │ │ └── microbucks │ │ │ └── customerservice │ │ │ └── CustomerServiceApplicationTests.java │ ├── .gitignore │ └── pom.xml └── order-service │ ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── microbucks │ │ │ └── orderservice │ │ │ ├── repository │ │ │ └── OrderRepository.java │ │ │ ├── model │ │ │ ├── Status.java │ │ │ └── Order.java │ │ │ └── OrderServiceApplication.java │ └── test │ │ └── java │ │ └── microbucks │ │ └── orderservice │ │ └── OrderServiceApplicationTests.java │ ├── .gitignore │ └── pom.xml ├── section-03 ├── customer-service │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ └── application.properties │ │ │ └── java │ │ │ │ └── microbucks │ │ │ │ └── customerservice │ │ │ │ ├── model │ │ │ │ └── Order.java │ │ │ │ ├── CustomerServiceApplication.java │ │ │ │ └── runner │ │ │ │ └── OrderServiceGetRunner.java │ │ └── test │ │ │ └── java │ │ │ └── microbucks │ │ │ └── customerservice │ │ │ └── CustomerServiceApplicationTests.java │ ├── .gitignore │ └── pom.xml └── order-service │ ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ ├── java │ │ │ └── microbucks │ │ │ │ └── orderservice │ │ │ │ ├── repository │ │ │ │ └── OrderRepository.java │ │ │ │ ├── OrderServiceApplication.java │ │ │ │ ├── health │ │ │ │ └── OrderHealthIndicator.java │ │ │ │ ├── model │ │ │ │ └── Order.java │ │ │ │ ├── Swagger2Configuration.java │ │ │ │ ├── runner │ │ │ │ └── DataInitializerRunner.java │ │ │ │ └── service │ │ │ │ └── OrderServiceController.java │ │ └── asciidoc │ │ │ └── main.adoc │ └── test │ │ └── java │ │ └── microbucks │ │ └── orderservice │ │ ├── repository │ │ └── OrderRepositoryTest.java │ │ ├── runner │ │ └── DataInitializerRunnerTest.java │ │ ├── OrderServiceApplicationTests.java │ │ └── service │ │ └── OrderServiceControllerTest.java │ └── .gitignore ├── section-04 ├── customer-service │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ └── application.properties │ │ │ └── java │ │ │ │ └── microbucks │ │ │ │ └── customerservice │ │ │ │ ├── model │ │ │ │ └── Order.java │ │ │ │ ├── CustomerServiceApplication.java │ │ │ │ └── runner │ │ │ │ └── OrderServiceGetRunner.java │ │ └── test │ │ │ └── java │ │ │ └── microbucks │ │ │ └── customerservice │ │ │ └── CustomerServiceApplicationTests.java │ ├── .gitignore │ └── pom.xml └── order-service │ ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── microbucks │ │ │ └── orderservice │ │ │ ├── OrderServiceApplication.java │ │ │ ├── repository │ │ │ └── OrderRepository.java │ │ │ ├── health │ │ │ └── OrderHealthIndicator.java │ │ │ ├── model │ │ │ └── Order.java │ │ │ ├── service │ │ │ └── OrderServiceController.java │ │ │ └── runner │ │ │ └── DataInitializerRunner.java │ └── test │ │ └── java │ │ └── microbucks │ │ └── orderservice │ │ ├── repository │ │ └── OrderRepositoryTest.java │ │ ├── runner │ │ └── DataInitializerRunnerTest.java │ │ ├── OrderServiceApplicationTests.java │ │ └── service │ │ └── OrderServiceControllerTest.java │ └── .gitignore ├── section-12 └── zuul-gateway │ ├── .mvn │ └── wrapper │ │ └── maven-wrapper.properties │ ├── .gitignore │ └── src │ ├── test │ └── java │ │ └── microbucks │ │ └── zuulgateway │ │ └── ZuulGatewayApplicationTests.java │ └── main │ ├── resources │ └── application.properties │ └── java │ └── microbucks │ └── zuulgateway │ ├── ZuulGatewayApplication.java │ └── LogFilter.java ├── section-13 ├── config-server │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ ├── bootstrap.properties │ │ │ │ └── application.properties │ │ │ └── java │ │ │ │ └── microbucks │ │ │ │ └── configserver │ │ │ │ └── ConfigServerApplication.java │ │ └── test │ │ │ └── java │ │ │ └── microbucks │ │ │ └── configserver │ │ │ └── ConfigServerApplicationTests.java │ └── .gitignore └── order-service │ ├── src │ ├── main │ │ ├── resources │ │ │ ├── application.properties │ │ │ └── bootstrap.properties │ │ └── java │ │ │ └── microbucks │ │ │ └── orderservice │ │ │ ├── repository │ │ │ └── OrderRepository.java │ │ │ ├── model │ │ │ ├── Status.java │ │ │ └── Order.java │ │ │ ├── OrderServiceApplication.java │ │ │ └── config │ │ │ ├── CoffeeProperties.java │ │ │ └── CoffeePrinterRunner.java │ └── test │ │ └── java │ │ └── microbucks │ │ └── orderservice │ │ └── OrderServiceApplicationTests.java │ └── .gitignore ├── section-02 └── order-service │ ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── microbucks │ │ │ └── orderservice │ │ │ ├── repository │ │ │ └── OrderRepository.java │ │ │ ├── OrderServiceApplication.java │ │ │ ├── health │ │ │ └── OrderHealthIndicator.java │ │ │ ├── model │ │ │ └── Order.java │ │ │ ├── service │ │ │ └── OrderServiceController.java │ │ │ └── runner │ │ │ └── DataInitializerRunner.java │ └── test │ │ └── java │ │ └── microbucks │ │ └── orderservice │ │ ├── repository │ │ └── OrderRepositoryTest.java │ │ ├── runner │ │ └── DataInitializerRunnerTest.java │ │ ├── OrderServiceApplicationTests.java │ │ └── service │ │ └── OrderServiceControllerTest.java │ └── .gitignore ├── .gitignore └── README.md /section-01/order-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /section-10/hystrix-dashboard/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8082 -------------------------------------------------------------------------------- /section-08/order-service/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=order-service -------------------------------------------------------------------------------- /section-09/order-service/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=order-service -------------------------------------------------------------------------------- /section-14/order-service/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=order-service -------------------------------------------------------------------------------- /section-15/order-service/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=order-service -------------------------------------------------------------------------------- /section-16/order-service/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=order-service -------------------------------------------------------------------------------- /section-08/customer-service/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=customer-service -------------------------------------------------------------------------------- /section-09/customer-service/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=customer-service -------------------------------------------------------------------------------- /section-10/customer-service/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=customer-service -------------------------------------------------------------------------------- /section-11/customer-service/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=customer-service -------------------------------------------------------------------------------- /section-15/customer-service/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=customer-service -------------------------------------------------------------------------------- /section-16/customer-service/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=customer-service -------------------------------------------------------------------------------- /section-05/customer-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | app.name=customer-service 2 | server.port=9070 3 | -------------------------------------------------------------------------------- /section-06/customer-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | app.name=customer-service 2 | server.port=9070 3 | grpc.server=127.0.0.1 4 | grpc.port=8888 -------------------------------------------------------------------------------- /section-07/customer-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | app.name=customer-service 2 | server.port=8081 3 | 4 | orderservice.url=http://localhost:8080 -------------------------------------------------------------------------------- /section-08/customer-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | app.name=customer-service 2 | spring.application.name=customer-service 3 | server.port=8081 4 | -------------------------------------------------------------------------------- /section-11/customer-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | app.name=customer-service 2 | spring.application.name=customer-service 3 | server.port=8081 4 | -------------------------------------------------------------------------------- /section-03/customer-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | app.name=customer-service 2 | server.port=9070 3 | 4 | orderservice.url=http://localhost:9080/orders -------------------------------------------------------------------------------- /section-04/customer-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | app.name=customer-service 2 | server.port=9070 3 | 4 | orderservice.url=http://localhost:9080/orders -------------------------------------------------------------------------------- /section-12/zuul-gateway/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip 2 | -------------------------------------------------------------------------------- /section-07/order-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | app.name=order-service 2 | server.port=8080 3 | spring.output.ansi.enabled=ALWAYS 4 | management.security.enabled=false -------------------------------------------------------------------------------- /section-08/eureka-server/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | app.name=microbucks-eureka 2 | server.port=8761 3 | 4 | eureka.client.register-with-eureka=false 5 | eureka.client.fetch-registry=false -------------------------------------------------------------------------------- /section-08/order-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | app.name=order-service 2 | spring.application.name=order-service 3 | server.port=8080 4 | spring.output.ansi.enabled=ALWAYS 5 | management.security.enabled=false 6 | -------------------------------------------------------------------------------- /section-15/zipkin-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=zipkin-service 2 | server.port=9411 3 | 4 | spring.rabbitmq.host=localhost 5 | spring.rabbitmq.port=5672 6 | spring.rabbitmq.username=guest 7 | spring.rabbitmq.password=guest -------------------------------------------------------------------------------- /section-13/config-server/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=configserver 2 | security.user.password=pwd 3 | security.basic.enabled=false 4 | #spring.cloud.zookeeper.connect-string=localhost:2181 5 | eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/ 6 | encrypt.key=MYKEY -------------------------------------------------------------------------------- /section-13/order-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | app.name=order-service 2 | spring.application.name=order-service 3 | server.port=8080 4 | spring.output.ansi.enabled=ALWAYS 5 | management.security.enabled=false 6 | 7 | # used for zookeeper 8 | spring.cloud.zookeeper.connect-string=localhost:2181 9 | -------------------------------------------------------------------------------- /section-02/order-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | app.name=order-service 2 | spring.output.ansi.enabled=ALWAYS 3 | spring.main.banner-mode=OFF 4 | barista.name=Master${random.int} 5 | server.port=9080 6 | management.port=9081 7 | management.context-path=/management 8 | management.security.enabled=false 9 | -------------------------------------------------------------------------------- /section-03/order-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | app.name=order-service 2 | spring.output.ansi.enabled=ALWAYS 3 | spring.main.banner-mode=OFF 4 | barista.name=Master${random.int} 5 | server.port=9080 6 | management.port=9081 7 | management.context-path=/management 8 | management.security.enabled=false 9 | -------------------------------------------------------------------------------- /section-04/order-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | app.name=order-service 2 | spring.output.ansi.enabled=ALWAYS 3 | spring.main.banner-mode=OFF 4 | barista.name=Master${random.int} 5 | server.port=9080 6 | management.port=9081 7 | management.context-path=/management 8 | management.security.enabled=false 9 | -------------------------------------------------------------------------------- /section-05/order-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | app.name=order-service 2 | spring.output.ansi.enabled=ALWAYS 3 | spring.main.banner-mode=OFF 4 | barista.name=Master${random.int} 5 | server.port=9080 6 | management.port=9081 7 | management.context-path=/management 8 | management.security.enabled=false 9 | -------------------------------------------------------------------------------- /section-06/order-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | app.name=order-service 2 | spring.output.ansi.enabled=ALWAYS 3 | spring.main.banner-mode=OFF 4 | barista.name=Master${random.int} 5 | server.port=9080 6 | management.port=9081 7 | management.context-path=/management 8 | management.security.enabled=false 9 | grpc.port=8888 -------------------------------------------------------------------------------- /section-01/order-service/src/main/java/microbucks/orderservice/repository/OrderRepository.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.repository; 2 | 3 | import microbucks.orderservice.model.Order; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | public interface OrderRepository extends JpaRepository { 7 | } 8 | -------------------------------------------------------------------------------- /section-02/order-service/src/main/java/microbucks/orderservice/repository/OrderRepository.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.repository; 2 | 3 | import microbucks.orderservice.model.Order; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | public interface OrderRepository extends JpaRepository { 7 | } 8 | -------------------------------------------------------------------------------- /section-03/order-service/src/main/java/microbucks/orderservice/repository/OrderRepository.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.repository; 2 | 3 | import microbucks.orderservice.model.Order; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | public interface OrderRepository extends JpaRepository { 7 | } 8 | -------------------------------------------------------------------------------- /section-05/order-service/src/main/java/microbucks/orderservice/repository/OrderRepository.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.repository; 2 | 3 | import microbucks.orderservice.model.Order; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | public interface OrderRepository extends JpaRepository { 7 | } 8 | -------------------------------------------------------------------------------- /section-06/order-service/src/main/java/microbucks/orderservice/repository/OrderRepository.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.repository; 2 | 3 | import microbucks.orderservice.model.Order; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | public interface OrderRepository extends JpaRepository { 7 | } 8 | -------------------------------------------------------------------------------- /section-07/order-service/src/main/java/microbucks/orderservice/repository/OrderRepository.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.repository; 2 | 3 | import microbucks.orderservice.model.Order; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | public interface OrderRepository extends JpaRepository { 7 | } 8 | -------------------------------------------------------------------------------- /section-08/order-service/src/main/java/microbucks/orderservice/repository/OrderRepository.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.repository; 2 | 3 | import microbucks.orderservice.model.Order; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | public interface OrderRepository extends JpaRepository { 7 | } 8 | -------------------------------------------------------------------------------- /section-09/order-service/src/main/java/microbucks/orderservice/repository/OrderRepository.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.repository; 2 | 3 | import microbucks.orderservice.model.Order; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | public interface OrderRepository extends JpaRepository { 7 | } 8 | -------------------------------------------------------------------------------- /section-13/order-service/src/main/java/microbucks/orderservice/repository/OrderRepository.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.repository; 2 | 3 | import microbucks.orderservice.model.Order; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | public interface OrderRepository extends JpaRepository { 7 | } 8 | -------------------------------------------------------------------------------- /section-14/order-service/src/main/java/microbucks/orderservice/repository/OrderRepository.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.repository; 2 | 3 | import microbucks.orderservice.model.Order; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | public interface OrderRepository extends JpaRepository { 7 | } 8 | -------------------------------------------------------------------------------- /section-15/order-service/src/main/java/microbucks/orderservice/repository/OrderRepository.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.repository; 2 | 3 | import microbucks.orderservice.model.Order; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | public interface OrderRepository extends JpaRepository { 7 | } 8 | -------------------------------------------------------------------------------- /section-16/order-service/src/main/java/microbucks/orderservice/repository/OrderRepository.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.repository; 2 | 3 | import microbucks.orderservice.model.Order; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | public interface OrderRepository extends JpaRepository { 7 | } 8 | -------------------------------------------------------------------------------- /section-05/order-service/src/main/java/microbucks/orderservice/service/OrderServiceFacade.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.service; 2 | 3 | import microbucks.orderservice.model.Order; 4 | 5 | import java.util.List; 6 | 7 | public interface OrderServiceFacade { 8 | List getAllOrders(); 9 | Order getOrder(Long id); 10 | } 11 | -------------------------------------------------------------------------------- /section-05/customer-service/src/main/java/microbucks/orderservice/service/OrderServiceFacade.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.service; 2 | 3 | import microbucks.orderservice.model.Order; 4 | 5 | import java.util.List; 6 | 7 | public interface OrderServiceFacade { 8 | List getAllOrders(); 9 | Order getOrder(Long id); 10 | } 11 | -------------------------------------------------------------------------------- /section-07/order-service/src/main/java/microbucks/orderservice/model/Status.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.model; 2 | 3 | public class Status { 4 | public static final int INIT =0; 5 | public static final int PAYED = 1; 6 | public static final int PREPARING = 2; 7 | public static final int READY = 3; 8 | public static final int TAKEN = 4; 9 | } 10 | -------------------------------------------------------------------------------- /section-08/order-service/src/main/java/microbucks/orderservice/model/Status.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.model; 2 | 3 | public class Status { 4 | public static final int INIT =0; 5 | public static final int PAYED = 1; 6 | public static final int PREPARING = 2; 7 | public static final int READY = 3; 8 | public static final int TAKEN = 4; 9 | } 10 | -------------------------------------------------------------------------------- /section-09/order-service/src/main/java/microbucks/orderservice/model/Status.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.model; 2 | 3 | public class Status { 4 | public static final int INIT =0; 5 | public static final int PAYED = 1; 6 | public static final int PREPARING = 2; 7 | public static final int READY = 3; 8 | public static final int TAKEN = 4; 9 | } 10 | -------------------------------------------------------------------------------- /section-13/order-service/src/main/java/microbucks/orderservice/model/Status.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.model; 2 | 3 | public class Status { 4 | public static final int INIT =0; 5 | public static final int PAYED = 1; 6 | public static final int PREPARING = 2; 7 | public static final int READY = 3; 8 | public static final int TAKEN = 4; 9 | } 10 | -------------------------------------------------------------------------------- /section-14/order-service/src/main/java/microbucks/orderservice/model/Status.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.model; 2 | 3 | public class Status { 4 | public static final int INIT =0; 5 | public static final int PAYED = 1; 6 | public static final int PREPARING = 2; 7 | public static final int READY = 3; 8 | public static final int TAKEN = 4; 9 | } 10 | -------------------------------------------------------------------------------- /section-15/order-service/src/main/java/microbucks/orderservice/model/Status.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.model; 2 | 3 | public class Status { 4 | public static final int INIT =0; 5 | public static final int PAYED = 1; 6 | public static final int PREPARING = 2; 7 | public static final int READY = 3; 8 | public static final int TAKEN = 4; 9 | } 10 | -------------------------------------------------------------------------------- /section-16/order-service/src/main/java/microbucks/orderservice/model/Status.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.model; 2 | 3 | public class Status { 4 | public static final int INIT =0; 5 | public static final int PAYED = 1; 6 | public static final int PREPARING = 2; 7 | public static final int READY = 3; 8 | public static final int TAKEN = 4; 9 | } 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.ear 17 | *.zip 18 | *.tar.gz 19 | *.rar 20 | 21 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 22 | hs_err_pid* 23 | -------------------------------------------------------------------------------- /section-01/order-service/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /section-02/order-service/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /section-03/customer-service/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /section-03/order-service/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /section-04/customer-service/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /section-04/order-service/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /section-05/customer-service/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /section-05/order-service/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /section-06/customer-service/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /section-06/order-service/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /section-07/customer-service/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /section-07/order-service/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /section-08/customer-service/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /section-08/eureka-server/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /section-08/order-service/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /section-09/customer-service/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /section-09/order-service/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /section-10/customer-service/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /section-11/customer-service/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /section-12/zuul-gateway/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /section-13/config-server/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /section-13/order-service/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /section-14/barista-service/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /section-14/order-service/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /section-15/barista-service/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /section-15/customer-service/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /section-15/order-service/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /section-15/zipkin-service/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /section-16/customer-service/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /section-16/oauth-service/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /section-16/order-service/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /section-10/hystrix-dashboard/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /section-13/order-service/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=order-service 2 | #spring.cloud.config.uri=http://user:pwd@localhost:8000 3 | 4 | spring.cloud.config.discovery.enabled=true 5 | spring.cloud.config.discovery.serviceId=configserver 6 | eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/ 7 | #spring.cloud.zookeeper.connect-string=localhost:2181 8 | -------------------------------------------------------------------------------- /section-16/oauth-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=oauth-service 2 | 3 | server.port=7000 4 | 5 | eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/ 6 | 7 | spring.rabbitmq.host=localhost 8 | spring.rabbitmq.port=5672 9 | spring.rabbitmq.username=guest 10 | spring.rabbitmq.password=guest 11 | 12 | spring.sleuth.sampler.percentage=1 13 | -------------------------------------------------------------------------------- /section-09/customer-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | app.name=customer-service 2 | spring.application.name=customer-service 3 | server.port=8081 4 | 5 | # used for zookeeper 6 | spring.cloud.zookeeper.connect-string=localhost:2181 7 | 8 | # used for consul 9 | spring.cloud.consul.host=localhost 10 | spring.cloud.consul.port=8500 11 | spring.cloud.consul.discovery.preferIpAddress=true 12 | -------------------------------------------------------------------------------- /section-13/config-server/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # Spring Cloud默认用这个ServiceId作为配置中心 2 | spring.application.name=configserver 3 | 4 | server.port=8000 5 | management.security.enabled=false 6 | security.user.password=pwd 7 | 8 | spring.cloud.config.server.git.uri=/Users/digitalsonic/Codes/git-config/ 9 | 10 | #encrypt.key=MYKEY 11 | 12 | #spring.cloud.zookeeper.connect-string=localhost:2181 13 | 14 | -------------------------------------------------------------------------------- /section-10/customer-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | app.name=customer-service 2 | spring.application.name=customer-service 3 | server.port=8081 4 | management.security.enabled=false 5 | 6 | # used for zookeeper 7 | spring.cloud.zookeeper.connect-string=localhost:2181 8 | 9 | # used for consul 10 | spring.cloud.consul.host=localhost 11 | spring.cloud.consul.port=8500 12 | spring.cloud.consul.discovery.preferIpAddress=true 13 | -------------------------------------------------------------------------------- /section-06/order-service/src/main/java/microbucks/orderservice/OrderServiceApplication.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class OrderServiceApplication { 8 | public static void main(String[] args) { 9 | SpringApplication.run(OrderServiceApplication.class, args); 10 | } 11 | } -------------------------------------------------------------------------------- /section-15/customer-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | app.name=customer-service 2 | spring.application.name=customer-service 3 | server.port=8081 4 | management.security.enabled=false 5 | 6 | spring.sleuth.sampler.percentage=1 7 | 8 | spring.rabbitmq.host=localhost 9 | spring.rabbitmq.port=5672 10 | spring.rabbitmq.username=guest 11 | spring.rabbitmq.password=guest 12 | 13 | #hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=2000 -------------------------------------------------------------------------------- /section-09/order-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | app.name=order-service 2 | spring.application.name=order-service 3 | server.port=8080 4 | spring.output.ansi.enabled=ALWAYS 5 | management.security.enabled=false 6 | 7 | # used for zookeeper 8 | spring.cloud.zookeeper.connect-string=localhost:2181 9 | 10 | # used for consul 11 | spring.cloud.consul.host=localhost 12 | spring.cloud.consul.port=8500 13 | spring.cloud.consul.discovery.preferIpAddress=true 14 | -------------------------------------------------------------------------------- /section-01/order-service/src/main/java/microbucks/orderservice/OrderServiceApplication.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class OrderServiceApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(OrderServiceApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /section-02/order-service/src/main/java/microbucks/orderservice/OrderServiceApplication.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class OrderServiceApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(OrderServiceApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /section-03/order-service/src/main/java/microbucks/orderservice/OrderServiceApplication.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class OrderServiceApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(OrderServiceApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /section-04/order-service/src/main/java/microbucks/orderservice/OrderServiceApplication.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class OrderServiceApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(OrderServiceApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /section-07/order-service/src/main/java/microbucks/orderservice/OrderServiceApplication.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class OrderServiceApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(OrderServiceApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /section-14/barista-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=barista-service 2 | server.port=8081 3 | 4 | barista.name=digitalsonic 5 | 6 | spring.rabbitmq.host=localhost 7 | spring.rabbitmq.port=5672 8 | spring.rabbitmq.username=guest 9 | spring.rabbitmq.password=guest 10 | 11 | spring.cloud.stream.bindinds.default.binder=rabbit 12 | spring.cloud.stream.binders.rabbit.type=rabbit 13 | 14 | spring.cloud.stream.bindings.barista.group=barista-service -------------------------------------------------------------------------------- /section-12/zuul-gateway/src/test/java/microbucks/zuulgateway/ZuulGatewayApplicationTests.java: -------------------------------------------------------------------------------- 1 | package microbucks.zuulgateway; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ZuulGatewayApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /section-01/order-service/src/test/java/microbucks/orderservice/OrderServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class OrderServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /section-06/order-service/src/main/proto/order_model.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package microbucks.orderservice.service; 4 | 5 | import "google/protobuf/timestamp.proto"; 6 | 7 | option java_package = "microbucks.orderservice.service"; 8 | option java_outer_classname = "OrderModel"; 9 | 10 | message Order { 11 | int64 id = 1; 12 | string customer = 2; 13 | string barista = 3; 14 | google.protobuf.Timestamp createTime = 4; 15 | google.protobuf.Timestamp modifyTime = 5; 16 | } 17 | -------------------------------------------------------------------------------- /section-07/order-service/src/test/java/microbucks/orderservice/OrderServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class OrderServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /section-08/eureka-server/src/test/java/microbucks/eurekaserver/EurekaServerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package microbucks.eurekaserver; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class EurekaServerApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /section-08/order-service/src/test/java/microbucks/orderservice/OrderServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class OrderServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /section-09/order-service/src/test/java/microbucks/orderservice/OrderServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class OrderServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /section-13/config-server/src/test/java/microbucks/configserver/ConfigServerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package microbucks.configserver; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ConfigServerApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /section-13/order-service/src/test/java/microbucks/orderservice/OrderServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class OrderServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /section-14/order-service/src/test/java/microbucks/orderservice/OrderServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class OrderServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /section-15/order-service/src/test/java/microbucks/orderservice/OrderServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class OrderServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /section-16/oauth-service/src/test/java/microbucks/oauthservice/OauthServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package microbucks.oauthservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class OauthServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /section-16/order-service/src/test/java/microbucks/orderservice/OrderServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class OrderServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /section-06/customer-service/src/main/proto/order_model.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package microbucks.orderservice.service; 4 | 5 | import "google/protobuf/timestamp.proto"; 6 | 7 | option java_package = "microbucks.orderservice.service"; 8 | option java_outer_classname = "OrderModel"; 9 | 10 | message Order { 11 | int64 id = 1; 12 | string customer = 2; 13 | string barista = 3; 14 | google.protobuf.Timestamp createTime = 4; 15 | google.protobuf.Timestamp modifyTime = 5; 16 | } 17 | -------------------------------------------------------------------------------- /section-15/zipkin-service/src/test/java/microbucks/zipkinservice/ZipkinServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package microbucks.zipkinservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ZipkinServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /section-14/barista-service/src/test/java/microbucks/baristaservice/BaristaServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package microbucks.baristaservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class BaristaServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /section-15/barista-service/src/test/java/microbucks/baristaservice/BaristaServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package microbucks.baristaservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class BaristaServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /section-03/customer-service/src/test/java/microbucks/customerservice/CustomerServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package microbucks.customerservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class CustomerServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /section-04/customer-service/src/test/java/microbucks/customerservice/CustomerServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package microbucks.customerservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class CustomerServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /section-05/customer-service/src/test/java/microbucks/customerservice/CustomerServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package microbucks.customerservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class CustomerServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /section-06/customer-service/src/main/java/microbucks/customerservice/CustomerServiceApplication.java: -------------------------------------------------------------------------------- 1 | package microbucks.customerservice; 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication; 4 | import org.springframework.boot.builder.SpringApplicationBuilder; 5 | 6 | @SpringBootApplication 7 | public class CustomerServiceApplication { 8 | 9 | public static void main(String[] args) { 10 | new SpringApplicationBuilder(CustomerServiceApplication.class).web(false).run(args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /section-06/customer-service/src/test/java/microbucks/customerservice/CustomerServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package microbucks.customerservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class CustomerServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /section-07/customer-service/src/test/java/microbucks/customerservice/CustomerServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package microbucks.customerservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class CustomerServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /section-08/customer-service/src/test/java/microbucks/customerservice/CustomerServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package microbucks.customerservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class CustomerServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /section-09/customer-service/src/test/java/microbucks/customerservice/CustomerServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package microbucks.customerservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class CustomerServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /section-10/customer-service/src/test/java/microbucks/customerservice/CustomerServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package microbucks.customerservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class CustomerServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /section-11/customer-service/src/test/java/microbucks/customerservice/CustomerServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package microbucks.customerservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class CustomerServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /section-15/customer-service/src/test/java/microbucks/customerservice/CustomerServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package microbucks.customerservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class CustomerServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /section-16/customer-service/src/test/java/microbucks/customerservice/CustomerServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package microbucks.customerservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class CustomerServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /section-10/hystrix-dashboard/src/test/java/microbucks/hystrixdashboard/HystrixDashboardApplicationTests.java: -------------------------------------------------------------------------------- 1 | package microbucks.hystrixdashboard; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class HystrixDashboardApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /section-15/barista-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=barista-service 2 | server.port=8082 3 | 4 | barista.name=digitalsonic 5 | 6 | spring.sleuth.sampler.percentage=1 7 | 8 | spring.rabbitmq.host=localhost 9 | spring.rabbitmq.port=5672 10 | spring.rabbitmq.username=guest 11 | spring.rabbitmq.password=guest 12 | 13 | spring.cloud.stream.bindinds.default.binder=rabbit 14 | spring.cloud.stream.binders.rabbit.type=rabbit 15 | 16 | spring.cloud.stream.bindings.barista.group=barista-service -------------------------------------------------------------------------------- /section-14/order-service/src/main/java/microbucks/orderservice/stream/OrderStream.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.stream; 2 | 3 | import org.springframework.cloud.stream.annotation.Input; 4 | import org.springframework.cloud.stream.annotation.Output; 5 | import org.springframework.messaging.MessageChannel; 6 | import org.springframework.messaging.SubscribableChannel; 7 | 8 | public interface OrderStream { 9 | @Input 10 | SubscribableChannel order(); 11 | 12 | @Output 13 | MessageChannel barista(); 14 | } 15 | -------------------------------------------------------------------------------- /section-15/order-service/src/main/java/microbucks/orderservice/stream/OrderStream.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.stream; 2 | 3 | import org.springframework.cloud.stream.annotation.Input; 4 | import org.springframework.cloud.stream.annotation.Output; 5 | import org.springframework.messaging.MessageChannel; 6 | import org.springframework.messaging.SubscribableChannel; 7 | 8 | public interface OrderStream { 9 | @Input 10 | SubscribableChannel order(); 11 | 12 | @Output 13 | MessageChannel barista(); 14 | } 15 | -------------------------------------------------------------------------------- /section-16/order-service/src/main/java/microbucks/orderservice/stream/OrderStream.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.stream; 2 | 3 | import org.springframework.cloud.stream.annotation.Input; 4 | import org.springframework.cloud.stream.annotation.Output; 5 | import org.springframework.messaging.MessageChannel; 6 | import org.springframework.messaging.SubscribableChannel; 7 | 8 | public interface OrderStream { 9 | @Input 10 | SubscribableChannel order(); 11 | 12 | @Output 13 | MessageChannel barista(); 14 | } 15 | -------------------------------------------------------------------------------- /section-14/barista-service/src/main/java/microbucks/baristaservice/stream/BaristaStream.java: -------------------------------------------------------------------------------- 1 | package microbucks.baristaservice.stream; 2 | 3 | import org.springframework.cloud.stream.annotation.Input; 4 | import org.springframework.cloud.stream.annotation.Output; 5 | import org.springframework.messaging.MessageChannel; 6 | import org.springframework.messaging.SubscribableChannel; 7 | 8 | public interface BaristaStream { 9 | @Input 10 | SubscribableChannel barista(); 11 | 12 | @Output 13 | MessageChannel order(); 14 | } 15 | -------------------------------------------------------------------------------- /section-15/barista-service/src/main/java/microbucks/baristaservice/stream/BaristaStream.java: -------------------------------------------------------------------------------- 1 | package microbucks.baristaservice.stream; 2 | 3 | import org.springframework.cloud.stream.annotation.Input; 4 | import org.springframework.cloud.stream.annotation.Output; 5 | import org.springframework.messaging.MessageChannel; 6 | import org.springframework.messaging.SubscribableChannel; 7 | 8 | public interface BaristaStream { 9 | @Input 10 | SubscribableChannel barista(); 11 | 12 | @Output 13 | MessageChannel order(); 14 | } 15 | -------------------------------------------------------------------------------- /section-12/zuul-gateway/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | app.name=zuul-gateway 2 | spring.application.name=zuul-gateway 3 | management.security.enabled=false 4 | server.port=9999 5 | 6 | zuul.prefix=/api 7 | #zuul.ignoredServices=* 8 | #zuul.sensitiveHeaders=Cookie,Set-Cookie,Authorization 9 | #zuul.routes.order-service.path=/orders/** 10 | #zuul.routes.orders.serviceId=order-service 11 | 12 | # used for consul 13 | spring.cloud.consul.host=localhost 14 | spring.cloud.consul.port=8500 15 | spring.cloud.consul.discovery.preferIpAddress=true 16 | -------------------------------------------------------------------------------- /section-05/customer-service/src/main/java/microbucks/orderservice/model/Order.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.model; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.io.Serializable; 8 | import java.util.Date; 9 | 10 | @Data 11 | @NoArgsConstructor 12 | @AllArgsConstructor 13 | public class Order implements Serializable { 14 | private Long id; 15 | private String customer; 16 | private String barista; 17 | private Date createTime; 18 | private Date modifyTime; 19 | } 20 | -------------------------------------------------------------------------------- /section-08/eureka-server/src/main/java/microbucks/eurekaserver/EurekaServerApplication.java: -------------------------------------------------------------------------------- 1 | package microbucks.eurekaserver; 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 | @SpringBootApplication 8 | @EnableEurekaServer 9 | public class EurekaServerApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(EurekaServerApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /section-09/order-service/src/main/java/microbucks/orderservice/OrderServiceApplication.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | 7 | @SpringBootApplication 8 | @EnableDiscoveryClient 9 | public class OrderServiceApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(OrderServiceApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /section-13/order-service/src/main/java/microbucks/orderservice/OrderServiceApplication.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | 7 | @SpringBootApplication 8 | @EnableDiscoveryClient 9 | public class OrderServiceApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(OrderServiceApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /section-03/order-service/src/main/asciidoc/main.adoc: -------------------------------------------------------------------------------- 1 | Document for /orders/ 2 | 3 | include::{snippets}/index/curl-request.adoc[] 4 | include::{snippets}/index/http-request.adoc[] 5 | include::{snippets}/index/http-response.adoc[] 6 | include::{snippets}/index/httpie-request.adoc[] 7 | 8 | Document for /orders/{id} 9 | 10 | include::{snippets}/detail/curl-request.adoc[] 11 | include::{snippets}/detail/path-parameters.adoc[] 12 | include::{snippets}/detail/http-request.adoc[] 13 | include::{snippets}/detail/http-response.adoc[] 14 | include::{snippets}/detail/httpie-request.adoc[] 15 | -------------------------------------------------------------------------------- /section-05/order-service/src/main/java/microbucks/orderservice/OrderServiceApplication.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.ImportResource; 6 | 7 | @SpringBootApplication 8 | @ImportResource("/META-INF/spring/applicationContext.xml") 9 | public class OrderServiceApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(OrderServiceApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /section-10/hystrix-dashboard/src/main/java/microbucks/hystrixdashboard/HystrixDashboardApplication.java: -------------------------------------------------------------------------------- 1 | package microbucks.hystrixdashboard; 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 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(HystrixDashboardApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /section-04/order-service/src/main/java/microbucks/orderservice/repository/OrderRepository.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.repository; 2 | 3 | import microbucks.orderservice.model.Order; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import org.springframework.data.repository.query.Param; 6 | import org.springframework.data.rest.core.annotation.RepositoryRestResource; 7 | 8 | import java.util.List; 9 | 10 | @RepositoryRestResource 11 | public interface OrderRepository extends JpaRepository { 12 | 13 | List findByCustomer(@Param("customer") String customer); 14 | } 15 | -------------------------------------------------------------------------------- /section-14/barista-service/src/main/java/microbucks/baristaservice/BaristaServiceApplication.java: -------------------------------------------------------------------------------- 1 | package microbucks.baristaservice; 2 | 3 | import microbucks.baristaservice.stream.BaristaStream; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.cloud.stream.annotation.EnableBinding; 7 | 8 | @SpringBootApplication 9 | @EnableBinding(BaristaStream.class) 10 | public class BaristaServiceApplication { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(BaristaServiceApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /section-15/barista-service/src/main/java/microbucks/baristaservice/BaristaServiceApplication.java: -------------------------------------------------------------------------------- 1 | package microbucks.baristaservice; 2 | 3 | import microbucks.baristaservice.stream.BaristaStream; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.cloud.stream.annotation.EnableBinding; 7 | 8 | @SpringBootApplication 9 | @EnableBinding(BaristaStream.class) 10 | public class BaristaServiceApplication { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(BaristaServiceApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /section-05/customer-service/src/main/java/microbucks/customerservice/CustomerServiceApplication.java: -------------------------------------------------------------------------------- 1 | package microbucks.customerservice; 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication; 4 | import org.springframework.boot.builder.SpringApplicationBuilder; 5 | import org.springframework.context.annotation.ImportResource; 6 | 7 | @SpringBootApplication 8 | @ImportResource("/META-INF/spring/applicationContext.xml") 9 | public class CustomerServiceApplication { 10 | 11 | public static void main(String[] args) { 12 | new SpringApplicationBuilder(CustomerServiceApplication.class).web(false).run(args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /section-06/order-service/src/main/proto/order_service.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package microbucks.orderservice.service; 4 | 5 | import "order_model.proto"; 6 | 7 | option java_package = "microbucks.orderservice.service"; 8 | option java_outer_classname = "OrderProtoService"; 9 | 10 | service OrderService { 11 | rpc GetAll (GetAllRequest) returns (OrderListResponse); 12 | rpc GetOrderById (GetOrderByIdRequest) returns (Order); 13 | } 14 | 15 | message GetAllRequest { 16 | 17 | } 18 | 19 | message GetOrderByIdRequest { 20 | int64 id = 1; 21 | } 22 | 23 | message OrderListResponse { 24 | repeated Order orders = 1; 25 | } -------------------------------------------------------------------------------- /section-13/order-service/src/main/java/microbucks/orderservice/config/CoffeeProperties.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.config; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | import org.springframework.cloud.context.config.annotation.RefreshScope; 6 | import org.springframework.stereotype.Component; 7 | 8 | import java.util.HashMap; 9 | import java.util.Map; 10 | 11 | @Component 12 | @Data 13 | @ConfigurationProperties("coffee") 14 | @RefreshScope 15 | public class CoffeeProperties { 16 | private String secrets; 17 | private Map price = new HashMap<>(); 18 | } 19 | -------------------------------------------------------------------------------- /section-15/zipkin-service/src/main/java/microbucks/zipkinservice/ZipkinServiceApplication.java: -------------------------------------------------------------------------------- 1 | package microbucks.zipkinservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.sleuth.zipkin.stream.EnableZipkinStreamServer; 6 | import zipkin.server.EnableZipkinServer; 7 | 8 | @SpringBootApplication 9 | @EnableZipkinStreamServer 10 | //@EnableZipkinServer 11 | public class ZipkinServiceApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(ZipkinServiceApplication.class, args); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /section-06/customer-service/src/main/proto/order_service.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package microbucks.orderservice.service; 4 | 5 | import "src/main/proto/order_model.proto"; 6 | 7 | option java_package = "microbucks.orderservice.service"; 8 | option java_outer_classname = "OrderProtoService"; 9 | 10 | service OrderService { 11 | rpc GetAll (GetAllRequest) returns (OrderListResponse); 12 | rpc GetOrderById (GetOrderByIdRequest) returns (Order); 13 | } 14 | 15 | message GetAllRequest { 16 | 17 | } 18 | 19 | message GetOrderByIdRequest { 20 | int64 id = 1; 21 | } 22 | 23 | message OrderListResponse { 24 | repeated Order orders = 1; 25 | } 26 | -------------------------------------------------------------------------------- /section-08/order-service/src/main/java/microbucks/orderservice/OrderServiceApplication.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice; 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.eureka.EnableEurekaClient; 7 | 8 | @SpringBootApplication 9 | @EnableDiscoveryClient 10 | @EnableEurekaClient 11 | public class OrderServiceApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(OrderServiceApplication.class, args); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /section-14/barista-service/src/main/java/microbucks/orderservice/model/Order.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.model; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.util.Date; 9 | 10 | @Data 11 | @Builder 12 | @NoArgsConstructor 13 | @AllArgsConstructor 14 | public class Order { 15 | private Long id; 16 | private String customer; 17 | private String barista; 18 | private String content; 19 | private Integer state; 20 | private String price; // 简单期间使用String,真实场景中请使用JodaMoney 21 | private Date createTime; 22 | private Date modifyTime; 23 | } 24 | -------------------------------------------------------------------------------- /section-15/barista-service/src/main/java/microbucks/orderservice/model/Order.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.model; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.util.Date; 9 | 10 | @Data 11 | @Builder 12 | @NoArgsConstructor 13 | @AllArgsConstructor 14 | public class Order { 15 | private Long id; 16 | private String customer; 17 | private String barista; 18 | private String content; 19 | private Integer state; 20 | private String price; // 简单期间使用String,真实场景中请使用JodaMoney 21 | private Date createTime; 22 | private Date modifyTime; 23 | } 24 | -------------------------------------------------------------------------------- /section-11/customer-service/src/main/java/microbucks/customerservice/CustomerServiceApplication.java: -------------------------------------------------------------------------------- 1 | package microbucks.customerservice; 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication; 4 | import org.springframework.boot.builder.SpringApplicationBuilder; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | import org.springframework.cloud.netflix.feign.EnableFeignClients; 7 | 8 | @SpringBootApplication 9 | @EnableDiscoveryClient 10 | @EnableFeignClients 11 | public class CustomerServiceApplication { 12 | 13 | public static void main(String[] args) { 14 | new SpringApplicationBuilder(CustomerServiceApplication.class).web(false).run(args); 15 | } 16 | } -------------------------------------------------------------------------------- /section-03/customer-service/src/main/java/microbucks/customerservice/model/Order.java: -------------------------------------------------------------------------------- 1 | package microbucks.customerservice.model; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.util.Date; 9 | 10 | @Data 11 | @NoArgsConstructor 12 | @AllArgsConstructor 13 | public class Order { 14 | private Long id; 15 | private String customer; 16 | private String barista; 17 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 18 | private Date createTime; 19 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 20 | private Date modifyTime; 21 | } 22 | -------------------------------------------------------------------------------- /section-04/customer-service/src/main/java/microbucks/customerservice/model/Order.java: -------------------------------------------------------------------------------- 1 | package microbucks.customerservice.model; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.util.Date; 9 | 10 | @Data 11 | @NoArgsConstructor 12 | @AllArgsConstructor 13 | public class Order { 14 | private Long id; 15 | private String customer; 16 | private String barista; 17 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 18 | private Date createTime; 19 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 20 | private Date modifyTime; 21 | } 22 | -------------------------------------------------------------------------------- /section-03/customer-service/src/main/java/microbucks/customerservice/CustomerServiceApplication.java: -------------------------------------------------------------------------------- 1 | package microbucks.customerservice; 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication; 4 | import org.springframework.boot.builder.SpringApplicationBuilder; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.web.client.RestTemplate; 7 | 8 | @SpringBootApplication 9 | public class CustomerServiceApplication { 10 | 11 | public static void main(String[] args) { 12 | new SpringApplicationBuilder(CustomerServiceApplication.class).web(false).run(args); 13 | } 14 | 15 | @Bean 16 | public RestTemplate restTemplate() { 17 | return new RestTemplate(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /section-07/customer-service/src/main/java/microbucks/customerservice/CustomerServiceApplication.java: -------------------------------------------------------------------------------- 1 | package microbucks.customerservice; 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication; 4 | import org.springframework.boot.builder.SpringApplicationBuilder; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.web.client.RestTemplate; 7 | 8 | @SpringBootApplication 9 | public class CustomerServiceApplication { 10 | 11 | public static void main(String[] args) { 12 | new SpringApplicationBuilder(CustomerServiceApplication.class).web(false).run(args); 13 | } 14 | 15 | @Bean 16 | public RestTemplate restTemplate() { 17 | return new RestTemplate(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /section-14/order-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | app.name=order-service 2 | spring.application.name=order-service 3 | server.port=8080 4 | spring.output.ansi.enabled=ALWAYS 5 | management.security.enabled=false 6 | 7 | spring.rabbitmq.host=localhost 8 | spring.rabbitmq.port=5672 9 | spring.rabbitmq.username=guest 10 | spring.rabbitmq.password=guest 11 | 12 | spring.cloud.stream.bindinds.default.binder=rabbit 13 | spring.cloud.stream.bindings.order.group=order-service 14 | spring.cloud.stream.binders.rabbit.type=rabbit 15 | 16 | spring.cloud.stream.bindinds.barista.destination=barista 17 | spring.cloud.stream.bindinds.order.destination=order 18 | #spring.cloud.stream.default.contentType=application/json 19 | 20 | -------------------------------------------------------------------------------- /section-13/config-server/src/main/java/microbucks/configserver/ConfigServerApplication.java: -------------------------------------------------------------------------------- 1 | package microbucks.configserver; 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.config.server.EnableConfigServer; 7 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 8 | 9 | @SpringBootApplication 10 | @EnableConfigServer 11 | @EnableDiscoveryClient 12 | @EnableEurekaClient 13 | public class ConfigServerApplication { 14 | 15 | public static void main(String[] args) { 16 | SpringApplication.run(ConfigServerApplication.class, args); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /section-15/order-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | app.name=order-service 2 | spring.application.name=order-service 3 | server.port=8080 4 | spring.output.ansi.enabled=ALWAYS 5 | management.security.enabled=false 6 | 7 | spring.sleuth.sampler.percentage=1 8 | 9 | spring.rabbitmq.host=localhost 10 | spring.rabbitmq.port=5672 11 | spring.rabbitmq.username=guest 12 | spring.rabbitmq.password=guest 13 | 14 | spring.cloud.stream.bindinds.default.binder=rabbit 15 | spring.cloud.stream.bindings.order.group=order-service 16 | spring.cloud.stream.binders.rabbit.type=rabbit 17 | 18 | spring.cloud.stream.bindinds.barista.destination=barista 19 | spring.cloud.stream.bindinds.order.destination=order 20 | #spring.cloud.stream.default.contentType=application/json 21 | 22 | -------------------------------------------------------------------------------- /section-13/order-service/src/main/java/microbucks/orderservice/config/CoffeePrinterRunner.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.config; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.boot.CommandLineRunner; 6 | import org.springframework.stereotype.Component; 7 | 8 | @Component 9 | @Slf4j 10 | public class CoffeePrinterRunner implements CommandLineRunner { 11 | @Autowired 12 | private CoffeeProperties coffeeProperties; 13 | 14 | @Override 15 | public void run(String... args) throws Exception { 16 | log.info("my secret: {}", coffeeProperties.getSecrets()); 17 | coffeeProperties.getPrice().forEach((name, price) -> log.info("{} -> {}", name, price)); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /section-10/customer-service/src/main/java/microbucks/customerservice/controller/CustomerController.java: -------------------------------------------------------------------------------- 1 | package microbucks.customerservice.controller; 2 | 3 | import microbucks.customerservice.action.BuyerAction; 4 | import microbucks.customerservice.model.Order; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RequestMethod; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | @RestController 11 | public class CustomerController { 12 | @Autowired 13 | private BuyerAction buyerAction; 14 | 15 | @RequestMapping(value = "/buy", method = RequestMethod.POST) 16 | public String buyCoffee() { 17 | return buyerAction.buy(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /section-15/customer-service/src/main/java/microbucks/customerservice/controller/CustomerController.java: -------------------------------------------------------------------------------- 1 | package microbucks.customerservice.controller; 2 | 3 | import microbucks.customerservice.action.BuyerAction; 4 | import microbucks.customerservice.model.Order; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RequestMethod; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | @RestController 11 | public class CustomerController { 12 | @Autowired 13 | private BuyerAction buyerAction; 14 | 15 | @RequestMapping(value = "/buy", method = RequestMethod.POST) 16 | public String buyCoffee() { 17 | return buyerAction.buy(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /section-16/customer-service/src/main/java/microbucks/customerservice/controller/CustomerController.java: -------------------------------------------------------------------------------- 1 | package microbucks.customerservice.controller; 2 | 3 | import microbucks.customerservice.action.BuyerAction; 4 | import microbucks.customerservice.model.Order; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RequestMethod; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | @RestController 11 | public class CustomerController { 12 | @Autowired 13 | private BuyerAction buyerAction; 14 | 15 | @RequestMapping(value = "/buy", method = RequestMethod.POST) 16 | public String buyCoffee() { 17 | return buyerAction.buy(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /section-05/customer-service/src/main/resources/META-INF/spring/applicationContext.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /section-14/order-service/src/main/java/microbucks/orderservice/OrderServiceApplication.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice; 2 | 3 | import microbucks.orderservice.stream.OrderStream; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 7 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 8 | import org.springframework.cloud.stream.annotation.EnableBinding; 9 | 10 | @SpringBootApplication 11 | @EnableDiscoveryClient 12 | @EnableEurekaClient 13 | @EnableBinding(OrderStream.class) 14 | public class OrderServiceApplication { 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(OrderServiceApplication.class, args); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /section-15/order-service/src/main/java/microbucks/orderservice/OrderServiceApplication.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice; 2 | 3 | import microbucks.orderservice.stream.OrderStream; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 7 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 8 | import org.springframework.cloud.stream.annotation.EnableBinding; 9 | 10 | @SpringBootApplication 11 | @EnableDiscoveryClient 12 | @EnableEurekaClient 13 | @EnableBinding(OrderStream.class) 14 | public class OrderServiceApplication { 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(OrderServiceApplication.class, args); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /section-16/customer-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | app.name=customer-service 2 | spring.application.name=customer-service 3 | server.port=8081 4 | management.security.enabled=false 5 | 6 | spring.sleuth.sampler.percentage=1 7 | 8 | spring.rabbitmq.host=localhost 9 | spring.rabbitmq.port=5672 10 | spring.rabbitmq.username=guest 11 | spring.rabbitmq.password=guest 12 | 13 | #hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=2000 14 | 15 | security.ignored=/buy 16 | 17 | security.oauth2.resource.loadBalanced=true 18 | 19 | security.oauth2.client.client-id=customer 20 | security.oauth2.client.client-secret=customer 21 | security.oauth2.client.authorized-grant-types=client_credentials 22 | security.oauth2.client.scope=vip 23 | security.oauth2.client.access-token-uri=http://oauth-service/oauth/token -------------------------------------------------------------------------------- /section-05/order-service/src/main/resources/META-INF/spring/applicationContext.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /section-05/order-service/src/main/java/microbucks/orderservice/service/OrderServiceImpl.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.service; 2 | 3 | import com.alibaba.dubbo.config.annotation.Service; 4 | import microbucks.orderservice.model.Order; 5 | import microbucks.orderservice.repository.OrderRepository; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Component; 8 | 9 | import java.util.List; 10 | 11 | @Service 12 | @Component 13 | public class OrderServiceImpl implements OrderServiceFacade { 14 | @Autowired 15 | private OrderRepository orderRepository; 16 | 17 | @Override 18 | public List getAllOrders() { 19 | return orderRepository.findAll(); 20 | } 21 | 22 | @Override 23 | public Order getOrder(Long id) { 24 | return orderRepository.findOne(id); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /section-07/customer-service/src/main/java/microbucks/customerservice/model/Order.java: -------------------------------------------------------------------------------- 1 | package microbucks.customerservice.model; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | import java.util.Date; 10 | 11 | @Data 12 | @Builder 13 | @NoArgsConstructor 14 | @AllArgsConstructor 15 | public class Order { 16 | private Long id; 17 | private String customer; 18 | private String barista; 19 | private String content; 20 | private Integer state; 21 | private String price; // 简单期间使用String,真实场景中请使用JodaMoney 22 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 23 | private Date createTime; 24 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 25 | private Date modifyTime; 26 | } 27 | -------------------------------------------------------------------------------- /section-08/customer-service/src/main/java/microbucks/customerservice/model/Order.java: -------------------------------------------------------------------------------- 1 | package microbucks.customerservice.model; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | import java.util.Date; 10 | 11 | @Data 12 | @Builder 13 | @NoArgsConstructor 14 | @AllArgsConstructor 15 | public class Order { 16 | private Long id; 17 | private String customer; 18 | private String barista; 19 | private String content; 20 | private Integer state; 21 | private String price; // 简单期间使用String,真实场景中请使用JodaMoney 22 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 23 | private Date createTime; 24 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 25 | private Date modifyTime; 26 | } 27 | -------------------------------------------------------------------------------- /section-09/customer-service/src/main/java/microbucks/customerservice/model/Order.java: -------------------------------------------------------------------------------- 1 | package microbucks.customerservice.model; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | import java.util.Date; 10 | 11 | @Data 12 | @Builder 13 | @NoArgsConstructor 14 | @AllArgsConstructor 15 | public class Order { 16 | private Long id; 17 | private String customer; 18 | private String barista; 19 | private String content; 20 | private Integer state; 21 | private String price; // 简单期间使用String,真实场景中请使用JodaMoney 22 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 23 | private Date createTime; 24 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 25 | private Date modifyTime; 26 | } 27 | -------------------------------------------------------------------------------- /section-10/customer-service/src/main/java/microbucks/customerservice/model/Order.java: -------------------------------------------------------------------------------- 1 | package microbucks.customerservice.model; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | import java.util.Date; 10 | 11 | @Data 12 | @Builder 13 | @NoArgsConstructor 14 | @AllArgsConstructor 15 | public class Order { 16 | private Long id; 17 | private String customer; 18 | private String barista; 19 | private String content; 20 | private Integer state; 21 | private String price; // 简单期间使用String,真实场景中请使用JodaMoney 22 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 23 | private Date createTime; 24 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 25 | private Date modifyTime; 26 | } 27 | -------------------------------------------------------------------------------- /section-11/customer-service/src/main/java/microbucks/customerservice/model/Order.java: -------------------------------------------------------------------------------- 1 | package microbucks.customerservice.model; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | import java.util.Date; 10 | 11 | @Data 12 | @Builder 13 | @NoArgsConstructor 14 | @AllArgsConstructor 15 | public class Order { 16 | private Long id; 17 | private String customer; 18 | private String barista; 19 | private String content; 20 | private Integer state; 21 | private String price; // 简单期间使用String,真实场景中请使用JodaMoney 22 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 23 | private Date createTime; 24 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 25 | private Date modifyTime; 26 | } 27 | -------------------------------------------------------------------------------- /section-15/customer-service/src/main/java/microbucks/customerservice/model/Order.java: -------------------------------------------------------------------------------- 1 | package microbucks.customerservice.model; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | import java.util.Date; 10 | 11 | @Data 12 | @Builder 13 | @NoArgsConstructor 14 | @AllArgsConstructor 15 | public class Order { 16 | private Long id; 17 | private String customer; 18 | private String barista; 19 | private String content; 20 | private Integer state; 21 | private String price; // 简单期间使用String,真实场景中请使用JodaMoney 22 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 23 | private Date createTime; 24 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 25 | private Date modifyTime; 26 | } 27 | -------------------------------------------------------------------------------- /section-16/customer-service/src/main/java/microbucks/customerservice/model/Order.java: -------------------------------------------------------------------------------- 1 | package microbucks.customerservice.model; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | import java.util.Date; 10 | 11 | @Data 12 | @Builder 13 | @NoArgsConstructor 14 | @AllArgsConstructor 15 | public class Order { 16 | private Long id; 17 | private String customer; 18 | private String barista; 19 | private String content; 20 | private Integer state; 21 | private String price; // 简单期间使用String,真实场景中请使用JodaMoney 22 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 23 | private Date createTime; 24 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 25 | private Date modifyTime; 26 | } 27 | -------------------------------------------------------------------------------- /section-09/customer-service/src/main/java/microbucks/customerservice/CustomerServiceApplication.java: -------------------------------------------------------------------------------- 1 | package microbucks.customerservice; 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication; 4 | import org.springframework.boot.builder.SpringApplicationBuilder; 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 | @SpringBootApplication 11 | @EnableDiscoveryClient 12 | public class CustomerServiceApplication { 13 | 14 | public static void main(String[] args) { 15 | new SpringApplicationBuilder(CustomerServiceApplication.class).web(true).run(args); 16 | } 17 | 18 | @Bean 19 | @LoadBalanced 20 | public RestTemplate restTemplate() { 21 | return new RestTemplate(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /section-08/customer-service/src/main/java/microbucks/customerservice/CustomerServiceApplication.java: -------------------------------------------------------------------------------- 1 | package microbucks.customerservice; 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication; 4 | import org.springframework.boot.builder.SpringApplicationBuilder; 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 | @SpringBootApplication 11 | @EnableDiscoveryClient 12 | public class CustomerServiceApplication { 13 | 14 | public static void main(String[] args) { 15 | new SpringApplicationBuilder(CustomerServiceApplication.class).web(false).run(args); 16 | } 17 | 18 | @Bean 19 | @LoadBalanced 20 | public RestTemplate restTemplate() { 21 | return new RestTemplate(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /section-12/zuul-gateway/src/main/java/microbucks/zuulgateway/ZuulGatewayApplication.java: -------------------------------------------------------------------------------- 1 | package microbucks.zuulgateway; 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.cloud.netflix.zuul.EnableZuulProxy; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.web.client.RestTemplate; 10 | 11 | @SpringBootApplication 12 | @EnableZuulProxy 13 | @EnableDiscoveryClient 14 | public class ZuulGatewayApplication { 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(ZuulGatewayApplication.class, args); 18 | } 19 | 20 | @Bean 21 | @LoadBalanced 22 | public RestTemplate restTemplate() { 23 | return new RestTemplate(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /section-10/customer-service/src/main/java/microbucks/customerservice/CustomerServiceApplication.java: -------------------------------------------------------------------------------- 1 | package microbucks.customerservice; 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication; 4 | import org.springframework.boot.builder.SpringApplicationBuilder; 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 | @SpringBootApplication 12 | @EnableDiscoveryClient 13 | @EnableCircuitBreaker 14 | public class CustomerServiceApplication { 15 | 16 | public static void main(String[] args) { 17 | new SpringApplicationBuilder(CustomerServiceApplication.class).web(true).run(args); 18 | } 19 | 20 | @Bean 21 | @LoadBalanced 22 | public RestTemplate restTemplate() { 23 | return new RestTemplate(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /section-15/customer-service/src/main/java/microbucks/customerservice/CustomerServiceApplication.java: -------------------------------------------------------------------------------- 1 | package microbucks.customerservice; 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication; 4 | import org.springframework.boot.builder.SpringApplicationBuilder; 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 | @SpringBootApplication 12 | @EnableDiscoveryClient 13 | @EnableCircuitBreaker 14 | public class CustomerServiceApplication { 15 | 16 | public static void main(String[] args) { 17 | new SpringApplicationBuilder(CustomerServiceApplication.class).web(true).run(args); 18 | } 19 | 20 | @Bean 21 | @LoadBalanced 22 | public RestTemplate restTemplate() { 23 | return new RestTemplate(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /section-16/oauth-service/src/main/java/microbucks/oauthservice/OauthServiceApplication.java: -------------------------------------------------------------------------------- 1 | package microbucks.oauthservice; 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.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | import java.security.Principal; 11 | 12 | @SpringBootApplication 13 | @EnableDiscoveryClient 14 | @RestController 15 | @EnableAuthorizationServer 16 | public class OauthServiceApplication { 17 | 18 | public static void main(String[] args) { 19 | SpringApplication.run(OauthServiceApplication.class, args); 20 | } 21 | 22 | @RequestMapping("/principal") 23 | public Principal principal(Principal p) { 24 | return p; 25 | } 26 | } 27 | 28 | 29 | -------------------------------------------------------------------------------- /section-02/order-service/src/main/java/microbucks/orderservice/health/OrderHealthIndicator.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.health; 2 | 3 | import microbucks.orderservice.model.Order; 4 | import microbucks.orderservice.repository.OrderRepository; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.actuate.health.Health; 7 | import org.springframework.boot.actuate.health.HealthIndicator; 8 | import org.springframework.stereotype.Component; 9 | 10 | import java.util.List; 11 | 12 | @Component 13 | public class OrderHealthIndicator implements HealthIndicator { 14 | @Autowired 15 | private OrderRepository orderRepository; 16 | 17 | @Override 18 | public Health health() { 19 | List orders = orderRepository.findAll(); 20 | if (orders == null || orders.isEmpty()) { 21 | return Health.unknown().withDetail("order.size", "none").build(); 22 | } 23 | 24 | return Health.up().withDetail("order.size", orders.size()).build(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /section-03/order-service/src/main/java/microbucks/orderservice/health/OrderHealthIndicator.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.health; 2 | 3 | import microbucks.orderservice.model.Order; 4 | import microbucks.orderservice.repository.OrderRepository; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.actuate.health.Health; 7 | import org.springframework.boot.actuate.health.HealthIndicator; 8 | import org.springframework.stereotype.Component; 9 | 10 | import java.util.List; 11 | 12 | @Component 13 | public class OrderHealthIndicator implements HealthIndicator { 14 | @Autowired 15 | private OrderRepository orderRepository; 16 | 17 | @Override 18 | public Health health() { 19 | List orders = orderRepository.findAll(); 20 | if (orders == null || orders.isEmpty()) { 21 | return Health.unknown().withDetail("order.size", "none").build(); 22 | } 23 | 24 | return Health.up().withDetail("order.size", orders.size()).build(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /section-04/order-service/src/main/java/microbucks/orderservice/health/OrderHealthIndicator.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.health; 2 | 3 | import microbucks.orderservice.model.Order; 4 | import microbucks.orderservice.repository.OrderRepository; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.actuate.health.Health; 7 | import org.springframework.boot.actuate.health.HealthIndicator; 8 | import org.springframework.stereotype.Component; 9 | 10 | import java.util.List; 11 | 12 | @Component 13 | public class OrderHealthIndicator implements HealthIndicator { 14 | @Autowired 15 | private OrderRepository orderRepository; 16 | 17 | @Override 18 | public Health health() { 19 | List orders = orderRepository.findAll(); 20 | if (orders == null || orders.isEmpty()) { 21 | return Health.unknown().withDetail("order.size", "none").build(); 22 | } 23 | 24 | return Health.up().withDetail("order.size", orders.size()).build(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /section-05/order-service/src/main/java/microbucks/orderservice/health/OrderHealthIndicator.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.health; 2 | 3 | import microbucks.orderservice.model.Order; 4 | import microbucks.orderservice.repository.OrderRepository; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.actuate.health.Health; 7 | import org.springframework.boot.actuate.health.HealthIndicator; 8 | import org.springframework.stereotype.Component; 9 | 10 | import java.util.List; 11 | 12 | @Component 13 | public class OrderHealthIndicator implements HealthIndicator { 14 | @Autowired 15 | private OrderRepository orderRepository; 16 | 17 | @Override 18 | public Health health() { 19 | List orders = orderRepository.findAll(); 20 | if (orders == null || orders.isEmpty()) { 21 | return Health.unknown().withDetail("order.size", "none").build(); 22 | } 23 | 24 | return Health.up().withDetail("order.size", orders.size()).build(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /section-06/order-service/src/main/java/microbucks/orderservice/runner/GrpcServerRunner.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.runner; 2 | 3 | import io.grpc.ServerBuilder; 4 | import lombok.extern.slf4j.Slf4j; 5 | import microbucks.orderservice.service.OrderServiceImpl; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.beans.factory.annotation.Value; 8 | import org.springframework.boot.CommandLineRunner; 9 | import org.springframework.core.annotation.Order; 10 | import org.springframework.stereotype.Component; 11 | 12 | @Component 13 | @Order(2) 14 | @Slf4j 15 | public class GrpcServerRunner implements CommandLineRunner{ 16 | @Autowired 17 | private OrderServiceImpl orderService; 18 | @Value("${grpc.port:8888}") 19 | private int grpcPort; 20 | 21 | @Override 22 | public void run(String... args) throws Exception { 23 | ServerBuilder.forPort(grpcPort).addService(orderService).build().start(); 24 | log.info("start grpc orderService on {}", grpcPort); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /section-01/order-service/src/main/java/microbucks/orderservice/model/Order.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.model; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | import javax.persistence.Column; 10 | import javax.persistence.Entity; 11 | import javax.persistence.GeneratedValue; 12 | import javax.persistence.Id; 13 | import javax.persistence.Table; 14 | import java.util.Date; 15 | 16 | @Entity 17 | @Data 18 | @Builder 19 | @NoArgsConstructor 20 | @AllArgsConstructor 21 | @Table(name = "coffee_orders") 22 | public class Order { 23 | @Id 24 | @GeneratedValue 25 | private Long id; 26 | private String customer; 27 | private String barista; 28 | @Column(updatable = false) 29 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 30 | private Date createTime; 31 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 32 | private Date modifyTime; 33 | } 34 | -------------------------------------------------------------------------------- /section-02/order-service/src/main/java/microbucks/orderservice/model/Order.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.model; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | import javax.persistence.Column; 10 | import javax.persistence.Entity; 11 | import javax.persistence.GeneratedValue; 12 | import javax.persistence.Id; 13 | import javax.persistence.Table; 14 | import java.util.Date; 15 | 16 | @Entity 17 | @Data 18 | @Builder 19 | @NoArgsConstructor 20 | @AllArgsConstructor 21 | @Table(name = "coffee_orders") 22 | public class Order { 23 | @Id 24 | @GeneratedValue 25 | private Long id; 26 | private String customer; 27 | private String barista; 28 | @Column(updatable = false) 29 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 30 | private Date createTime; 31 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 32 | private Date modifyTime; 33 | } 34 | -------------------------------------------------------------------------------- /section-04/order-service/src/main/java/microbucks/orderservice/model/Order.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.model; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | import javax.persistence.Column; 10 | import javax.persistence.Entity; 11 | import javax.persistence.GeneratedValue; 12 | import javax.persistence.Id; 13 | import javax.persistence.Table; 14 | import java.util.Date; 15 | 16 | @Entity 17 | @Data 18 | @Builder 19 | @NoArgsConstructor 20 | @AllArgsConstructor 21 | @Table(name = "coffee_orders") 22 | public class Order { 23 | @Id 24 | @GeneratedValue 25 | private Long id; 26 | private String customer; 27 | private String barista; 28 | @Column(updatable = false) 29 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 30 | private Date createTime; 31 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 32 | private Date modifyTime; 33 | } 34 | -------------------------------------------------------------------------------- /section-11/customer-service/src/main/java/microbucks/customerservice/OrderService.java: -------------------------------------------------------------------------------- 1 | package microbucks.customerservice; 2 | 3 | import microbucks.customerservice.model.Order; 4 | import org.springframework.cloud.netflix.feign.FeignClient; 5 | import org.springframework.http.ResponseEntity; 6 | import org.springframework.web.bind.annotation.PathVariable; 7 | import org.springframework.web.bind.annotation.RequestBody; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RequestMethod; 10 | 11 | @FeignClient("order-service") 12 | public interface OrderService { 13 | @RequestMapping(value = "/orders/", method = RequestMethod.POST) 14 | Order createOrder(@RequestBody Order order); 15 | 16 | @RequestMapping(value = "/orders/{id}", method = RequestMethod.GET) 17 | Order getOrderById(@PathVariable("id") Long id); 18 | 19 | @RequestMapping(value = "/orders/{id}", method = RequestMethod.PUT) 20 | ResponseEntity modifyOrder(@PathVariable("id") Long id, @RequestBody Order order); 21 | } 22 | -------------------------------------------------------------------------------- /section-05/customer-service/src/main/java/microbucks/customerservice/runner/OrderServiceGetRunner.java: -------------------------------------------------------------------------------- 1 | package microbucks.customerservice.runner; 2 | 3 | import com.alibaba.dubbo.config.annotation.Reference; 4 | import lombok.extern.slf4j.Slf4j; 5 | import microbucks.orderservice.model.Order; 6 | import microbucks.orderservice.service.OrderServiceFacade; 7 | import org.springframework.boot.ApplicationArguments; 8 | import org.springframework.boot.ApplicationRunner; 9 | import org.springframework.stereotype.Component; 10 | 11 | import java.util.List; 12 | 13 | @Component 14 | @Slf4j 15 | public class OrderServiceGetRunner implements ApplicationRunner { 16 | @Reference 17 | private OrderServiceFacade orderServiceFacade; 18 | 19 | @Override 20 | public void run(ApplicationArguments args) throws Exception { 21 | List orderList = orderServiceFacade.getAllOrders(); 22 | log.info("get {} orders from remote", orderList.size()); 23 | 24 | Order order = orderServiceFacade.getOrder(1L); 25 | log.info("getOrder(1): {}", order); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /section-03/order-service/src/main/java/microbucks/orderservice/model/Order.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.model; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | import javax.persistence.Column; 10 | import javax.persistence.Entity; 11 | import javax.persistence.GeneratedValue; 12 | import javax.persistence.Id; 13 | import javax.persistence.Table; 14 | import javax.xml.bind.annotation.XmlRootElement; 15 | import java.util.Date; 16 | 17 | @Entity 18 | @Data 19 | @Builder 20 | @NoArgsConstructor 21 | @AllArgsConstructor 22 | @Table(name = "coffee_orders") 23 | @XmlRootElement 24 | public class Order { 25 | @Id 26 | @GeneratedValue 27 | private Long id; 28 | private String customer; 29 | private String barista; 30 | @Column(updatable = false) 31 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 32 | private Date createTime; 33 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 34 | private Date modifyTime; 35 | } 36 | -------------------------------------------------------------------------------- /section-01/order-service/src/main/java/microbucks/orderservice/runner/DataInitializerRunner.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.runner; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import microbucks.orderservice.model.Order; 5 | import microbucks.orderservice.repository.OrderRepository; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.CommandLineRunner; 8 | import org.springframework.stereotype.Component; 9 | 10 | import java.util.Arrays; 11 | import java.util.Date; 12 | 13 | @Component 14 | @Slf4j 15 | public class DataInitializerRunner implements CommandLineRunner { 16 | @Autowired 17 | private OrderRepository orderRepository; 18 | 19 | @Override 20 | public void run(String... args) throws Exception { 21 | Arrays.asList("LiLei", "HanMeimei").forEach(x -> { 22 | Order order = Order.builder().customer(x).barista("Master") 23 | .createTime(new Date()).modifyTime(new Date()).build(); 24 | orderRepository.save(order); 25 | log.info("Saving Order[{}] to database.", order); 26 | }); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /section-14/barista-service/src/main/java/microbucks/baristaservice/stream/StreamProcessor.java: -------------------------------------------------------------------------------- 1 | package microbucks.baristaservice.stream; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import microbucks.orderservice.model.Order; 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.cloud.stream.annotation.StreamListener; 7 | import org.springframework.messaging.handler.annotation.SendTo; 8 | import org.springframework.stereotype.Component; 9 | 10 | import java.util.Date; 11 | 12 | @Component 13 | @Slf4j 14 | public class StreamProcessor { 15 | @Value("${barista.name}") 16 | private String baristaName; 17 | 18 | @StreamListener("barista") 19 | @SendTo("order") 20 | public Order receiveOrder(Order order) { 21 | log.info("receive order: {}", order); 22 | try { 23 | Thread.sleep(1000); 24 | } catch (InterruptedException e) { 25 | } 26 | log.info("coffee for order {} is ready", order.getId()); 27 | order.setBarista(baristaName); 28 | order.setState(3); 29 | order.setModifyTime(new Date()); 30 | return order; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /section-15/barista-service/src/main/java/microbucks/baristaservice/stream/StreamProcessor.java: -------------------------------------------------------------------------------- 1 | package microbucks.baristaservice.stream; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import microbucks.orderservice.model.Order; 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.cloud.stream.annotation.StreamListener; 7 | import org.springframework.messaging.handler.annotation.SendTo; 8 | import org.springframework.stereotype.Component; 9 | 10 | import java.util.Date; 11 | 12 | @Component 13 | @Slf4j 14 | public class StreamProcessor { 15 | @Value("${barista.name}") 16 | private String baristaName; 17 | 18 | @StreamListener("barista") 19 | @SendTo("order") 20 | public Order receiveOrder(Order order) { 21 | log.info("receive order: {}", order); 22 | try { 23 | Thread.sleep(1000); 24 | } catch (InterruptedException e) { 25 | } 26 | log.info("coffee for order {} is ready", order.getId()); 27 | order.setBarista(baristaName); 28 | order.setState(3); 29 | order.setModifyTime(new Date()); 30 | return order; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /section-01/order-service/src/main/java/microbucks/orderservice/service/OrderServiceController.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.service; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import microbucks.orderservice.model.Order; 5 | import microbucks.orderservice.repository.OrderRepository; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.PathVariable; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | import java.util.List; 12 | 13 | @RestController 14 | @RequestMapping("/orders") 15 | @Slf4j 16 | public class OrderServiceController { 17 | @Autowired 18 | private OrderRepository orderRepository; 19 | 20 | @RequestMapping("/") 21 | public List getOrders() { 22 | List orders = orderRepository.findAll(); 23 | orders.forEach(o -> log.info("Order[{}] loaded.", o)); 24 | return orders; 25 | } 26 | 27 | @RequestMapping("/{id}") 28 | public Order getOrderById(@PathVariable Long id) { 29 | return orderRepository.findOne(id); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /section-05/order-service/src/main/java/microbucks/orderservice/model/Order.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.model; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | import javax.persistence.Column; 10 | import javax.persistence.Entity; 11 | import javax.persistence.GeneratedValue; 12 | import javax.persistence.Id; 13 | import javax.persistence.Table; 14 | import javax.xml.bind.annotation.XmlRootElement; 15 | import java.io.Serializable; 16 | import java.util.Date; 17 | 18 | @Entity 19 | @Data 20 | @Builder 21 | @NoArgsConstructor 22 | @AllArgsConstructor 23 | @Table(name = "coffee_orders") 24 | @XmlRootElement 25 | public class Order implements Serializable{ 26 | @Id 27 | @GeneratedValue 28 | private Long id; 29 | private String customer; 30 | private String barista; 31 | @Column(updatable = false) 32 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 33 | private Date createTime; 34 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 35 | private Date modifyTime; 36 | } 37 | -------------------------------------------------------------------------------- /section-06/order-service/src/main/java/microbucks/orderservice/model/Order.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.model; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | import javax.persistence.Column; 10 | import javax.persistence.Entity; 11 | import javax.persistence.GeneratedValue; 12 | import javax.persistence.Id; 13 | import javax.persistence.Table; 14 | import javax.xml.bind.annotation.XmlRootElement; 15 | import java.io.Serializable; 16 | import java.util.Date; 17 | 18 | @Entity 19 | @Data 20 | @Builder 21 | @NoArgsConstructor 22 | @AllArgsConstructor 23 | @Table(name = "coffee_orders") 24 | @XmlRootElement 25 | public class Order implements Serializable{ 26 | @Id 27 | @GeneratedValue 28 | private Long id; 29 | private String customer; 30 | private String barista; 31 | @Column(updatable = false) 32 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 33 | private Date createTime; 34 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 35 | private Date modifyTime; 36 | } 37 | -------------------------------------------------------------------------------- /section-07/order-service/src/main/java/microbucks/orderservice/model/Order.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.model; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | import javax.persistence.Column; 10 | import javax.persistence.Entity; 11 | import javax.persistence.GeneratedValue; 12 | import javax.persistence.Id; 13 | import javax.persistence.Table; 14 | import java.util.Date; 15 | 16 | @Entity 17 | @Data 18 | @Builder 19 | @NoArgsConstructor 20 | @AllArgsConstructor 21 | @Table(name = "coffee_orders") 22 | public class Order { 23 | @Id 24 | @GeneratedValue 25 | private Long id; 26 | private String customer; 27 | private String barista; 28 | private String content; 29 | private Integer state; 30 | private String price; // 简单期间使用String,真实场景中请使用JodaMoney 31 | @Column(updatable = false) 32 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 33 | private Date createTime; 34 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 35 | private Date modifyTime; 36 | } 37 | -------------------------------------------------------------------------------- /section-08/order-service/src/main/java/microbucks/orderservice/model/Order.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.model; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | import javax.persistence.Column; 10 | import javax.persistence.Entity; 11 | import javax.persistence.GeneratedValue; 12 | import javax.persistence.Id; 13 | import javax.persistence.Table; 14 | import java.util.Date; 15 | 16 | @Entity 17 | @Data 18 | @Builder 19 | @NoArgsConstructor 20 | @AllArgsConstructor 21 | @Table(name = "coffee_orders") 22 | public class Order { 23 | @Id 24 | @GeneratedValue 25 | private Long id; 26 | private String customer; 27 | private String barista; 28 | private String content; 29 | private Integer state; 30 | private String price; // 简单期间使用String,真实场景中请使用JodaMoney 31 | @Column(updatable = false) 32 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 33 | private Date createTime; 34 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 35 | private Date modifyTime; 36 | } 37 | -------------------------------------------------------------------------------- /section-09/order-service/src/main/java/microbucks/orderservice/model/Order.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.model; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | import javax.persistence.Column; 10 | import javax.persistence.Entity; 11 | import javax.persistence.GeneratedValue; 12 | import javax.persistence.Id; 13 | import javax.persistence.Table; 14 | import java.util.Date; 15 | 16 | @Entity 17 | @Data 18 | @Builder 19 | @NoArgsConstructor 20 | @AllArgsConstructor 21 | @Table(name = "coffee_orders") 22 | public class Order { 23 | @Id 24 | @GeneratedValue 25 | private Long id; 26 | private String customer; 27 | private String barista; 28 | private String content; 29 | private Integer state; 30 | private String price; // 简单期间使用String,真实场景中请使用JodaMoney 31 | @Column(updatable = false) 32 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 33 | private Date createTime; 34 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 35 | private Date modifyTime; 36 | } 37 | -------------------------------------------------------------------------------- /section-13/order-service/src/main/java/microbucks/orderservice/model/Order.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.model; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | import javax.persistence.Column; 10 | import javax.persistence.Entity; 11 | import javax.persistence.GeneratedValue; 12 | import javax.persistence.Id; 13 | import javax.persistence.Table; 14 | import java.util.Date; 15 | 16 | @Entity 17 | @Data 18 | @Builder 19 | @NoArgsConstructor 20 | @AllArgsConstructor 21 | @Table(name = "coffee_orders") 22 | public class Order { 23 | @Id 24 | @GeneratedValue 25 | private Long id; 26 | private String customer; 27 | private String barista; 28 | private String content; 29 | private Integer state; 30 | private String price; // 简单期间使用String,真实场景中请使用JodaMoney 31 | @Column(updatable = false) 32 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 33 | private Date createTime; 34 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 35 | private Date modifyTime; 36 | } 37 | -------------------------------------------------------------------------------- /section-14/order-service/src/main/java/microbucks/orderservice/model/Order.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.model; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | import javax.persistence.Column; 10 | import javax.persistence.Entity; 11 | import javax.persistence.GeneratedValue; 12 | import javax.persistence.Id; 13 | import javax.persistence.Table; 14 | import java.util.Date; 15 | 16 | @Entity 17 | @Data 18 | @Builder 19 | @NoArgsConstructor 20 | @AllArgsConstructor 21 | @Table(name = "coffee_orders") 22 | public class Order { 23 | @Id 24 | @GeneratedValue 25 | private Long id; 26 | private String customer; 27 | private String barista; 28 | private String content; 29 | private Integer state; 30 | private String price; // 简单期间使用String,真实场景中请使用JodaMoney 31 | @Column(updatable = false) 32 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 33 | private Date createTime; 34 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 35 | private Date modifyTime; 36 | } 37 | -------------------------------------------------------------------------------- /section-15/order-service/src/main/java/microbucks/orderservice/model/Order.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.model; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | import javax.persistence.Column; 10 | import javax.persistence.Entity; 11 | import javax.persistence.GeneratedValue; 12 | import javax.persistence.Id; 13 | import javax.persistence.Table; 14 | import java.util.Date; 15 | 16 | @Entity 17 | @Data 18 | @Builder 19 | @NoArgsConstructor 20 | @AllArgsConstructor 21 | @Table(name = "coffee_orders") 22 | public class Order { 23 | @Id 24 | @GeneratedValue 25 | private Long id; 26 | private String customer; 27 | private String barista; 28 | private String content; 29 | private Integer state; 30 | private String price; // 简单期间使用String,真实场景中请使用JodaMoney 31 | @Column(updatable = false) 32 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 33 | private Date createTime; 34 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 35 | private Date modifyTime; 36 | } 37 | -------------------------------------------------------------------------------- /section-16/order-service/src/main/java/microbucks/orderservice/model/Order.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.model; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | import javax.persistence.Column; 10 | import javax.persistence.Entity; 11 | import javax.persistence.GeneratedValue; 12 | import javax.persistence.Id; 13 | import javax.persistence.Table; 14 | import java.util.Date; 15 | 16 | @Entity 17 | @Data 18 | @Builder 19 | @NoArgsConstructor 20 | @AllArgsConstructor 21 | @Table(name = "coffee_orders") 22 | public class Order { 23 | @Id 24 | @GeneratedValue 25 | private Long id; 26 | private String customer; 27 | private String barista; 28 | private String content; 29 | private Integer state; 30 | private String price; // 简单期间使用String,真实场景中请使用JodaMoney 31 | @Column(updatable = false) 32 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 33 | private Date createTime; 34 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 35 | private Date modifyTime; 36 | } 37 | -------------------------------------------------------------------------------- /section-16/order-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | app.name=order-service 2 | spring.application.name=order-service 3 | server.port=8080 4 | spring.output.ansi.enabled=ALWAYS 5 | management.security.enabled=false 6 | 7 | spring.sleuth.sampler.percentage=1 8 | 9 | spring.rabbitmq.host=localhost 10 | spring.rabbitmq.port=5672 11 | spring.rabbitmq.username=guest 12 | spring.rabbitmq.password=guest 13 | 14 | spring.cloud.stream.bindinds.default.binder=rabbit 15 | spring.cloud.stream.bindings.order.group=order-service 16 | spring.cloud.stream.binders.rabbit.type=rabbit 17 | 18 | spring.cloud.stream.bindinds.barista.destination=barista 19 | spring.cloud.stream.bindinds.order.destination=order 20 | #spring.cloud.stream.default.contentType=application/json 21 | 22 | security.oauth2.resource.userInfoUri=http://oauth-service/principal 23 | security.oauth2.resource.tokenInfoUri=http://oauth-service/oauth/check_token 24 | 25 | security.oauth2.client.clientId=order 26 | security.oauth2.client.clientSecret=order 27 | security.oauth2.client.authorizedGrantTypes=client_credentials 28 | security.oauth2.client.scope=vip 29 | security.oauth2.client.accessTokenUri=http://oauth-service/oauth/token 30 | -------------------------------------------------------------------------------- /section-12/zuul-gateway/src/main/java/microbucks/zuulgateway/LogFilter.java: -------------------------------------------------------------------------------- 1 | package microbucks.zuulgateway; 2 | 3 | import com.netflix.zuul.ZuulFilter; 4 | import com.netflix.zuul.context.RequestContext; 5 | import lombok.extern.slf4j.Slf4j; 6 | import org.springframework.stereotype.Component; 7 | 8 | import javax.servlet.http.HttpServletRequest; 9 | 10 | @Component 11 | @Slf4j 12 | public class LogFilter extends ZuulFilter { 13 | @Override 14 | public String filterType() { 15 | return "post"; 16 | } 17 | 18 | @Override 19 | public int filterOrder() { 20 | return 1; 21 | } 22 | 23 | @Override 24 | public boolean shouldFilter() { 25 | return true; 26 | } 27 | 28 | @Override 29 | public Object run() { 30 | RequestContext ctx = RequestContext.getCurrentContext(); 31 | HttpServletRequest request = ctx.getRequest(); 32 | log.info("Request URI {} with METHOD: {}\n" + 33 | "The response code is {}, response body is {}", 34 | request.getRequestURI(), request.getMethod(), 35 | ctx.getResponseStatusCode(), ctx.getResponseBody()); 36 | 37 | return null; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /section-02/order-service/src/test/java/microbucks/orderservice/repository/OrderRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.repository; 2 | 3 | import microbucks.orderservice.model.Order; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; 8 | import org.springframework.test.annotation.Rollback; 9 | import org.springframework.test.context.junit4.SpringRunner; 10 | 11 | import static org.junit.Assert.*; 12 | 13 | @RunWith(SpringRunner.class) 14 | @DataJpaTest 15 | public class OrderRepositoryTest { 16 | @Autowired 17 | private OrderRepository orderRepository; 18 | 19 | @Test 20 | @Rollback 21 | public void testSaveOrder() { 22 | Order order = Order.builder().customer("Foo").barista("bar").build(); 23 | orderRepository.save(order); 24 | Long id = order.getId(); 25 | assertNotNull(id); 26 | assertNotNull(orderRepository.findAll()); 27 | assertEquals("Foo", orderRepository.findOne(id).getCustomer()); 28 | } 29 | 30 | @Test 31 | public void testNoOrderFound() { 32 | assertEquals(0, orderRepository.findAll().size()); 33 | } 34 | } -------------------------------------------------------------------------------- /section-03/order-service/src/test/java/microbucks/orderservice/repository/OrderRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.repository; 2 | 3 | import microbucks.orderservice.model.Order; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; 8 | import org.springframework.test.annotation.Rollback; 9 | import org.springframework.test.context.junit4.SpringRunner; 10 | 11 | import static org.junit.Assert.*; 12 | 13 | @RunWith(SpringRunner.class) 14 | @DataJpaTest 15 | public class OrderRepositoryTest { 16 | @Autowired 17 | private OrderRepository orderRepository; 18 | 19 | @Test 20 | @Rollback 21 | public void testSaveOrder() { 22 | Order order = Order.builder().customer("Foo").barista("bar").build(); 23 | orderRepository.save(order); 24 | Long id = order.getId(); 25 | assertNotNull(id); 26 | assertNotNull(orderRepository.findAll()); 27 | assertEquals("Foo", orderRepository.findOne(id).getCustomer()); 28 | } 29 | 30 | @Test 31 | public void testNoOrderFound() { 32 | assertEquals(0, orderRepository.findAll().size()); 33 | } 34 | } -------------------------------------------------------------------------------- /section-04/order-service/src/test/java/microbucks/orderservice/repository/OrderRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.repository; 2 | 3 | import microbucks.orderservice.model.Order; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; 8 | import org.springframework.test.annotation.Rollback; 9 | import org.springframework.test.context.junit4.SpringRunner; 10 | 11 | import static org.junit.Assert.*; 12 | 13 | @RunWith(SpringRunner.class) 14 | @DataJpaTest 15 | public class OrderRepositoryTest { 16 | @Autowired 17 | private OrderRepository orderRepository; 18 | 19 | @Test 20 | @Rollback 21 | public void testSaveOrder() { 22 | Order order = Order.builder().customer("Foo").barista("bar").build(); 23 | orderRepository.save(order); 24 | Long id = order.getId(); 25 | assertNotNull(id); 26 | assertNotNull(orderRepository.findAll()); 27 | assertEquals("Foo", orderRepository.findOne(id).getCustomer()); 28 | } 29 | 30 | @Test 31 | public void testNoOrderFound() { 32 | assertEquals(0, orderRepository.findAll().size()); 33 | } 34 | } -------------------------------------------------------------------------------- /section-02/order-service/src/main/java/microbucks/orderservice/service/OrderServiceController.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.service; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import microbucks.orderservice.model.Order; 5 | import microbucks.orderservice.repository.OrderRepository; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.PathVariable; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | import java.util.List; 12 | 13 | @RestController 14 | @RequestMapping("/orders") 15 | @Slf4j 16 | public class OrderServiceController { 17 | @Autowired 18 | private OrderRepository orderRepository; 19 | 20 | @RequestMapping("/") 21 | public List getOrders() { 22 | List orders = orderRepository.findAll(); 23 | orders.forEach(o -> log.info("Order[{}] loaded.", o)); 24 | return orders; 25 | } 26 | 27 | @RequestMapping("/{id}") 28 | public Order getOrderById(@PathVariable Long id) { 29 | return orderRepository.findOne(id); 30 | } 31 | 32 | public void setOrderRepository(OrderRepository orderRepository) { 33 | this.orderRepository = orderRepository; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /section-04/order-service/src/main/java/microbucks/orderservice/service/OrderServiceController.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.service; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import microbucks.orderservice.model.Order; 5 | import microbucks.orderservice.repository.OrderRepository; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.PathVariable; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | import java.util.List; 12 | 13 | @RestController 14 | @RequestMapping("/my_orders") 15 | @Slf4j 16 | public class OrderServiceController { 17 | @Autowired 18 | private OrderRepository orderRepository; 19 | 20 | @RequestMapping("/") 21 | public List getOrders() { 22 | List orders = orderRepository.findAll(); 23 | orders.forEach(o -> log.info("Order[{}] loaded.", o)); 24 | return orders; 25 | } 26 | 27 | @RequestMapping("/{id}") 28 | public Order getOrderById(@PathVariable Long id) { 29 | return orderRepository.findOne(id); 30 | } 31 | 32 | public void setOrderRepository(OrderRepository orderRepository) { 33 | this.orderRepository = orderRepository; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /section-05/order-service/src/main/java/microbucks/orderservice/service/OrderServiceController.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.service; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import microbucks.orderservice.model.Order; 5 | import microbucks.orderservice.repository.OrderRepository; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.PathVariable; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | import java.util.List; 12 | 13 | @RestController 14 | @RequestMapping("/orders") 15 | @Slf4j 16 | public class OrderServiceController { 17 | @Autowired 18 | private OrderRepository orderRepository; 19 | 20 | @RequestMapping("/") 21 | public List getOrders() { 22 | List orders = orderRepository.findAll(); 23 | orders.forEach(o -> log.info("Order[{}] loaded.", o)); 24 | return orders; 25 | } 26 | 27 | @RequestMapping("/{id}") 28 | public Order getOrderById(@PathVariable Long id) { 29 | return orderRepository.findOne(id); 30 | } 31 | 32 | public void setOrderRepository(OrderRepository orderRepository) { 33 | this.orderRepository = orderRepository; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /section-03/order-service/src/main/java/microbucks/orderservice/Swagger2Configuration.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import springfox.documentation.builders.ApiInfoBuilder; 6 | import springfox.documentation.builders.PathSelectors; 7 | import springfox.documentation.builders.RequestHandlerSelectors; 8 | import springfox.documentation.service.ApiInfo; 9 | import springfox.documentation.spi.DocumentationType; 10 | import springfox.documentation.spring.web.plugins.Docket; 11 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 12 | 13 | @Configuration 14 | @EnableSwagger2 15 | public class Swagger2Configuration { 16 | @Bean 17 | public Docket productApi() { 18 | return new Docket(DocumentationType.SWAGGER_2) 19 | .apiInfo(buildApiInfo()) 20 | .select() 21 | .apis(RequestHandlerSelectors.basePackage("microbucks.orderservice.service")) 22 | .paths(PathSelectors.any()) 23 | .build(); 24 | } 25 | 26 | private ApiInfo buildApiInfo() { 27 | return new ApiInfoBuilder() 28 | .title("MicroBucks API") 29 | .description("A demo service to show the magic of microservices.") 30 | .build(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /section-06/customer-service/src/main/java/microbucks/customerservice/runner/OrderServiceGetRunner.java: -------------------------------------------------------------------------------- 1 | package microbucks.customerservice.runner; 2 | 3 | import io.grpc.ManagedChannel; 4 | import io.grpc.ManagedChannelBuilder; 5 | import lombok.extern.slf4j.Slf4j; 6 | import microbucks.orderservice.service.OrderProtoService; 7 | import microbucks.orderservice.service.OrderServiceGrpc; 8 | import org.springframework.beans.factory.annotation.Value; 9 | import org.springframework.boot.ApplicationArguments; 10 | import org.springframework.boot.ApplicationRunner; 11 | import org.springframework.stereotype.Component; 12 | 13 | @Component 14 | @Slf4j 15 | public class OrderServiceGetRunner implements ApplicationRunner { 16 | @Value("${grpc.server}") 17 | private String server; 18 | @Value("${grpc.port}") 19 | private int port; 20 | 21 | @Override 22 | public void run(ApplicationArguments args) throws Exception { 23 | ManagedChannel channel = ManagedChannelBuilder.forAddress(server, port) 24 | .usePlaintext(true) // turn off secure 25 | .build(); 26 | OrderServiceGrpc.OrderServiceBlockingStub stub = 27 | OrderServiceGrpc.newBlockingStub(channel); 28 | 29 | OrderProtoService.OrderListResponse response = 30 | stub.getAll(OrderProtoService.GetAllRequest.newBuilder().build()); 31 | response.getOrdersList().forEach(o -> log.info("getAll(): {}", o)); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /section-16/oauth-service/src/main/java/microbucks/oauthservice/AuthorizationServerConfiguration.java: -------------------------------------------------------------------------------- 1 | package microbucks.oauthservice; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.security.oauth2.config.annotation.builders.InMemoryClientDetailsServiceBuilder; 5 | import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer; 6 | import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter; 7 | import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer; 8 | 9 | @Configuration 10 | public class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter { 11 | public void configure(AuthorizationServerSecurityConfigurer securityConfigurer) 12 | throws Exception { 13 | securityConfigurer.checkTokenAccess("isAuthenticated()"); 14 | } 15 | 16 | public void configure(ClientDetailsServiceConfigurer clients) throws Exception { 17 | InMemoryClientDetailsServiceBuilder builder = clients.inMemory(); 18 | builder.withClient("customer").secret("customer") 19 | .scopes("vip") 20 | .authorizedGrantTypes("client_credentials"); 21 | builder.withClient("order").secret("order") 22 | .scopes("vip") 23 | .authorizedGrantTypes("client_credentials"); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /section-02/order-service/src/main/java/microbucks/orderservice/runner/DataInitializerRunner.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.runner; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import microbucks.orderservice.model.Order; 5 | import microbucks.orderservice.repository.OrderRepository; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.beans.factory.annotation.Value; 8 | import org.springframework.boot.CommandLineRunner; 9 | import org.springframework.stereotype.Component; 10 | 11 | import java.util.Arrays; 12 | import java.util.Date; 13 | 14 | @Component 15 | @Slf4j 16 | public class DataInitializerRunner implements CommandLineRunner { 17 | @Autowired 18 | private OrderRepository orderRepository; 19 | @Value("${barista.name}") 20 | private String baristaName; 21 | 22 | @Override 23 | public void run(String... args) throws Exception { 24 | Arrays.asList("LiLei", "HanMeimei").forEach(x -> { 25 | Order order = Order.builder().customer(x).barista(baristaName) 26 | .createTime(new Date()).modifyTime(new Date()).build(); 27 | orderRepository.save(order); 28 | log.info("Saving Order[{}] to database.", order); 29 | }); 30 | } 31 | 32 | public void setOrderRepository(OrderRepository orderRepository) { 33 | this.orderRepository = orderRepository; 34 | } 35 | 36 | public void setBaristaName(String baristaName) { 37 | this.baristaName = baristaName; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /section-03/order-service/src/main/java/microbucks/orderservice/runner/DataInitializerRunner.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.runner; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import microbucks.orderservice.model.Order; 5 | import microbucks.orderservice.repository.OrderRepository; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.beans.factory.annotation.Value; 8 | import org.springframework.boot.CommandLineRunner; 9 | import org.springframework.stereotype.Component; 10 | 11 | import java.util.Arrays; 12 | import java.util.Date; 13 | 14 | @Component 15 | @Slf4j 16 | public class DataInitializerRunner implements CommandLineRunner { 17 | @Autowired 18 | private OrderRepository orderRepository; 19 | @Value("${barista.name}") 20 | private String baristaName; 21 | 22 | @Override 23 | public void run(String... args) throws Exception { 24 | Arrays.asList("LiLei", "HanMeimei").forEach(x -> { 25 | Order order = Order.builder().customer(x).barista(baristaName) 26 | .createTime(new Date()).modifyTime(new Date()).build(); 27 | orderRepository.save(order); 28 | log.info("Saving Order[{}] to database.", order); 29 | }); 30 | } 31 | 32 | public void setOrderRepository(OrderRepository orderRepository) { 33 | this.orderRepository = orderRepository; 34 | } 35 | 36 | public void setBaristaName(String baristaName) { 37 | this.baristaName = baristaName; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /section-04/customer-service/src/main/java/microbucks/customerservice/CustomerServiceApplication.java: -------------------------------------------------------------------------------- 1 | package microbucks.customerservice; 2 | 3 | import com.fasterxml.jackson.databind.DeserializationFeature; 4 | import com.fasterxml.jackson.databind.ObjectMapper; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.boot.builder.SpringApplicationBuilder; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.hateoas.hal.Jackson2HalModule; 9 | import org.springframework.http.MediaType; 10 | import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; 11 | import org.springframework.web.client.RestTemplate; 12 | 13 | import java.util.Arrays; 14 | 15 | @SpringBootApplication 16 | public class CustomerServiceApplication { 17 | 18 | public static void main(String[] args) { 19 | new SpringApplicationBuilder(CustomerServiceApplication.class).web(false).run(args); 20 | } 21 | 22 | @Bean 23 | public RestTemplate restTemplate() { 24 | ObjectMapper mapper = new ObjectMapper(); 25 | mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); 26 | mapper.registerModule(new Jackson2HalModule()); 27 | 28 | MappingJackson2HttpMessageConverter converter = 29 | new MappingJackson2HttpMessageConverter(); 30 | converter.setSupportedMediaTypes(MediaType.parseMediaTypes("application/hal+json")); 31 | converter.setObjectMapper(mapper); 32 | 33 | return new RestTemplate(Arrays.asList(converter)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /section-04/order-service/src/main/java/microbucks/orderservice/runner/DataInitializerRunner.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.runner; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import microbucks.orderservice.model.Order; 5 | import microbucks.orderservice.repository.OrderRepository; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.beans.factory.annotation.Value; 8 | import org.springframework.boot.CommandLineRunner; 9 | import org.springframework.stereotype.Component; 10 | 11 | import java.util.Arrays; 12 | import java.util.Date; 13 | 14 | @Component 15 | @Slf4j 16 | public class DataInitializerRunner implements CommandLineRunner { 17 | @Autowired 18 | private OrderRepository orderRepository; 19 | @Value("${barista.name}") 20 | private String baristaName; 21 | 22 | @Override 23 | public void run(String... args) throws Exception { 24 | Arrays.asList("LiLei", "HanMeimei").forEach(x -> { 25 | Order order = Order.builder().customer(x).barista(baristaName) 26 | .createTime(new Date()).modifyTime(new Date()).build(); 27 | orderRepository.save(order); 28 | log.info("Saving Order[{}] to database.", order); 29 | }); 30 | } 31 | 32 | public void setOrderRepository(OrderRepository orderRepository) { 33 | this.orderRepository = orderRepository; 34 | } 35 | 36 | public void setBaristaName(String baristaName) { 37 | this.baristaName = baristaName; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /section-05/order-service/src/main/java/microbucks/orderservice/runner/DataInitializerRunner.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.runner; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import microbucks.orderservice.model.Order; 5 | import microbucks.orderservice.repository.OrderRepository; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.beans.factory.annotation.Value; 8 | import org.springframework.boot.CommandLineRunner; 9 | import org.springframework.stereotype.Component; 10 | 11 | import java.util.Arrays; 12 | import java.util.Date; 13 | 14 | @Component 15 | @Slf4j 16 | public class DataInitializerRunner implements CommandLineRunner { 17 | @Autowired 18 | private OrderRepository orderRepository; 19 | @Value("${barista.name}") 20 | private String baristaName; 21 | 22 | @Override 23 | public void run(String... args) throws Exception { 24 | Arrays.asList("LiLei", "HanMeimei").forEach(x -> { 25 | Order order = Order.builder().customer(x).barista(baristaName) 26 | .createTime(new Date()).modifyTime(new Date()).build(); 27 | orderRepository.save(order); 28 | log.info("Saving Order[{}] to database.", order); 29 | }); 30 | } 31 | 32 | public void setOrderRepository(OrderRepository orderRepository) { 33 | this.orderRepository = orderRepository; 34 | } 35 | 36 | public void setBaristaName(String baristaName) { 37 | this.baristaName = baristaName; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /section-06/order-service/src/main/java/microbucks/orderservice/runner/DataInitializerRunner.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.runner; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import microbucks.orderservice.model.Order; 5 | import microbucks.orderservice.repository.OrderRepository; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.beans.factory.annotation.Value; 8 | import org.springframework.boot.CommandLineRunner; 9 | import org.springframework.stereotype.Component; 10 | 11 | import java.util.Arrays; 12 | import java.util.Date; 13 | 14 | @Component 15 | @Slf4j 16 | @org.springframework.core.annotation.Order(1) 17 | public class DataInitializerRunner implements CommandLineRunner { 18 | @Autowired 19 | private OrderRepository orderRepository; 20 | @Value("${barista.name}") 21 | private String baristaName; 22 | 23 | @Override 24 | public void run(String... args) throws Exception { 25 | Arrays.asList("LiLei", "HanMeimei").forEach(x -> { 26 | Order order = Order.builder().customer(x).barista(baristaName) 27 | .createTime(new Date()).modifyTime(new Date()).build(); 28 | orderRepository.save(order); 29 | log.info("Saving Order[{}] to database.", order); 30 | }); 31 | } 32 | 33 | public void setOrderRepository(OrderRepository orderRepository) { 34 | this.orderRepository = orderRepository; 35 | } 36 | 37 | public void setBaristaName(String baristaName) { 38 | this.baristaName = baristaName; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /section-16/order-service/src/main/java/microbucks/orderservice/OrderServiceApplication.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice; 2 | 3 | import microbucks.orderservice.stream.OrderStream; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 8 | import org.springframework.cloud.client.loadbalancer.LoadBalanced; 9 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 10 | import org.springframework.cloud.stream.annotation.EnableBinding; 11 | import org.springframework.context.annotation.Bean; 12 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; 13 | import org.springframework.security.oauth2.provider.token.RemoteTokenServices; 14 | import org.springframework.web.client.RestTemplate; 15 | 16 | @SpringBootApplication 17 | @EnableDiscoveryClient 18 | @EnableEurekaClient 19 | @EnableBinding(OrderStream.class) 20 | @EnableResourceServer 21 | public class OrderServiceApplication { 22 | @Autowired 23 | private RestTemplate restTemplate; 24 | 25 | public static void main(String[] args) { 26 | SpringApplication.run(OrderServiceApplication.class, args); 27 | } 28 | 29 | @Bean 30 | @LoadBalanced 31 | public RestTemplate restTemplate() { 32 | return new RestTemplate(); 33 | } 34 | 35 | @Autowired 36 | public void setRemoteTokenServices(RemoteTokenServices services) { 37 | services.setRestTemplate(restTemplate); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /section-14/order-service/src/main/java/microbucks/orderservice/stream/StreamProcessor.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.stream; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import microbucks.orderservice.model.Order; 5 | import microbucks.orderservice.model.Status; 6 | import microbucks.orderservice.repository.OrderRepository; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.beans.factory.annotation.Qualifier; 9 | import org.springframework.cloud.stream.annotation.StreamListener; 10 | import org.springframework.messaging.MessageChannel; 11 | import org.springframework.messaging.support.MessageBuilder; 12 | import org.springframework.stereotype.Component; 13 | 14 | import java.util.Date; 15 | 16 | @Component 17 | @Slf4j 18 | public class StreamProcessor { 19 | @Autowired 20 | private OrderRepository orderRepository; 21 | 22 | @Autowired 23 | @Qualifier("barista") 24 | private MessageChannel barista; 25 | 26 | @StreamListener("order") 27 | public void handle(Order order) { 28 | if (order == null) { 29 | return; 30 | } 31 | 32 | Order savedOrder = orderRepository.findOne(order.getId()); 33 | savedOrder.setBarista(order.getBarista()); 34 | savedOrder.setState(Status.READY); 35 | savedOrder.setModifyTime(new Date()); 36 | orderRepository.save(savedOrder); 37 | log.info("Order is READY! {}", savedOrder); 38 | } 39 | 40 | public void sendOrder(Order order) { 41 | log.info("send order {} to barista", order.getId()); 42 | barista.send(MessageBuilder.withPayload(order).build()); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /section-15/order-service/src/main/java/microbucks/orderservice/stream/StreamProcessor.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.stream; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import microbucks.orderservice.model.Order; 5 | import microbucks.orderservice.model.Status; 6 | import microbucks.orderservice.repository.OrderRepository; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.beans.factory.annotation.Qualifier; 9 | import org.springframework.cloud.stream.annotation.StreamListener; 10 | import org.springframework.messaging.MessageChannel; 11 | import org.springframework.messaging.support.MessageBuilder; 12 | import org.springframework.stereotype.Component; 13 | 14 | import java.util.Date; 15 | 16 | @Component 17 | @Slf4j 18 | public class StreamProcessor { 19 | @Autowired 20 | private OrderRepository orderRepository; 21 | 22 | @Autowired 23 | @Qualifier("barista") 24 | private MessageChannel barista; 25 | 26 | @StreamListener("order") 27 | public void handle(Order order) { 28 | if (order == null) { 29 | return; 30 | } 31 | 32 | Order savedOrder = orderRepository.findOne(order.getId()); 33 | savedOrder.setBarista(order.getBarista()); 34 | savedOrder.setState(Status.READY); 35 | savedOrder.setModifyTime(new Date()); 36 | orderRepository.save(savedOrder); 37 | log.info("Order is READY! {}", savedOrder); 38 | } 39 | 40 | public void sendOrder(Order order) { 41 | log.info("send order {} to barista", order.getId()); 42 | barista.send(MessageBuilder.withPayload(order).build()); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /section-16/order-service/src/main/java/microbucks/orderservice/stream/StreamProcessor.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.stream; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import microbucks.orderservice.model.Order; 5 | import microbucks.orderservice.model.Status; 6 | import microbucks.orderservice.repository.OrderRepository; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.beans.factory.annotation.Qualifier; 9 | import org.springframework.cloud.stream.annotation.StreamListener; 10 | import org.springframework.messaging.MessageChannel; 11 | import org.springframework.messaging.support.MessageBuilder; 12 | import org.springframework.stereotype.Component; 13 | 14 | import java.util.Date; 15 | 16 | @Component 17 | @Slf4j 18 | public class StreamProcessor { 19 | @Autowired 20 | private OrderRepository orderRepository; 21 | 22 | @Autowired 23 | @Qualifier("barista") 24 | private MessageChannel barista; 25 | 26 | @StreamListener("order") 27 | public void handle(Order order) { 28 | if (order == null) { 29 | return; 30 | } 31 | 32 | Order savedOrder = orderRepository.findOne(order.getId()); 33 | savedOrder.setBarista(order.getBarista()); 34 | savedOrder.setState(Status.READY); 35 | savedOrder.setModifyTime(new Date()); 36 | orderRepository.save(savedOrder); 37 | log.info("Order is READY! {}", savedOrder); 38 | } 39 | 40 | public void sendOrder(Order order) { 41 | log.info("send order {} to barista", order.getId()); 42 | barista.send(MessageBuilder.withPayload(order).build()); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /section-02/order-service/src/test/java/microbucks/orderservice/runner/DataInitializerRunnerTest.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.runner; 2 | 3 | import microbucks.orderservice.model.Order; 4 | import microbucks.orderservice.repository.OrderRepository; 5 | import org.junit.After; 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.mockito.Mock; 10 | import org.mockito.junit.MockitoJUnitRunner; 11 | 12 | import static org.junit.Assert.assertNotNull; 13 | import static org.mockito.Mockito.any; 14 | import static org.mockito.Mockito.argThat; 15 | import static org.mockito.Mockito.times; 16 | import static org.mockito.Mockito.verify; 17 | 18 | @RunWith(MockitoJUnitRunner.class) 19 | public class DataInitializerRunnerTest { 20 | @Mock 21 | private OrderRepository orderRepository; 22 | private DataInitializerRunner dataInitializerRunner; 23 | 24 | @Before 25 | public void setUp() throws Exception { 26 | dataInitializerRunner = new DataInitializerRunner(); 27 | dataInitializerRunner.setOrderRepository(orderRepository); 28 | dataInitializerRunner.setBaristaName("M"); 29 | } 30 | 31 | @After 32 | public void tearDown() throws Exception { 33 | dataInitializerRunner = null; 34 | } 35 | 36 | @Test 37 | public void testRun() throws Exception { 38 | assertNotNull(orderRepository); 39 | assertNotNull(dataInitializerRunner); 40 | 41 | dataInitializerRunner.run(); 42 | verify(orderRepository, times(2)).save(any(Order.class)); 43 | verify(orderRepository).save(argThat((Order o) -> o.getCustomer().equals("LiLei"))); 44 | } 45 | } -------------------------------------------------------------------------------- /section-03/order-service/src/test/java/microbucks/orderservice/runner/DataInitializerRunnerTest.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.runner; 2 | 3 | import microbucks.orderservice.model.Order; 4 | import microbucks.orderservice.repository.OrderRepository; 5 | import org.junit.After; 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.mockito.Mock; 10 | import org.mockito.junit.MockitoJUnitRunner; 11 | 12 | import static org.junit.Assert.assertNotNull; 13 | import static org.mockito.Mockito.any; 14 | import static org.mockito.Mockito.argThat; 15 | import static org.mockito.Mockito.times; 16 | import static org.mockito.Mockito.verify; 17 | 18 | @RunWith(MockitoJUnitRunner.class) 19 | public class DataInitializerRunnerTest { 20 | @Mock 21 | private OrderRepository orderRepository; 22 | private DataInitializerRunner dataInitializerRunner; 23 | 24 | @Before 25 | public void setUp() throws Exception { 26 | dataInitializerRunner = new DataInitializerRunner(); 27 | dataInitializerRunner.setOrderRepository(orderRepository); 28 | dataInitializerRunner.setBaristaName("M"); 29 | } 30 | 31 | @After 32 | public void tearDown() throws Exception { 33 | dataInitializerRunner = null; 34 | } 35 | 36 | @Test 37 | public void testRun() throws Exception { 38 | assertNotNull(orderRepository); 39 | assertNotNull(dataInitializerRunner); 40 | 41 | dataInitializerRunner.run(); 42 | verify(orderRepository, times(2)).save(any(Order.class)); 43 | verify(orderRepository).save(argThat((Order o) -> o.getCustomer().equals("LiLei"))); 44 | } 45 | } -------------------------------------------------------------------------------- /section-04/order-service/src/test/java/microbucks/orderservice/runner/DataInitializerRunnerTest.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.runner; 2 | 3 | import microbucks.orderservice.model.Order; 4 | import microbucks.orderservice.repository.OrderRepository; 5 | import org.junit.After; 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.mockito.Mock; 10 | import org.mockito.junit.MockitoJUnitRunner; 11 | 12 | import static org.junit.Assert.assertNotNull; 13 | import static org.mockito.Mockito.any; 14 | import static org.mockito.Mockito.argThat; 15 | import static org.mockito.Mockito.times; 16 | import static org.mockito.Mockito.verify; 17 | 18 | @RunWith(MockitoJUnitRunner.class) 19 | public class DataInitializerRunnerTest { 20 | @Mock 21 | private OrderRepository orderRepository; 22 | private DataInitializerRunner dataInitializerRunner; 23 | 24 | @Before 25 | public void setUp() throws Exception { 26 | dataInitializerRunner = new DataInitializerRunner(); 27 | dataInitializerRunner.setOrderRepository(orderRepository); 28 | dataInitializerRunner.setBaristaName("M"); 29 | } 30 | 31 | @After 32 | public void tearDown() throws Exception { 33 | dataInitializerRunner = null; 34 | } 35 | 36 | @Test 37 | public void testRun() throws Exception { 38 | assertNotNull(orderRepository); 39 | assertNotNull(dataInitializerRunner); 40 | 41 | dataInitializerRunner.run(); 42 | verify(orderRepository, times(2)).save(any(Order.class)); 43 | verify(orderRepository).save(argThat((Order o) -> o.getCustomer().equals("LiLei"))); 44 | } 45 | } -------------------------------------------------------------------------------- /section-04/customer-service/src/main/java/microbucks/customerservice/runner/OrderServiceGetRunner.java: -------------------------------------------------------------------------------- 1 | package microbucks.customerservice.runner; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import microbucks.customerservice.model.Order; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.beans.factory.annotation.Value; 7 | import org.springframework.boot.ApplicationArguments; 8 | import org.springframework.boot.ApplicationRunner; 9 | import org.springframework.core.ParameterizedTypeReference; 10 | import org.springframework.hateoas.Link; 11 | import org.springframework.hateoas.PagedResources; 12 | import org.springframework.http.HttpMethod; 13 | import org.springframework.stereotype.Component; 14 | import org.springframework.web.client.RestTemplate; 15 | import org.springframework.web.util.UriComponentsBuilder; 16 | 17 | import java.net.URI; 18 | 19 | @Component 20 | @Slf4j 21 | public class OrderServiceGetRunner implements ApplicationRunner { 22 | @Autowired 23 | private RestTemplate restTemplate; 24 | 25 | @Value("${orderservice.url}") 26 | private String orderServiceUrl; 27 | 28 | @Override 29 | public void run(ApplicationArguments args) throws Exception { 30 | URI uri = UriComponentsBuilder.fromUriString(orderServiceUrl + "/").build().toUri(); 31 | PagedResources resources = 32 | restTemplate.exchange(uri, HttpMethod.GET, null, 33 | new ParameterizedTypeReference>() { 34 | }).getBody(); 35 | log.info("get orders from Link: {}", resources.getLink(Link.REL_SELF)); 36 | resources.getContent().forEach(o -> log.info("get Order[{}]", o)); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /section-03/order-service/src/main/java/microbucks/orderservice/service/OrderServiceController.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.service; 2 | 3 | import io.swagger.annotations.Api; 4 | import io.swagger.annotations.ApiImplicitParam; 5 | import io.swagger.annotations.ApiOperation; 6 | import lombok.extern.slf4j.Slf4j; 7 | import microbucks.orderservice.model.Order; 8 | import microbucks.orderservice.repository.OrderRepository; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.http.MediaType; 11 | import org.springframework.web.bind.annotation.PathVariable; 12 | import org.springframework.web.bind.annotation.RequestMapping; 13 | import org.springframework.web.bind.annotation.RestController; 14 | 15 | import java.util.List; 16 | 17 | @RestController 18 | @RequestMapping("/orders") 19 | @Slf4j 20 | @Api("the services related to Order") 21 | public class OrderServiceController { 22 | @Autowired 23 | private OrderRepository orderRepository; 24 | 25 | @RequestMapping("/") 26 | @ApiOperation(value = "get the list of orders", response = List.class) 27 | public List getOrders() { 28 | List orders = orderRepository.findAll(); 29 | orders.forEach(o -> log.info("Order[{}] loaded.", o)); 30 | return orders; 31 | } 32 | 33 | @RequestMapping("/{id}") 34 | @ApiOperation(value = "get one detail order", response = Order.class) 35 | @ApiImplicitParam(value = "orderId", name = "id", required = true) 36 | public Order getOrderById(@PathVariable Long id) { 37 | return orderRepository.findOne(id); 38 | } 39 | 40 | public void setOrderRepository(OrderRepository orderRepository) { 41 | this.orderRepository = orderRepository; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /section-03/customer-service/src/main/java/microbucks/customerservice/runner/OrderServiceGetRunner.java: -------------------------------------------------------------------------------- 1 | package microbucks.customerservice.runner; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import microbucks.customerservice.model.Order; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.beans.factory.annotation.Value; 7 | import org.springframework.boot.ApplicationArguments; 8 | import org.springframework.boot.ApplicationRunner; 9 | import org.springframework.core.ParameterizedTypeReference; 10 | import org.springframework.http.HttpMethod; 11 | import org.springframework.stereotype.Component; 12 | import org.springframework.web.client.RestTemplate; 13 | 14 | import java.util.ArrayList; 15 | 16 | @Component 17 | @Slf4j 18 | public class OrderServiceGetRunner implements ApplicationRunner { 19 | @Autowired 20 | private RestTemplate restTemplate; 21 | 22 | @Value("${orderservice.url}") 23 | private String orderServiceUrl; 24 | 25 | @Override 26 | public void run(ApplicationArguments args) throws Exception { 27 | String ordersStr = restTemplate.getForObject(orderServiceUrl + "/", String.class); 28 | log.info("Simply getForObject(): {}", ordersStr); 29 | 30 | Order order = restTemplate.getForObject(orderServiceUrl+ "/{id}", Order.class, "1"); 31 | log.info("Simply get one order: {}", order); 32 | 33 | ParameterizedTypeReference> ptr = 34 | new ParameterizedTypeReference>() {}; 35 | ArrayList response = 36 | restTemplate.exchange(orderServiceUrl + "/", HttpMethod.GET, null, ptr).getBody(); 37 | for (Order o : response) { 38 | log.info("exchange with type, order: {}", o); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /section-03/customer-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | microbucks 7 | customer-service 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | customer-service 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.7.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-web 31 | 32 | 33 | 34 | org.projectlombok 35 | lombok 36 | true 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-test 41 | test 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.springframework.boot 49 | spring-boot-maven-plugin 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /section-07/customer-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | microbucks 7 | customer-service 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | customer-service 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.7.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-web 31 | 32 | 33 | 34 | org.projectlombok 35 | lombok 36 | true 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-test 41 | test 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.springframework.boot 49 | spring-boot-maven-plugin 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /section-02/order-service/src/test/java/microbucks/orderservice/OrderServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | import org.springframework.http.MediaType; 9 | import org.springframework.test.context.junit4.SpringRunner; 10 | import org.springframework.test.web.servlet.MockMvc; 11 | 12 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; 13 | import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.log; 14 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; 15 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; 16 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; 17 | 18 | @RunWith(SpringRunner.class) 19 | @SpringBootTest 20 | @AutoConfigureMockMvc 21 | public class OrderServiceApplicationTests { 22 | @Autowired 23 | private MockMvc mockMvc; 24 | 25 | @Test 26 | public void testGetOrders() throws Exception { 27 | mockMvc.perform(get("/orders/")) 28 | .andDo(log()) 29 | .andExpect(status().isOk()) 30 | .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) 31 | .andExpect(jsonPath("$").isArray()) 32 | .andExpect(jsonPath("$[0].customer").value("LiLei")); 33 | } 34 | 35 | @Test 36 | public void testGetOrderOne() throws Exception { 37 | mockMvc.perform(get("/orders/1")) 38 | .andDo(log()) 39 | .andExpect(jsonPath("$.id").value(1)); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /section-03/order-service/src/test/java/microbucks/orderservice/OrderServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | import org.springframework.http.MediaType; 9 | import org.springframework.test.context.junit4.SpringRunner; 10 | import org.springframework.test.web.servlet.MockMvc; 11 | 12 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; 13 | import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.log; 14 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; 15 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; 16 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; 17 | 18 | @RunWith(SpringRunner.class) 19 | @SpringBootTest 20 | @AutoConfigureMockMvc 21 | public class OrderServiceApplicationTests { 22 | @Autowired 23 | private MockMvc mockMvc; 24 | 25 | @Test 26 | public void testGetOrders() throws Exception { 27 | mockMvc.perform(get("/orders/")) 28 | .andDo(log()) 29 | .andExpect(status().isOk()) 30 | .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) 31 | .andExpect(jsonPath("$").isArray()) 32 | .andExpect(jsonPath("$[0].customer").value("LiLei")); 33 | } 34 | 35 | @Test 36 | public void testGetOrderOne() throws Exception { 37 | mockMvc.perform(get("/orders/1")) 38 | .andDo(log()) 39 | .andExpect(jsonPath("$.id").value(1)); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /section-04/order-service/src/test/java/microbucks/orderservice/OrderServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | import org.springframework.http.MediaType; 9 | import org.springframework.test.context.junit4.SpringRunner; 10 | import org.springframework.test.web.servlet.MockMvc; 11 | 12 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; 13 | import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.log; 14 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; 15 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; 16 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; 17 | 18 | @RunWith(SpringRunner.class) 19 | @SpringBootTest 20 | @AutoConfigureMockMvc 21 | public class OrderServiceApplicationTests { 22 | @Autowired 23 | private MockMvc mockMvc; 24 | 25 | @Test 26 | public void testGetOrders() throws Exception { 27 | mockMvc.perform(get("/orders/")) 28 | .andDo(log()) 29 | .andExpect(status().isOk()) 30 | .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) 31 | .andExpect(jsonPath("$").isArray()) 32 | .andExpect(jsonPath("$[0].customer").value("LiLei")); 33 | } 34 | 35 | @Test 36 | public void testGetOrderOne() throws Exception { 37 | mockMvc.perform(get("/orders/1")) 38 | .andDo(log()) 39 | .andExpect(jsonPath("$.id").value(1)); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /section-05/order-service/src/test/java/microbucks/orderservice/OrderServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | import org.springframework.http.MediaType; 9 | import org.springframework.test.context.junit4.SpringRunner; 10 | import org.springframework.test.web.servlet.MockMvc; 11 | 12 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; 13 | import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.log; 14 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; 15 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; 16 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; 17 | 18 | @RunWith(SpringRunner.class) 19 | @SpringBootTest 20 | @AutoConfigureMockMvc 21 | public class OrderServiceApplicationTests { 22 | @Autowired 23 | private MockMvc mockMvc; 24 | 25 | @Test 26 | public void testGetOrders() throws Exception { 27 | mockMvc.perform(get("/orders/")) 28 | .andDo(log()) 29 | .andExpect(status().isOk()) 30 | .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) 31 | .andExpect(jsonPath("$").isArray()) 32 | .andExpect(jsonPath("$[0].customer").value("LiLei")); 33 | } 34 | 35 | @Test 36 | public void testGetOrderOne() throws Exception { 37 | mockMvc.perform(get("/orders/1")) 38 | .andDo(log()) 39 | .andExpect(jsonPath("$.id").value(1)); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /section-06/order-service/src/test/java/microbucks/orderservice/OrderServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | import org.springframework.http.MediaType; 9 | import org.springframework.test.context.junit4.SpringRunner; 10 | import org.springframework.test.web.servlet.MockMvc; 11 | 12 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; 13 | import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.log; 14 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; 15 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; 16 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; 17 | 18 | @RunWith(SpringRunner.class) 19 | @SpringBootTest 20 | @AutoConfigureMockMvc 21 | public class OrderServiceApplicationTests { 22 | @Autowired 23 | private MockMvc mockMvc; 24 | 25 | @Test 26 | public void testGetOrders() throws Exception { 27 | mockMvc.perform(get("/orders/")) 28 | .andDo(log()) 29 | .andExpect(status().isOk()) 30 | .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) 31 | .andExpect(jsonPath("$").isArray()) 32 | .andExpect(jsonPath("$[0].customer").value("LiLei")); 33 | } 34 | 35 | @Test 36 | public void testGetOrderOne() throws Exception { 37 | mockMvc.perform(get("/orders/1")) 38 | .andDo(log()) 39 | .andExpect(jsonPath("$.id").value(1)); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /section-04/customer-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | microbucks 7 | customer-service 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | customer-service 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.7.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-web 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-data-rest 35 | 36 | 37 | 38 | org.projectlombok 39 | lombok 40 | true 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-starter-test 45 | test 46 | 47 | 48 | 49 | 50 | 51 | 52 | org.springframework.boot 53 | spring-boot-maven-plugin 54 | 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /section-08/eureka-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | microbucks 7 | eureka-server 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | eureka-server 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.7.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Dalston.SR4 26 | 27 | 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-starter-eureka-server 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-test 37 | test 38 | 39 | 40 | 41 | 42 | 43 | 44 | org.springframework.cloud 45 | spring-cloud-dependencies 46 | ${spring-cloud.version} 47 | pom 48 | import 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.springframework.boot 57 | spring-boot-maven-plugin 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /section-10/hystrix-dashboard/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | microbucks 7 | hystrix-dashboard 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | hystrix-dashboard 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.7.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Dalston.SR4 26 | 27 | 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-starter-hystrix-dashboard 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-test 37 | test 38 | 39 | 40 | 41 | 42 | 43 | 44 | org.springframework.cloud 45 | spring-cloud-dependencies 46 | ${spring-cloud.version} 47 | pom 48 | import 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.springframework.boot 57 | spring-boot-maven-plugin 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /section-01/order-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | microbucks 7 | order-service 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | order-service 12 | Order services for the coffee shop 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.7.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-data-jpa 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-web 35 | 36 | 37 | 38 | com.h2database 39 | h2 40 | runtime 41 | 42 | 43 | org.projectlombok 44 | lombok 45 | true 46 | 47 | 48 | org.springframework.boot 49 | spring-boot-starter-test 50 | test 51 | 52 | 53 | 54 | 55 | 56 | 57 | org.springframework.boot 58 | spring-boot-maven-plugin 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /section-05/customer-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | microbucks 7 | customer-service 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | customer-service 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.7.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-web 31 | 32 | 33 | 34 | com.alibaba 35 | dubbo 36 | 2.5.5 37 | 38 | 39 | com.101tec 40 | zkclient 41 | 0.10 42 | 43 | 44 | 45 | org.projectlombok 46 | lombok 47 | true 48 | 49 | 50 | org.springframework.boot 51 | spring-boot-starter-test 52 | test 53 | 54 | 55 | 56 | 57 | 58 | 59 | org.springframework.boot 60 | spring-boot-maven-plugin 61 | 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /section-02/order-service/src/test/java/microbucks/orderservice/service/OrderServiceControllerTest.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.service; 2 | 3 | import microbucks.orderservice.model.Order; 4 | import microbucks.orderservice.repository.OrderRepository; 5 | import org.junit.After; 6 | import org.junit.Before; 7 | import org.junit.Rule; 8 | import org.junit.Test; 9 | import org.mockito.Mock; 10 | import org.mockito.junit.MockitoJUnit; 11 | import org.mockito.junit.MockitoRule; 12 | import org.mockito.quality.Strictness; 13 | 14 | import static org.junit.Assert.assertEquals; 15 | import static org.junit.Assert.assertNull; 16 | import static org.mockito.Mockito.anyLong; 17 | import static org.mockito.Mockito.never; 18 | import static org.mockito.Mockito.only; 19 | import static org.mockito.Mockito.reset; 20 | import static org.mockito.Mockito.verify; 21 | import static org.mockito.Mockito.when; 22 | 23 | public class OrderServiceControllerTest { 24 | @Rule 25 | public MockitoRule rule = MockitoJUnit.rule().strictness(Strictness.STRICT_STUBS); 26 | @Mock 27 | private OrderRepository orderRepository; 28 | private OrderServiceController orderServiceController; 29 | 30 | @Before 31 | public void setUp() throws Exception { 32 | orderServiceController = new OrderServiceController(); 33 | orderServiceController.setOrderRepository(orderRepository); 34 | } 35 | 36 | @After 37 | public void tearDown() throws Exception { 38 | orderServiceController = null; 39 | reset(orderRepository); 40 | } 41 | 42 | @Test 43 | public void testGetOrders() throws Exception { 44 | orderServiceController.getOrders(); 45 | verify(orderRepository, only()).findAll(); 46 | verify(orderRepository, never()).findOne(anyLong()); 47 | } 48 | 49 | @Test 50 | public void getGetOrderById() throws Exception { 51 | Order order = Order.builder().id(1L).barista("M").customer("LiLei").build(); 52 | when(orderRepository.findOne(1L)).thenReturn(order); 53 | Order retrieved = orderServiceController.getOrderById(1L); 54 | assertEquals(order, retrieved); 55 | assertNull(orderServiceController.getOrderById(2L)); 56 | } 57 | } -------------------------------------------------------------------------------- /section-04/order-service/src/test/java/microbucks/orderservice/service/OrderServiceControllerTest.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.service; 2 | 3 | import microbucks.orderservice.model.Order; 4 | import microbucks.orderservice.repository.OrderRepository; 5 | import org.junit.After; 6 | import org.junit.Before; 7 | import org.junit.Rule; 8 | import org.junit.Test; 9 | import org.mockito.Mock; 10 | import org.mockito.junit.MockitoJUnit; 11 | import org.mockito.junit.MockitoRule; 12 | import org.mockito.quality.Strictness; 13 | 14 | import static org.junit.Assert.assertEquals; 15 | import static org.junit.Assert.assertNull; 16 | import static org.mockito.Mockito.anyLong; 17 | import static org.mockito.Mockito.never; 18 | import static org.mockito.Mockito.only; 19 | import static org.mockito.Mockito.reset; 20 | import static org.mockito.Mockito.verify; 21 | import static org.mockito.Mockito.when; 22 | 23 | public class OrderServiceControllerTest { 24 | @Rule 25 | public MockitoRule rule = MockitoJUnit.rule().strictness(Strictness.STRICT_STUBS); 26 | @Mock 27 | private OrderRepository orderRepository; 28 | private OrderServiceController orderServiceController; 29 | 30 | @Before 31 | public void setUp() throws Exception { 32 | orderServiceController = new OrderServiceController(); 33 | orderServiceController.setOrderRepository(orderRepository); 34 | } 35 | 36 | @After 37 | public void tearDown() throws Exception { 38 | orderServiceController = null; 39 | reset(orderRepository); 40 | } 41 | 42 | @Test 43 | public void testGetOrders() throws Exception { 44 | orderServiceController.getOrders(); 45 | verify(orderRepository, only()).findAll(); 46 | verify(orderRepository, never()).findOne(anyLong()); 47 | } 48 | 49 | @Test 50 | public void getGetOrderById() throws Exception { 51 | Order order = Order.builder().id(1L).barista("M").customer("LiLei").build(); 52 | when(orderRepository.findOne(1L)).thenReturn(order); 53 | Order retrieved = orderServiceController.getOrderById(1L); 54 | assertEquals(order, retrieved); 55 | assertNull(orderServiceController.getOrderById(2L)); 56 | } 57 | } -------------------------------------------------------------------------------- /section-03/order-service/src/test/java/microbucks/orderservice/service/OrderServiceControllerTest.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.service; 2 | 3 | import microbucks.orderservice.model.Order; 4 | import microbucks.orderservice.repository.OrderRepository; 5 | import org.junit.After; 6 | import org.junit.Before; 7 | import org.junit.Rule; 8 | import org.junit.Test; 9 | import org.mockito.Mock; 10 | import org.mockito.junit.MockitoJUnit; 11 | import org.mockito.junit.MockitoRule; 12 | import org.mockito.quality.Strictness; 13 | 14 | import static org.junit.Assert.assertEquals; 15 | import static org.junit.Assert.assertNull; 16 | import static org.mockito.Mockito.anyLong; 17 | import static org.mockito.Mockito.never; 18 | import static org.mockito.Mockito.only; 19 | import static org.mockito.Mockito.reset; 20 | import static org.mockito.Mockito.verify; 21 | import static org.mockito.Mockito.when; 22 | 23 | public class OrderServiceControllerTest { 24 | @Rule 25 | public MockitoRule rule = MockitoJUnit.rule().strictness(Strictness.STRICT_STUBS); 26 | 27 | @Mock 28 | private OrderRepository orderRepository; 29 | private OrderServiceController orderServiceController; 30 | 31 | @Before 32 | public void setUp() throws Exception { 33 | orderServiceController = new OrderServiceController(); 34 | orderServiceController.setOrderRepository(orderRepository); 35 | } 36 | 37 | @After 38 | public void tearDown() throws Exception { 39 | orderServiceController = null; 40 | reset(orderRepository); 41 | } 42 | 43 | @Test 44 | public void testGetOrders() throws Exception { 45 | orderServiceController.getOrders(); 46 | verify(orderRepository, only()).findAll(); 47 | verify(orderRepository, never()).findOne(anyLong()); 48 | } 49 | 50 | @Test 51 | public void getGetOrderById() throws Exception { 52 | Order order = Order.builder().id(1L).barista("M").customer("LiLei").build(); 53 | when(orderRepository.findOne(1L)).thenReturn(order); 54 | Order retrieved = orderServiceController.getOrderById(1L); 55 | assertEquals(order, retrieved); 56 | assertNull(orderServiceController.getOrderById(2L)); 57 | } 58 | } -------------------------------------------------------------------------------- /section-07/order-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | microbucks 7 | order-service 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | order-service 12 | Order services for the coffee shop 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.7.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-data-jpa 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-web 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-starter-actuator 39 | 40 | 41 | 42 | com.h2database 43 | h2 44 | runtime 45 | 46 | 47 | org.projectlombok 48 | lombok 49 | true 50 | 51 | 52 | org.springframework.boot 53 | spring-boot-starter-test 54 | test 55 | 56 | 57 | 58 | 59 | 60 | 61 | org.springframework.boot 62 | spring-boot-maven-plugin 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /section-06/order-service/src/main/java/microbucks/orderservice/service/OrderServiceImpl.java: -------------------------------------------------------------------------------- 1 | package microbucks.orderservice.service; 2 | 3 | import com.google.protobuf.Timestamp; 4 | import io.grpc.stub.StreamObserver; 5 | import lombok.extern.slf4j.Slf4j; 6 | import microbucks.orderservice.repository.OrderRepository; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Service; 9 | 10 | @Service 11 | @Slf4j 12 | public class OrderServiceImpl extends OrderServiceGrpc.OrderServiceImplBase { 13 | @Autowired 14 | private OrderRepository orderRepository; 15 | 16 | @Override 17 | public void getAll(OrderProtoService.GetAllRequest request, 18 | StreamObserver responseObserver) { 19 | OrderProtoService.OrderListResponse.Builder builder = 20 | OrderProtoService.OrderListResponse.newBuilder(); 21 | orderRepository.findAll().forEach( 22 | (microbucks.orderservice.model.Order o) -> builder.addOrders(convert(o))); 23 | OrderProtoService.OrderListResponse response = builder.build(); 24 | log.info("getAll() returns {} order(s).", response.getOrdersCount()); 25 | responseObserver.onNext(response); 26 | responseObserver.onCompleted(); 27 | } 28 | 29 | @Override 30 | public void getOrderById(OrderProtoService.GetOrderByIdRequest request, 31 | StreamObserver responseObserver) { 32 | Long id = request.getId(); 33 | OrderModel.Order order = convert(orderRepository.findOne(id)); 34 | log.info("getOrderById({}) return {}", id, order); 35 | responseObserver.onNext(order); 36 | responseObserver.onCompleted(); 37 | } 38 | 39 | private OrderModel.Order convert(microbucks.orderservice.model.Order o) { 40 | return OrderModel.Order.newBuilder() 41 | .setId(o.getId()) 42 | .setBarista(o.getBarista()) 43 | .setCustomer(o.getCustomer()) 44 | .setCreateTime(Timestamp.newBuilder().setSeconds(o.getCreateTime().getTime()).build()) 45 | .setCreateTime(Timestamp.newBuilder().setSeconds(o.getModifyTime().getTime()).build()) 46 | .build(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Practical Java Microservices 2 | 3 | 一些基于Spring Boot的微服务实例。 4 | 5 | ## Section 01 6 | 7 | 一个简单的微服务,查询一些简单的订单。 8 | 9 | 基于如下技术: 10 | 11 | 1. Spring Boot 12 | 2. Spring Data JPA访问数据 13 | 3. H2内存数据库作为数据存储 14 | 4. Spring MVC实现REST接口 15 | 5. Lombok简化代码 16 | 17 | ## Section 02 18 | 19 | 在Section 01的基础上,演示了Spring Boot的一些特性: 20 | 21 | 1. 修改一些常用参数 22 | 2. 替换日志框架spring-boot-starter-log4j2 23 | 3. 用Jetty替换Tomcat 24 | 4. Actuator 25 | 26 | ## Section 03 27 | 28 | 在Section 02的基础上,增加了一个客户端,使用`RestTemplate`进行服务调用。 29 | 30 | 为服务增加了文档说明,使用了以下两种技术: 31 | 32 | 1. Spring REST Docs 33 | 2. Swagger(SpringFox) 34 | 35 | ## Section 04 36 | 37 | 在Section 02的基础上,引入了HAL,使用Spring Data REST演示了简单的HATEOAS。 38 | 39 | ## Section 05 40 | 41 | 基于Section 01的代码,将服务提供方改为通过Dubbo发布服务。调用方同样使用Dubbo。 42 | 43 | 需要在本机启动一个Zookeeper,监听2181端口。 44 | 45 | ## Section 06 46 | 47 | 与Section 05类似,但不使用Dubbo,改用gRPC来提供服务。 48 | 49 | ## Section 07 50 | 51 | 完善Section 01的服务端和Section 03的客户端例子。丰富了Order实体的内容与状态。 52 | 53 | ## Section 08 54 | 55 | 在Section 07的基础上,使用Spring Cloud的服务发现和注册机制,使用Eureka作为注册中心,客户端使用Ribbon来做负载均衡。 56 | 57 | ## Section 09 58 | 59 | 将Section 08的Eureka替换成ZooKeeper和Consul。需要在本地启动ZooKeeper和Consul的服务。 60 | 61 | ## Section 10 62 | 63 | 在Section 09的基础上,为customer-service增加了断路器,调整了客户端的实现,通过POST调用触发操作,并演示了DashBoard功能。 64 | 65 | ## Section 11 66 | 67 | 在Section 09的基础上,将客户端从Ribbon替换为Feign。 68 | 69 | 注意,服务端的响应码需要>=200。 70 | 71 | ## Section 12 72 | 73 | 将Section 09的order-service放到Zuul代理背后,简单演示了ZuulProxy。 74 | 75 | ## Section 13 76 | 77 | 演示了Spring Cloud Config的功能,包含如下内容: 78 | 79 | 1. 基于Git的配置管理 80 | 2. 通过服务发现找到配置中心 81 | 3. 配置加解密 82 | 83 | ## Section 14 84 | 85 | 基于Section 08的order-service,增加了Spring Cloud Stream的消息机制。 86 | 87 | 新增了barista-service,作为咖啡师,通过消息推进订单状态。 88 | 89 | 需要在本地启动一个RabbitMQ,监听5672端口,默认用户名密码guest/guest。 90 | 91 | ## Section 15 92 | 93 | 通过Spring Cloud Sleuth将Section 14的order-service和barista-service,以及Section 09的customer-service串联起来。 94 | 95 | 这里用到了: 96 | 97 | 1. Spring Cloud Sleuth 98 | 2. Spring Cloud Stream 99 | 3. Zipkin Server 100 | 4. Zipkin Web 101 | 5. Eureka 102 | 103 | 需要在本地5672启动一个RabbitMQ。 104 | 105 | ## Section 16 106 | 107 | 在Section 15的基础上,增加了OAuth 2.0的客户端模式认证。 108 | 109 | 这里为了让OAuth相关的RestTemplate也支持LoadBalanced和Trace,做了些额外配置 -------------------------------------------------------------------------------- /section-08/customer-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | microbucks 7 | customer-service 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | customer-service 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.7.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Dalston.SR4 26 | 27 | 28 | 29 | 30 | 31 | org.springframework.cloud 32 | spring-cloud-dependencies 33 | ${spring-cloud.version} 34 | pom 35 | import 36 | 37 | 38 | 39 | 40 | 41 | 42 | org.springframework.boot 43 | spring-boot-starter-web 44 | 45 | 46 | org.springframework.cloud 47 | spring-cloud-starter-eureka 48 | 49 | 50 | 51 | org.projectlombok 52 | lombok 53 | true 54 | 55 | 56 | org.springframework.boot 57 | spring-boot-starter-test 58 | test 59 | 60 | 61 | 62 | 63 | 64 | 65 | org.springframework.boot 66 | spring-boot-maven-plugin 67 | 68 | 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /section-14/barista-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | microbucks 7 | barista-service 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | barista-service 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.7.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Dalston.SR4 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-actuator 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-starter-stream-rabbit 36 | 37 | 38 | 39 | org.projectlombok 40 | lombok 41 | true 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-starter-test 46 | test 47 | 48 | 49 | 50 | 51 | 52 | 53 | org.springframework.cloud 54 | spring-cloud-dependencies 55 | ${spring-cloud.version} 56 | pom 57 | import 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | org.springframework.boot 66 | spring-boot-maven-plugin 67 | 68 | 69 | 70 | 71 | 72 | 73 | --------------------------------------------------------------------------------