├── Chapter02 ├── lib │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ ├── com │ │ └── packtpub │ │ │ └── mmj │ │ │ └── lib │ │ │ └── model │ │ │ └── Calculation.java │ │ └── module-info.java ├── pom.xml └── rest │ ├── pom.xml │ └── src │ └── main │ ├── java │ ├── com │ │ └── packtpub │ │ │ └── mmj │ │ │ └── rest │ │ │ ├── RestSampleApp.java │ │ │ └── resources │ │ │ └── CalculationController.java │ └── module-info.java │ └── resources │ └── application.yml ├── Chapter03 ├── nbactions.xml ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── packtpub │ └── mmj │ ├── domain │ └── RestaurantApp.java │ └── mcrsrvc │ ├── domain │ └── model │ │ ├── BaseEntity.java │ │ ├── BaseService.java │ │ ├── Entity.java │ │ ├── ReadOnlyBaseService.java │ │ ├── ReadOnlyRepository.java │ │ ├── Repository.java │ │ ├── Restaurant.java │ │ ├── RestaurantRepository.java │ │ ├── RestaurantService.java │ │ └── Table.java │ └── persistence │ └── InMemRestaurantRepository.java ├── Chapter04 ├── booking-service │ ├── nbactions.xml │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── packtpub │ │ │ │ └── mmj │ │ │ │ └── booking │ │ │ │ ├── BookingApp.java │ │ │ │ ├── domain │ │ │ │ ├── model │ │ │ │ │ └── entity │ │ │ │ │ │ ├── BaseEntity.java │ │ │ │ │ │ ├── Booking.java │ │ │ │ │ │ └── Entity.java │ │ │ │ ├── repository │ │ │ │ │ ├── BookingRepository.java │ │ │ │ │ ├── InMemBookingRepository.java │ │ │ │ │ ├── ReadOnlyRepository.java │ │ │ │ │ └── Repository.java │ │ │ │ ├── service │ │ │ │ │ ├── BaseService.java │ │ │ │ │ ├── BookingService.java │ │ │ │ │ ├── BookingServiceImpl.java │ │ │ │ │ └── ReadOnlyBaseService.java │ │ │ │ └── valueobject │ │ │ │ │ └── BookingVO.java │ │ │ │ └── resources │ │ │ │ └── BookingController.java │ │ └── resources │ │ │ └── application.yml │ │ └── test │ │ ├── java │ │ └── com │ │ │ └── packtpub │ │ │ └── mmj │ │ │ └── booking │ │ │ └── resources │ │ │ └── BookingControllerIntegrationTests.java │ │ └── resources │ │ └── application.yml ├── eureka-service │ ├── nbactions.xml │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── packtpub │ │ │ └── mmj │ │ │ └── eureka │ │ │ └── service │ │ │ └── App.java │ │ └── resources │ │ └── application.yml ├── nbactions.xml ├── pom.xml ├── restaurant-service │ ├── nbactions.xml │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── packtpub │ │ │ │ └── mmj │ │ │ │ └── restaurant │ │ │ │ ├── RestaurantApp.java │ │ │ │ ├── domain │ │ │ │ ├── model │ │ │ │ │ └── entity │ │ │ │ │ │ ├── BaseEntity.java │ │ │ │ │ │ ├── Entity.java │ │ │ │ │ │ ├── Restaurant.java │ │ │ │ │ │ └── Table.java │ │ │ │ ├── repository │ │ │ │ │ ├── InMemRestaurantRepository.java │ │ │ │ │ ├── ReadOnlyRepository.java │ │ │ │ │ ├── Repository.java │ │ │ │ │ └── RestaurantRepository.java │ │ │ │ ├── service │ │ │ │ │ ├── BaseService.java │ │ │ │ │ ├── ReadOnlyBaseService.java │ │ │ │ │ ├── RestaurantService.java │ │ │ │ │ └── RestaurantServiceImpl.java │ │ │ │ └── valueobject │ │ │ │ │ └── RestaurantVO.java │ │ │ │ └── resources │ │ │ │ └── RestaurantController.java │ │ └── resources │ │ │ ├── application.yml │ │ │ └── bootstrap.yml │ │ └── test │ │ ├── java │ │ └── com │ │ │ └── packtpub │ │ │ └── mmj │ │ │ └── restaurant │ │ │ └── resources │ │ │ ├── AbstractRestaurantControllerTests.java │ │ │ ├── RestaurantControllerIntegrationTests.java │ │ │ └── RestaurantControllerTests.java │ │ └── resources │ │ └── application.yml └── user-service │ ├── nbactions.xml │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── packtpub │ │ │ └── mmj │ │ │ └── user │ │ │ ├── UsersApp.java │ │ │ ├── domain │ │ │ ├── model │ │ │ │ └── entity │ │ │ │ │ ├── BaseEntity.java │ │ │ │ │ ├── Entity.java │ │ │ │ │ └── User.java │ │ │ ├── repository │ │ │ │ ├── InMemUserRepository.java │ │ │ │ ├── ReadOnlyRepository.java │ │ │ │ ├── Repository.java │ │ │ │ └── UserRepository.java │ │ │ ├── service │ │ │ │ ├── BaseService.java │ │ │ │ ├── ReadOnlyBaseService.java │ │ │ │ ├── UserService.java │ │ │ │ └── UserServiceImpl.java │ │ │ └── valueobject │ │ │ │ └── UserVO.java │ │ │ └── resources │ │ │ └── UserController.java │ └── resources │ │ └── application.yml │ └── test │ ├── java │ └── com │ │ └── packtpub │ │ └── mmj │ │ └── user │ │ └── resources │ │ └── UserControllerIntegrationTests.java │ └── resources │ └── application.yml ├── Chapter05 ├── api-service │ ├── nbactions.xml │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── packtpub │ │ │ └── mmj │ │ │ └── api │ │ │ └── service │ │ │ ├── ApiApp.java │ │ │ └── restaurant │ │ │ └── RestaurantServiceAPI.java │ │ └── resources │ │ └── application.yml ├── booking-service │ ├── nbactions.xml │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── packtpub │ │ │ │ └── mmj │ │ │ │ └── booking │ │ │ │ ├── BookingApp.java │ │ │ │ ├── domain │ │ │ │ ├── model │ │ │ │ │ └── entity │ │ │ │ │ │ ├── BaseEntity.java │ │ │ │ │ │ ├── Booking.java │ │ │ │ │ │ └── Entity.java │ │ │ │ ├── repository │ │ │ │ │ ├── BookingRepository.java │ │ │ │ │ ├── InMemBookingRepository.java │ │ │ │ │ ├── ReadOnlyRepository.java │ │ │ │ │ └── Repository.java │ │ │ │ ├── service │ │ │ │ │ ├── BaseService.java │ │ │ │ │ ├── BookingService.java │ │ │ │ │ ├── BookingServiceImpl.java │ │ │ │ │ └── ReadOnlyBaseService.java │ │ │ │ └── valueobject │ │ │ │ │ └── BookingVO.java │ │ │ │ └── resources │ │ │ │ └── BookingController.java │ │ └── resources │ │ │ └── application.yml │ │ └── test │ │ ├── java │ │ └── com │ │ │ └── packtpub │ │ │ └── mmj │ │ │ └── booking │ │ │ └── resources │ │ │ └── BookingControllerIntegrationTests.java │ │ └── resources │ │ └── application.yml ├── common │ ├── nbactions.xml │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── packtpub │ │ └── mmj │ │ └── common │ │ ├── MDCConcurrentCallable.java │ │ ├── MDCHystrixConcurrencyStrategy.java │ │ └── ServiceHelper.java ├── dashboard-server │ ├── nbactions.xml │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── packtpub │ │ │ └── mmj │ │ │ └── dashboard │ │ │ └── DashboardApp.java │ │ └── resources │ │ ├── application.yml │ │ └── hystrixdashboard │ │ └── stream │ │ └── hystrix.stream ├── docker-compose.yml ├── docker │ └── docker-assembly.xml ├── eureka-server │ ├── nbactions.xml │ ├── pom.xml │ └── src │ │ └── main │ │ ├── docker │ │ └── docker-assembly.xml │ │ ├── java │ │ └── com │ │ │ └── packtpub │ │ │ └── mmj │ │ │ └── eureka │ │ │ └── service │ │ │ └── App.java │ │ └── resources │ │ ├── application.yml │ │ └── docker-config.yml ├── nbactions.xml ├── pom.xml ├── restaurant-service │ ├── nbactions.xml │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── docker │ │ │ └── docker-assembly.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── packtpub │ │ │ │ └── mmj │ │ │ │ └── restaurant │ │ │ │ ├── RestaurantApp.java │ │ │ │ ├── domain │ │ │ │ ├── model │ │ │ │ │ └── entity │ │ │ │ │ │ ├── BaseEntity.java │ │ │ │ │ │ ├── Entity.java │ │ │ │ │ │ ├── Restaurant.java │ │ │ │ │ │ └── Table.java │ │ │ │ ├── repository │ │ │ │ │ ├── InMemRestaurantRepository.java │ │ │ │ │ ├── ReadOnlyRepository.java │ │ │ │ │ ├── Repository.java │ │ │ │ │ └── RestaurantRepository.java │ │ │ │ ├── service │ │ │ │ │ ├── BaseService.java │ │ │ │ │ ├── ReadOnlyBaseService.java │ │ │ │ │ ├── RestaurantService.java │ │ │ │ │ └── RestaurantServiceImpl.java │ │ │ │ └── valueobject │ │ │ │ │ └── RestaurantVO.java │ │ │ │ └── resources │ │ │ │ └── RestaurantController.java │ │ └── resources │ │ │ ├── application.yml │ │ │ └── docker-config.yml │ │ └── test │ │ ├── java │ │ └── com │ │ │ └── packtpub │ │ │ └── mmj │ │ │ └── restaurant │ │ │ └── resources │ │ │ ├── AbstractRestaurantControllerTests.java │ │ │ ├── RestaurantControllerIntegrationTests.java │ │ │ ├── RestaurantControllerTests.java │ │ │ └── docker │ │ │ ├── DockerIT.java │ │ │ └── RestaurantAppDockerIT.java │ │ └── resources │ │ └── application.yml ├── security-service │ ├── nbactions.xml │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── packtpub │ │ │ └── mmj │ │ │ └── security │ │ │ └── service │ │ │ └── SecurityApp.java │ │ ├── resources │ │ ├── application.yml │ │ ├── keystore.jks │ │ └── templates │ │ │ ├── authorize.ftl │ │ │ └── login.ftl │ │ └── wro │ │ ├── main.less │ │ ├── wro.properties │ │ └── wro.xml ├── turbine-server │ ├── nbactions.xml │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── packtpub │ │ │ └── mmj │ │ │ └── turbine │ │ │ └── server │ │ │ └── TurbineApp.java │ │ └── resources │ │ └── applicaton.yml ├── user-service │ ├── nbactions.xml │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── docker │ │ │ └── docker-assembly.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── packtpub │ │ │ │ └── mmj │ │ │ │ └── user │ │ │ │ ├── UsersApp.java │ │ │ │ ├── domain │ │ │ │ ├── model │ │ │ │ │ └── entity │ │ │ │ │ │ ├── BaseEntity.java │ │ │ │ │ │ ├── Entity.java │ │ │ │ │ │ └── User.java │ │ │ │ ├── repository │ │ │ │ │ ├── InMemUserRepository.java │ │ │ │ │ ├── ReadOnlyRepository.java │ │ │ │ │ ├── Repository.java │ │ │ │ │ └── UserRepository.java │ │ │ │ ├── service │ │ │ │ │ ├── BaseService.java │ │ │ │ │ ├── ReadOnlyBaseService.java │ │ │ │ │ ├── UserService.java │ │ │ │ │ └── UserServiceImpl.java │ │ │ │ └── valueobject │ │ │ │ │ └── UserVO.java │ │ │ │ └── resources │ │ │ │ └── UserController.java │ │ └── resources │ │ │ ├── application.yml │ │ │ └── docker-config.yml │ │ └── test │ │ ├── java │ │ └── com │ │ │ └── packtpub │ │ │ └── mmj │ │ │ └── user │ │ │ └── resources │ │ │ ├── UserControllerIntegrationTests.java │ │ │ └── docker │ │ │ ├── DockerIntegrationTest.java │ │ │ └── UserAppDockerIT.java │ │ └── resources │ │ └── application.yml └── zuul-server │ ├── nbactions.xml │ ├── pom.xml │ └── src │ └── main │ ├── java │ └── com │ │ └── packtpub │ │ └── mmj │ │ └── zuul │ │ └── server │ │ └── EdgeApp.java │ └── resources │ ├── application.yml │ └── keystore.jks ├── Chapter06 ├── billing-service │ ├── nbactions.xml │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── packtpub │ │ │ │ └── mmj │ │ │ │ ├── billing │ │ │ │ ├── BillingApp.java │ │ │ │ └── domain │ │ │ │ │ ├── message │ │ │ │ │ ├── BillingMessageChannels.java │ │ │ │ │ └── EventListener.java │ │ │ │ │ ├── model │ │ │ │ │ └── entity │ │ │ │ │ │ ├── BaseEntity.java │ │ │ │ │ │ ├── Booking.java │ │ │ │ │ │ └── Entity.java │ │ │ │ │ ├── repository │ │ │ │ │ ├── BookingRepository.java │ │ │ │ │ ├── InMemBookingRepository.java │ │ │ │ │ ├── ReadOnlyRepository.java │ │ │ │ │ └── Repository.java │ │ │ │ │ ├── service │ │ │ │ │ ├── BaseService.java │ │ │ │ │ ├── BookingService.java │ │ │ │ │ ├── BookingServiceImpl.java │ │ │ │ │ └── ReadOnlyBaseService.java │ │ │ │ │ └── valueobject │ │ │ │ │ └── BookingVO.java │ │ │ │ └── booking │ │ │ │ └── domain │ │ │ │ └── valueobject │ │ │ │ └── avro │ │ │ │ └── BookingOrder.java │ │ └── resources │ │ │ ├── application.yml │ │ │ └── avro │ │ │ └── bookingOrder.avsc │ │ └── test │ │ └── resources │ │ └── application.yml ├── booking-service │ ├── nbactions.xml │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── packtpub │ │ │ │ └── mmj │ │ │ │ └── booking │ │ │ │ ├── BookingApp.java │ │ │ │ ├── domain │ │ │ │ ├── message │ │ │ │ │ └── BookingMessageChannels.java │ │ │ │ ├── model │ │ │ │ │ └── entity │ │ │ │ │ │ ├── BaseEntity.java │ │ │ │ │ │ ├── Booking.java │ │ │ │ │ │ └── Entity.java │ │ │ │ ├── repository │ │ │ │ │ ├── BookingRepository.java │ │ │ │ │ ├── InMemBookingRepository.java │ │ │ │ │ ├── ReadOnlyRepository.java │ │ │ │ │ └── Repository.java │ │ │ │ ├── service │ │ │ │ │ ├── BaseService.java │ │ │ │ │ ├── BookingService.java │ │ │ │ │ ├── BookingServiceImpl.java │ │ │ │ │ └── ReadOnlyBaseService.java │ │ │ │ └── valueobject │ │ │ │ │ ├── BookingVO.java │ │ │ │ │ └── avro │ │ │ │ │ └── BookingOrder.java │ │ │ │ └── resources │ │ │ │ └── BookingController.java │ │ └── resources │ │ │ ├── application.yml │ │ │ └── avro │ │ │ └── bookingOrder.avsc │ │ └── test │ │ ├── java │ │ └── com │ │ │ └── packtpub │ │ │ └── mmj │ │ │ └── booking │ │ │ └── resources │ │ │ └── BookingControllerIntegrationTests.java │ │ └── resources │ │ └── application.yml ├── nbactions.xml └── pom.xml ├── Chapter07 ├── api-service │ ├── nbactions.xml │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── packtpub │ │ │ └── mmj │ │ │ └── api │ │ │ └── service │ │ │ ├── ApiApp.java │ │ │ └── restaurant │ │ │ └── RestaurantServiceAPI.java │ │ └── resources │ │ └── application.yml ├── booking-service │ ├── nbactions.xml │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── packtpub │ │ │ │ └── mmj │ │ │ │ └── booking │ │ │ │ ├── BookingApp.java │ │ │ │ ├── domain │ │ │ │ ├── model │ │ │ │ │ └── entity │ │ │ │ │ │ ├── BaseEntity.java │ │ │ │ │ │ ├── Booking.java │ │ │ │ │ │ └── Entity.java │ │ │ │ ├── repository │ │ │ │ │ ├── BookingRepository.java │ │ │ │ │ ├── InMemBookingRepository.java │ │ │ │ │ ├── ReadOnlyRepository.java │ │ │ │ │ └── Repository.java │ │ │ │ ├── service │ │ │ │ │ ├── BaseService.java │ │ │ │ │ ├── BookingService.java │ │ │ │ │ ├── BookingServiceImpl.java │ │ │ │ │ └── ReadOnlyBaseService.java │ │ │ │ └── valueobject │ │ │ │ │ └── BookingVO.java │ │ │ │ └── resources │ │ │ │ └── BookingController.java │ │ └── resources │ │ │ └── application.yml │ │ └── test │ │ ├── java │ │ └── com │ │ │ └── packtpub │ │ │ └── mmj │ │ │ └── booking │ │ │ └── resources │ │ │ └── BookingControllerIntegrationTests.java │ │ └── resources │ │ └── application.yml ├── common │ ├── nbactions.xml │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── packtpub │ │ └── mmj │ │ └── common │ │ ├── MDCConcurrentCallable.java │ │ ├── MDCHystrixConcurrencyStrategy.java │ │ └── ServiceHelper.java ├── dashboard-server │ ├── nbactions.xml │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── packtpub │ │ │ └── mmj │ │ │ └── dashboard │ │ │ └── DashboardApp.java │ │ └── resources │ │ ├── application.yml │ │ └── hystrixdashboard │ │ └── stream │ │ └── hystrix.stream ├── docker-compose.yml ├── docker │ └── docker-assembly.xml ├── eureka-server │ ├── nbactions.xml │ ├── pom.xml │ └── src │ │ └── main │ │ ├── docker │ │ └── docker-assembly.xml │ │ ├── java │ │ └── com │ │ │ └── packtpub │ │ │ └── mmj │ │ │ └── eureka │ │ │ └── service │ │ │ └── App.java │ │ └── resources │ │ ├── application.yml │ │ └── docker-config.yml ├── nb-configuration.xml ├── nbactions.xml ├── pom.xml ├── restaurant-service │ ├── nbactions.xml │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── docker │ │ │ └── docker-assembly.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── packtpub │ │ │ │ └── mmj │ │ │ │ └── restaurant │ │ │ │ ├── RestaurantApp.java │ │ │ │ ├── domain │ │ │ │ ├── model │ │ │ │ │ └── entity │ │ │ │ │ │ ├── BaseEntity.java │ │ │ │ │ │ ├── Entity.java │ │ │ │ │ │ ├── Restaurant.java │ │ │ │ │ │ └── Table.java │ │ │ │ ├── repository │ │ │ │ │ ├── InMemRestaurantRepository.java │ │ │ │ │ ├── ReadOnlyRepository.java │ │ │ │ │ ├── Repository.java │ │ │ │ │ └── RestaurantRepository.java │ │ │ │ ├── service │ │ │ │ │ ├── BaseService.java │ │ │ │ │ ├── ReadOnlyBaseService.java │ │ │ │ │ ├── RestaurantService.java │ │ │ │ │ └── RestaurantServiceImpl.java │ │ │ │ └── valueobject │ │ │ │ │ └── RestaurantVO.java │ │ │ │ └── resources │ │ │ │ └── RestaurantController.java │ │ └── resources │ │ │ ├── application.yml │ │ │ └── docker-config.yml │ │ └── test │ │ ├── java │ │ └── com │ │ │ └── packtpub │ │ │ └── mmj │ │ │ └── restaurant │ │ │ └── resources │ │ │ ├── AbstractRestaurantControllerTests.java │ │ │ ├── RestaurantControllerIntegrationTests.java │ │ │ ├── RestaurantControllerTests.java │ │ │ └── docker │ │ │ ├── DockerIT.java │ │ │ └── RestaurantAppDockerIT.java │ │ └── resources │ │ └── application.yml ├── security-service │ ├── nb-configuration.xml │ ├── nbactions.xml │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── packtpub │ │ │ └── mmj │ │ │ └── security │ │ │ └── service │ │ │ └── SecurityApp.java │ │ ├── resources │ │ ├── application.yml │ │ └── keystore.jks │ │ └── wro │ │ ├── main.less │ │ ├── wro.properties │ │ └── wro.xml ├── turbine-server │ ├── nbactions.xml │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── packtpub │ │ │ └── mmj │ │ │ └── turbine │ │ │ └── server │ │ │ └── TurbineApp.java │ │ └── resources │ │ └── applicaton.yml ├── user-service │ ├── nbactions.xml │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── docker │ │ │ └── docker-assembly.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── packtpub │ │ │ │ └── mmj │ │ │ │ └── user │ │ │ │ ├── UsersApp.java │ │ │ │ ├── domain │ │ │ │ ├── model │ │ │ │ │ └── entity │ │ │ │ │ │ ├── BaseEntity.java │ │ │ │ │ │ ├── Entity.java │ │ │ │ │ │ └── User.java │ │ │ │ ├── repository │ │ │ │ │ ├── InMemUserRepository.java │ │ │ │ │ ├── ReadOnlyRepository.java │ │ │ │ │ ├── Repository.java │ │ │ │ │ └── UserRepository.java │ │ │ │ ├── service │ │ │ │ │ ├── BaseService.java │ │ │ │ │ ├── ReadOnlyBaseService.java │ │ │ │ │ ├── UserService.java │ │ │ │ │ └── UserServiceImpl.java │ │ │ │ └── valueobject │ │ │ │ │ └── UserVO.java │ │ │ │ └── resources │ │ │ │ └── UserController.java │ │ └── resources │ │ │ ├── application.yml │ │ │ └── docker-config.yml │ │ └── test │ │ ├── java │ │ └── com │ │ │ └── packtpub │ │ │ └── mmj │ │ │ └── user │ │ │ └── resources │ │ │ ├── UserControllerIntegrationTests.java │ │ │ └── docker │ │ │ ├── DockerIntegrationTest.java │ │ │ └── UserAppDockerIT.java │ │ └── resources │ │ └── application.yml └── zuul-server │ ├── nbactions.xml │ ├── pom.xml │ └── src │ └── main │ ├── java │ └── com │ │ └── packtpub │ │ └── mmj │ │ └── zuul │ │ └── server │ │ └── EdgeApp.java │ └── resources │ ├── application.yml │ └── keystore.jks ├── Chapter08 └── OTRS_UI │ ├── LICENSE │ ├── README.md │ ├── app │ ├── components │ │ └── version │ │ │ ├── interpolate-filter.js │ │ │ ├── interpolate-filter_test.js │ │ │ ├── version-directive.js │ │ │ ├── version-directive_test.js │ │ │ ├── version.js │ │ │ └── version_test.js │ └── src │ │ ├── index.html │ │ ├── scripts │ │ ├── AjaxHandler.js │ │ └── app.js │ │ ├── styles │ │ └── application.scss │ │ └── views │ │ ├── httperror │ │ ├── httperror.html │ │ └── httperror.js │ │ ├── login │ │ ├── login.html │ │ └── login.js │ │ └── restaurants │ │ ├── restaurant.html │ │ ├── restaurants.html │ │ └── restaurants.js │ ├── bower.json │ ├── e2e-tests │ ├── protractor.conf.js │ └── scenarios.js │ ├── gulpfile.coffee │ ├── gulpfile.js │ ├── karma.conf.js │ ├── nbproject │ ├── private │ │ ├── private.properties │ │ └── private.xml │ ├── project.properties │ └── project.xml │ └── package.json ├── LICENSE ├── README.md └── Software_Hardware_list.pdf /Chapter02/lib/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | com.packtpub.mmj 6 | 6392_chapter2 7 | 1.0-SNAPSHOT 8 | 9 | lib 10 | -------------------------------------------------------------------------------- /Chapter02/lib/src/main/java/com/packtpub/mmj/lib/model/Calculation.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.lib.model; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * 7 | * @author sousharm 8 | */ 9 | public class Calculation { 10 | 11 | String function; 12 | private List input; 13 | private List output; 14 | 15 | /** 16 | * 17 | * @param input 18 | * @param output 19 | * @param function 20 | */ 21 | public Calculation(List input, List output, String function) { 22 | this.function = function; 23 | this.input = input; 24 | this.output = output; 25 | } 26 | 27 | /** 28 | * 29 | * @return 30 | */ 31 | public List getInput() { 32 | return input; 33 | } 34 | 35 | /** 36 | * 37 | * @param input 38 | */ 39 | public void setInput(List input) { 40 | this.input = input; 41 | } 42 | 43 | /** 44 | * 45 | * @return 46 | */ 47 | public List getOutput() { 48 | return output; 49 | } 50 | 51 | /** 52 | * 53 | * @param output 54 | */ 55 | public void setOutput(List output) { 56 | this.output = output; 57 | } 58 | 59 | /** 60 | * 61 | * @return 62 | */ 63 | public String getFunction() { 64 | return function; 65 | } 66 | 67 | /** 68 | * 69 | * @param function 70 | */ 71 | public void setFunction(String function) { 72 | this.function = function; 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /Chapter02/lib/src/main/java/module-info.java: -------------------------------------------------------------------------------- 1 | 2 | module com.packtpub.mmj.lib { 3 | 4 | exports com.packtpub.mmj.lib.model to com.packtpub.mmj.rest; 5 | 6 | opens com.packtpub.mmj.lib.model; 7 | } 8 | -------------------------------------------------------------------------------- /Chapter02/rest/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | com.packtpub.mmj 6 | 6392_chapter2 7 | 1.0-SNAPSHOT 8 | 9 | rest 10 | 11 | 12 | 13 | com.packtpub.mmj 14 | lib 15 | 16 | 17 | org.springframework.boot 18 | spring-boot-starter-web 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-tomcat 23 | 24 | 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-jetty 29 | 30 | 31 | -------------------------------------------------------------------------------- /Chapter02/rest/src/main/java/com/packtpub/mmj/rest/RestSampleApp.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.rest; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * 8 | * @author sousharm 9 | */ 10 | @SpringBootApplication 11 | public class RestSampleApp { 12 | 13 | /** 14 | * 15 | * @param args 16 | */ 17 | public static void main(String[] args) { 18 | SpringApplication.run(RestSampleApp.class, args); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Chapter02/rest/src/main/java/module-info.java: -------------------------------------------------------------------------------- 1 | 2 | module com.packtpub.mmj.rest { 3 | 4 | requires spring.core; 5 | requires spring.beans; 6 | requires spring.context; 7 | requires spring.aop; 8 | requires spring.web; 9 | requires spring.expression; 10 | 11 | requires spring.boot; 12 | requires spring.boot.autoconfigure; 13 | 14 | requires com.packtpub.mmj.lib; 15 | 16 | exports com.packtpub.mmj.rest; 17 | exports com.packtpub.mmj.rest.resources; 18 | 19 | opens com.packtpub.mmj.rest; 20 | opens com.packtpub.mmj.rest.resources; 21 | } 22 | -------------------------------------------------------------------------------- /Chapter02/rest/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | ## YAML Template. 2 | 3 | server: 4 | port: 8000 5 | --- 6 | -------------------------------------------------------------------------------- /Chapter03/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | com.packtpub.mmj 5 | 6392_chapter3 6 | 1.0-SNAPSHOT 7 | 8 | com.packtpub.mmj.domain.RestaurantApp 9 | UTF-8 10 | 9 11 | 9 12 | com.packtpub.mmj.domain.RestaurantApp 13 | 14 | 6392_chapter3 15 | Master Microservices with Java, Chapter - 3 Domain Driven Design 16 | -------------------------------------------------------------------------------- /Chapter03/src/main/java/com/packtpub/mmj/mcrsrvc/domain/model/BaseEntity.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.mcrsrvc.domain.model; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | * @param 7 | */ 8 | public abstract class BaseEntity extends Entity { 9 | 10 | private final boolean isModified; 11 | 12 | /** 13 | * 14 | * @param id 15 | * @param name 16 | */ 17 | public BaseEntity(T id, String name) { 18 | super.id = id; 19 | super.name = name; 20 | isModified = false; 21 | } 22 | 23 | /** 24 | * 25 | * @return 26 | */ 27 | public boolean isIsModified() { 28 | return isModified; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Chapter03/src/main/java/com/packtpub/mmj/mcrsrvc/domain/model/BaseService.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.mcrsrvc.domain.model; 2 | 3 | import java.util.Collection; 4 | 5 | /** 6 | * 7 | * @author Sourabh Sharma 8 | * @param 9 | * @param 10 | */ 11 | public abstract class BaseService extends ReadOnlyBaseService { 12 | 13 | private final Repository _repository; 14 | 15 | BaseService(Repository repository) { 16 | super(repository); 17 | _repository = repository; 18 | } 19 | 20 | /** 21 | * 22 | * @param entity 23 | * @throws Exception 24 | */ 25 | public void add(TE entity) throws Exception { 26 | _repository.add(entity); 27 | } 28 | 29 | /** 30 | * 31 | * @return 32 | */ 33 | public Collection getAll() { 34 | return _repository.getAll(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Chapter03/src/main/java/com/packtpub/mmj/mcrsrvc/domain/model/Entity.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.mcrsrvc.domain.model; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | * @param 7 | */ 8 | public abstract class Entity { 9 | 10 | T id; 11 | String name; 12 | 13 | /** 14 | * 15 | * @return 16 | */ 17 | public T getId() { 18 | return id; 19 | } 20 | 21 | /** 22 | * 23 | * @param id 24 | */ 25 | public void setId(T id) { 26 | this.id = id; 27 | } 28 | 29 | /** 30 | * 31 | * @return 32 | */ 33 | public String getName() { 34 | return name; 35 | } 36 | 37 | /** 38 | * 39 | * @param name 40 | */ 41 | public void setName(String name) { 42 | this.name = name; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /Chapter03/src/main/java/com/packtpub/mmj/mcrsrvc/domain/model/ReadOnlyBaseService.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.mcrsrvc.domain.model; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | * @param 7 | * @param 8 | */ 9 | public abstract class ReadOnlyBaseService { 10 | 11 | private final ReadOnlyRepository repository; 12 | 13 | ReadOnlyBaseService(ReadOnlyRepository repository) { 14 | this.repository = repository; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Chapter03/src/main/java/com/packtpub/mmj/mcrsrvc/domain/model/ReadOnlyRepository.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.mcrsrvc.domain.model; 2 | 3 | import java.util.Collection; 4 | 5 | /** 6 | * 7 | * @author Sourabh Sharma 8 | * @param 9 | * @param 10 | */ 11 | public interface ReadOnlyRepository { 12 | 13 | //long Count; 14 | /** 15 | * 16 | * @param id 17 | * @return 18 | */ 19 | boolean contains(T id); 20 | 21 | /** 22 | * 23 | * @param id 24 | * @return 25 | */ 26 | TE get(T id); 27 | 28 | /** 29 | * 30 | * @return 31 | */ 32 | Collection getAll(); 33 | } 34 | -------------------------------------------------------------------------------- /Chapter03/src/main/java/com/packtpub/mmj/mcrsrvc/domain/model/Repository.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.mcrsrvc.domain.model; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | * @param 7 | * @param 8 | */ 9 | public interface Repository extends ReadOnlyRepository { 10 | 11 | /** 12 | * 13 | * @param entity 14 | */ 15 | void add(TE entity); 16 | 17 | /** 18 | * 19 | * @param id 20 | */ 21 | void remove(T id); 22 | 23 | /** 24 | * 25 | * @param entity 26 | */ 27 | void update(TE entity); 28 | } 29 | -------------------------------------------------------------------------------- /Chapter03/src/main/java/com/packtpub/mmj/mcrsrvc/domain/model/Restaurant.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.mcrsrvc.domain.model; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | * 8 | * @author Sourabh Sharma 9 | */ 10 | public class Restaurant extends BaseEntity { 11 | 12 | private List tables = new ArrayList<>(); 13 | 14 | /** 15 | * 16 | * @param name 17 | * @param id 18 | * @param tables 19 | */ 20 | public Restaurant(String name, String id, List
tables) { 21 | super(id, name); 22 | this.tables = tables; 23 | } 24 | 25 | /** 26 | * 27 | * @param tables 28 | */ 29 | public void setTables(List
tables) { 30 | this.tables = tables; 31 | } 32 | 33 | /** 34 | * 35 | * @return 36 | */ 37 | public List
getTables() { 38 | return tables; 39 | } 40 | 41 | /** 42 | * Overridden toString() method that return String presentation of the 43 | * Object 44 | * 45 | * @return 46 | */ 47 | @Override 48 | public String toString() { 49 | return new StringBuilder("{id: ").append(id).append(", name: ") 50 | .append(name).append(", tables: ").append(tables).append("}").toString(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Chapter03/src/main/java/com/packtpub/mmj/mcrsrvc/domain/model/RestaurantRepository.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.mcrsrvc.domain.model; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | * @param 7 | * @param 8 | */ 9 | public interface RestaurantRepository extends Repository { 10 | 11 | /** 12 | * 13 | * @param name 14 | * @return 15 | */ 16 | boolean containsName(String name); 17 | } 18 | -------------------------------------------------------------------------------- /Chapter03/src/main/java/com/packtpub/mmj/mcrsrvc/domain/model/RestaurantService.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.mcrsrvc.domain.model; 2 | 3 | import java.math.BigInteger; 4 | import java.util.Collection; 5 | 6 | /** 7 | * 8 | * @author Sourabh Sharma 9 | */ 10 | public class RestaurantService extends BaseService { 11 | 12 | private final RestaurantRepository restaurantRepository; 13 | 14 | /** 15 | * 16 | * @param repository 17 | */ 18 | public RestaurantService(RestaurantRepository repository) { 19 | super(repository); 20 | restaurantRepository = repository; 21 | } 22 | 23 | /** 24 | * 25 | * @param restaurant 26 | * @throws Exception 27 | */ 28 | @Override 29 | public void add(Restaurant restaurant) throws Exception { 30 | if (restaurantRepository.containsName(restaurant.getName())) { 31 | throw new Exception(String.format("There is already a product with the name - %s", restaurant.getName())); 32 | } 33 | 34 | if (restaurant.getName() == null || "".equals(restaurant.getName())) { 35 | throw new Exception("Restaurant name cannot be null or empty string."); 36 | } 37 | super.add(restaurant); 38 | } 39 | 40 | /** 41 | * 42 | * @return 43 | */ 44 | @Override 45 | public Collection getAll() { 46 | return super.getAll(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Chapter03/src/main/java/com/packtpub/mmj/mcrsrvc/domain/model/Table.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.mcrsrvc.domain.model; 2 | 3 | import java.math.BigInteger; 4 | 5 | /** 6 | * 7 | * @author Sourabh Sharma 8 | */ 9 | public class Table extends BaseEntity { 10 | 11 | private int capacity; 12 | 13 | /** 14 | * 15 | * @param name 16 | * @param id 17 | * @param capacity 18 | */ 19 | public Table(String name, BigInteger id, int capacity) { 20 | super(id, name); 21 | this.capacity = capacity; 22 | } 23 | 24 | /** 25 | * 26 | * @param capacity 27 | */ 28 | public void setCapacity(int capacity) { 29 | this.capacity = capacity; 30 | } 31 | 32 | /** 33 | * 34 | * @return 35 | */ 36 | public int getCapacity() { 37 | return capacity; 38 | } 39 | 40 | /** 41 | * Overridden toString() method that return String presentation of the 42 | * Object 43 | * 44 | * @return 45 | */ 46 | @Override 47 | public String toString() { 48 | return new StringBuilder("{id: ").append(id).append(", name: ") 49 | .append(name).append(", capacity: ").append(capacity).append("}").toString(); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /Chapter04/booking-service/nbactions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CUSTOM-clean and package 5 | clean and package 6 | 7 | clean 8 | package 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Chapter04/booking-service/src/main/java/com/packtpub/mmj/booking/BookingApp.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.booking; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | 7 | /** 8 | * 9 | * @author Sourabh Sharma 10 | */ 11 | @SpringBootApplication 12 | @EnableEurekaClient 13 | public class BookingApp { 14 | 15 | /** 16 | * 17 | * @param args 18 | */ 19 | public static void main(String[] args) { 20 | SpringApplication.run(BookingApp.class, args); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /Chapter04/booking-service/src/main/java/com/packtpub/mmj/booking/domain/model/entity/BaseEntity.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.booking.domain.model.entity; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | * @param 7 | */ 8 | public abstract class BaseEntity extends Entity { 9 | 10 | private boolean isModified; 11 | 12 | /** 13 | * 14 | * @param id 15 | * @param name 16 | */ 17 | public BaseEntity(T id, String name) { 18 | super.id = id; 19 | super.name = name; 20 | isModified = false; 21 | } 22 | 23 | /** 24 | * 25 | * @return 26 | */ 27 | public boolean isIsModified() { 28 | return isModified; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Chapter04/booking-service/src/main/java/com/packtpub/mmj/booking/domain/model/entity/Entity.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.booking.domain.model.entity; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | * @param 7 | */ 8 | public abstract class Entity { 9 | 10 | T id; 11 | String name; 12 | 13 | /** 14 | * 15 | * @return 16 | */ 17 | public T getId() { 18 | return id; 19 | } 20 | 21 | /** 22 | * 23 | * @param id 24 | */ 25 | public void setId(T id) { 26 | this.id = id; 27 | } 28 | 29 | /** 30 | * 31 | * @return 32 | */ 33 | public String getName() { 34 | return name; 35 | } 36 | 37 | /** 38 | * 39 | * @param name 40 | */ 41 | public void setName(String name) { 42 | this.name = name; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /Chapter04/booking-service/src/main/java/com/packtpub/mmj/booking/domain/repository/BookingRepository.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.booking.domain.repository; 2 | 3 | import java.util.Collection; 4 | 5 | /** 6 | * 7 | * @author Sourabh Sharma 8 | * @param 9 | * @param 10 | */ 11 | public interface BookingRepository extends Repository { 12 | 13 | /** 14 | * 15 | * @param name 16 | * @return 17 | */ 18 | boolean containsName(String name); 19 | 20 | /** 21 | * 22 | * @param name 23 | * @return 24 | * @throws Exception 25 | */ 26 | public Collection findByName(String name) throws Exception; 27 | } 28 | -------------------------------------------------------------------------------- /Chapter04/booking-service/src/main/java/com/packtpub/mmj/booking/domain/repository/ReadOnlyRepository.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.booking.domain.repository; 2 | 3 | import java.util.Collection; 4 | 5 | /** 6 | * 7 | * @author Sourabh Sharma 8 | * @param 9 | * @param 10 | */ 11 | public interface ReadOnlyRepository { 12 | 13 | //long Count; 14 | /** 15 | * 16 | * @param id 17 | * @return 18 | */ 19 | boolean contains(T id); 20 | 21 | /** 22 | * 23 | * @param id 24 | * @return 25 | */ 26 | TE get(T id); 27 | 28 | /** 29 | * 30 | * @return 31 | */ 32 | Collection getAll(); 33 | } 34 | -------------------------------------------------------------------------------- /Chapter04/booking-service/src/main/java/com/packtpub/mmj/booking/domain/repository/Repository.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.booking.domain.repository; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | * @param 7 | * @param 8 | */ 9 | public interface Repository extends ReadOnlyRepository { 10 | 11 | /** 12 | * 13 | * @param entity 14 | */ 15 | void add(TE entity); 16 | 17 | /** 18 | * 19 | * @param id 20 | */ 21 | void remove(T id); 22 | 23 | /** 24 | * 25 | * @param entity 26 | */ 27 | void update(TE entity); 28 | } 29 | -------------------------------------------------------------------------------- /Chapter04/booking-service/src/main/java/com/packtpub/mmj/booking/domain/service/BaseService.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.booking.domain.service; 2 | 3 | import com.packtpub.mmj.booking.domain.repository.Repository; 4 | import java.util.Collection; 5 | 6 | /** 7 | * 8 | * @author Sourabh Sharma 9 | * @param 10 | * @param 11 | */ 12 | public abstract class BaseService extends ReadOnlyBaseService { 13 | 14 | private Repository _repository; 15 | 16 | BaseService(Repository repository) { 17 | super(repository); 18 | _repository = repository; 19 | } 20 | 21 | /** 22 | * 23 | * @param entity 24 | * @throws Exception 25 | */ 26 | public void add(TE entity) throws Exception { 27 | _repository.add(entity); 28 | } 29 | 30 | /** 31 | * 32 | * @return 33 | */ 34 | public Collection getAll() { 35 | return _repository.getAll(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Chapter04/booking-service/src/main/java/com/packtpub/mmj/booking/domain/service/BookingService.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.booking.domain.service; 2 | 3 | import com.packtpub.mmj.booking.domain.model.entity.Booking; 4 | import com.packtpub.mmj.booking.domain.model.entity.Entity; 5 | import java.util.ArrayList; 6 | import java.util.Collection; 7 | import java.util.Map; 8 | 9 | /** 10 | * 11 | * @author Sourabh Sharma 12 | */ 13 | public interface BookingService { 14 | 15 | /** 16 | * 17 | * @param booking 18 | * @throws Exception 19 | */ 20 | public void add(Booking booking) throws Exception; 21 | 22 | /** 23 | * 24 | * @param booking 25 | * @throws Exception 26 | */ 27 | public void update(Booking booking) throws Exception; 28 | 29 | /** 30 | * 31 | * @param id 32 | * @throws Exception 33 | */ 34 | public void delete(String id) throws Exception; 35 | 36 | /** 37 | * 38 | * @param id 39 | * @return 40 | * @throws Exception 41 | */ 42 | public Entity findById(String id) throws Exception; 43 | 44 | /** 45 | * 46 | * @param name 47 | * @return 48 | * @throws Exception 49 | */ 50 | public Collection findByName(String name) throws Exception; 51 | 52 | /** 53 | * 54 | * @param name 55 | * @return 56 | * @throws Exception 57 | */ 58 | public Collection findByCriteria(Map> name) throws Exception; 59 | } 60 | -------------------------------------------------------------------------------- /Chapter04/booking-service/src/main/java/com/packtpub/mmj/booking/domain/service/ReadOnlyBaseService.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.booking.domain.service; 2 | 3 | import com.packtpub.mmj.booking.domain.repository.ReadOnlyRepository; 4 | 5 | /** 6 | * 7 | * @author Sourabh Sharma 8 | * @param 9 | * @param 10 | */ 11 | public abstract class ReadOnlyBaseService { 12 | 13 | private ReadOnlyRepository repository; 14 | 15 | ReadOnlyBaseService(ReadOnlyRepository repository) { 16 | this.repository = repository; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter04/booking-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | # Spring properties 2 | spring: 3 | application: 4 | name: booking-service # Service registers under this name 5 | freemarker: 6 | enabled: false # Ignore Eureka dashboard FreeMarker templates 7 | thymeleaf: 8 | cache: false # Allow Thymeleaf templates to be reloaded at runtime 9 | 10 | # Map the error path to error template (for Thymeleaf) 11 | error: 12 | path=/error 13 | 14 | # Discovery Server Access 15 | eureka: 16 | client: 17 | serviceUrl: 18 | defaultZone: http://localhost:8761/eureka/ 19 | 20 | # HTTP Server 21 | server: 22 | port: 2223 # HTTP (Tomcat) port 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Chapter04/booking-service/src/test/resources/application.yml: -------------------------------------------------------------------------------- 1 | # Spring properties 2 | spring: 3 | cloud: 4 | discovery: 5 | enabled: false 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Chapter04/eureka-service/nbactions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CUSTOM-clean and package 5 | clean and package 6 | 7 | clean 8 | package 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Chapter04/eureka-service/src/main/java/com/packtpub/mmj/eureka/service/App.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.eureka.service; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | /** 8 | * 9 | * @author Sourabh Sharma 10 | */ 11 | @SpringBootApplication 12 | @EnableEurekaServer 13 | public class App { 14 | 15 | /** 16 | * 17 | * @param args 18 | */ 19 | public static void main(String[] args) { 20 | SpringApplication.run(App.class, args); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Chapter04/eureka-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | # Yureka Server Configuration 2 | server: 3 | port: ${vcap.application.port:8761} # HTTP port 4 | 5 | eureka: 6 | instance: 7 | hostname: localhost 8 | client: 9 | registerWithEureka: false 10 | fetchRegistry: false 11 | serviceUrl: 12 | defaultZone: ${vcap.services.${PREFIX:}eureka.credentials.uri:http://user:password@localhost:8761}/eureka/ 13 | server: 14 | waitTimeInMsWhenSyncEmpty: 0 15 | enableSelfPreservation: false 16 | 17 | # Discovery Server Dashboard uses FreeMarker. Don't want Thymeleaf templates 18 | spring: 19 | thymeleaf: 20 | enabled: false # Disable Thymeleaf -------------------------------------------------------------------------------- /Chapter04/nbactions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CUSTOM-clean and package 5 | clean and package 6 | 7 | clean 8 | package 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Chapter04/restaurant-service/nbactions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CUSTOM-clean and package 5 | clean and package 6 | 7 | clean 8 | package 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Chapter04/restaurant-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | com.packtpub.mmj 6 | 6392_chapter4 7 | PACKT-SNAPSHOT 8 | 9 | 10 | online-table-reservation:restaurant-service 11 | restaurant-service 12 | jar 13 | 14 | com.packtpub.mmj.restaurant.RestaurantApp 15 | 16 | 17 | 18 | 19 | org.springframework.cloud 20 | spring-cloud-starter-config 21 | 22 | 23 | org.springframework.cloud 24 | spring-cloud-starter-eureka 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-test 30 | 31 | 32 | -------------------------------------------------------------------------------- /Chapter04/restaurant-service/src/main/java/com/packtpub/mmj/restaurant/RestaurantApp.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.restaurant; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | 7 | /** 8 | * 9 | * @author Sourabh Sharma 10 | */ 11 | @SpringBootApplication 12 | @EnableEurekaClient 13 | public class RestaurantApp { 14 | 15 | /** 16 | * 17 | * @param args 18 | */ 19 | public static void main(String[] args) { 20 | SpringApplication.run(RestaurantApp.class, args); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Chapter04/restaurant-service/src/main/java/com/packtpub/mmj/restaurant/domain/model/entity/BaseEntity.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.restaurant.domain.model.entity; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | * @param 7 | */ 8 | public abstract class BaseEntity extends Entity { 9 | 10 | private boolean isModified; 11 | 12 | /** 13 | * 14 | * @param id 15 | * @param name 16 | */ 17 | public BaseEntity(T id, String name) { 18 | super.id = id; 19 | super.name = name; 20 | isModified = false; 21 | } 22 | 23 | /** 24 | * 25 | * @return 26 | */ 27 | public boolean isIsModified() { 28 | return isModified; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Chapter04/restaurant-service/src/main/java/com/packtpub/mmj/restaurant/domain/model/entity/Entity.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.restaurant.domain.model.entity; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | * @param 7 | */ 8 | public abstract class Entity { 9 | 10 | T id; 11 | String name; 12 | 13 | /** 14 | * 15 | * @return 16 | */ 17 | public T getId() { 18 | return id; 19 | } 20 | 21 | /** 22 | * 23 | * @param id 24 | */ 25 | public void setId(T id) { 26 | this.id = id; 27 | } 28 | 29 | /** 30 | * 31 | * @return 32 | */ 33 | public String getName() { 34 | return name; 35 | } 36 | 37 | /** 38 | * 39 | * @param name 40 | */ 41 | public void setName(String name) { 42 | this.name = name; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /Chapter04/restaurant-service/src/main/java/com/packtpub/mmj/restaurant/domain/model/entity/Table.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.restaurant.domain.model.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import java.math.BigInteger; 5 | 6 | /** 7 | * 8 | * @author Sourabh Sharma 9 | */ 10 | public class Table extends BaseEntity { 11 | 12 | private int capacity; 13 | 14 | /** 15 | * 16 | * @param name 17 | * @param id 18 | * @param capacity 19 | */ 20 | public Table(@JsonProperty("name") String name, @JsonProperty("id") BigInteger id, @JsonProperty("capacity") int capacity) { 21 | super(id, name); 22 | this.capacity = capacity; 23 | } 24 | 25 | /** 26 | * 27 | * @param capacity 28 | */ 29 | public void setCapacity(int capacity) { 30 | this.capacity = capacity; 31 | } 32 | 33 | /** 34 | * 35 | * @return 36 | */ 37 | public int getCapacity() { 38 | return capacity; 39 | } 40 | 41 | /** 42 | * Overridden toString() method that return String presentation of the 43 | * Object 44 | * 45 | * @return 46 | */ 47 | @Override 48 | public String toString() { 49 | return String.format("{id: %s, name: %s, capacity: %s}", 50 | this.getId(), this.getName(), this.getCapacity()); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /Chapter04/restaurant-service/src/main/java/com/packtpub/mmj/restaurant/domain/repository/ReadOnlyRepository.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.restaurant.domain.repository; 2 | 3 | import java.util.Collection; 4 | 5 | /** 6 | * 7 | * @author Sourabh Sharma 8 | * @param 9 | * @param 10 | */ 11 | public interface ReadOnlyRepository { 12 | 13 | //long Count; 14 | /** 15 | * 16 | * @param id 17 | * @return 18 | */ 19 | boolean contains(T id); 20 | 21 | /** 22 | * 23 | * @param id 24 | * @return 25 | */ 26 | TE get(T id); 27 | 28 | /** 29 | * 30 | * @return 31 | */ 32 | Collection getAll(); 33 | } 34 | -------------------------------------------------------------------------------- /Chapter04/restaurant-service/src/main/java/com/packtpub/mmj/restaurant/domain/repository/Repository.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.restaurant.domain.repository; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | * @param 7 | * @param 8 | */ 9 | public interface Repository extends ReadOnlyRepository { 10 | 11 | /** 12 | * 13 | * @param entity 14 | */ 15 | void add(TE entity); 16 | 17 | /** 18 | * 19 | * @param id 20 | */ 21 | void remove(T id); 22 | 23 | /** 24 | * 25 | * @param entity 26 | */ 27 | void update(TE entity); 28 | } 29 | -------------------------------------------------------------------------------- /Chapter04/restaurant-service/src/main/java/com/packtpub/mmj/restaurant/domain/repository/RestaurantRepository.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.restaurant.domain.repository; 2 | 3 | import java.util.Collection; 4 | 5 | /** 6 | * 7 | * @author Sourabh Sharma 8 | * @param 9 | * @param 10 | */ 11 | public interface RestaurantRepository extends Repository { 12 | 13 | /** 14 | * 15 | * @param name 16 | * @return 17 | */ 18 | boolean containsName(String name); 19 | 20 | /** 21 | * 22 | * @param name 23 | * @return 24 | * @throws Exception 25 | */ 26 | public Collection findByName(String name) throws Exception; 27 | } 28 | -------------------------------------------------------------------------------- /Chapter04/restaurant-service/src/main/java/com/packtpub/mmj/restaurant/domain/service/BaseService.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.restaurant.domain.service; 2 | 3 | import com.packtpub.mmj.restaurant.domain.repository.Repository; 4 | import java.util.Collection; 5 | 6 | /** 7 | * 8 | * @author Sourabh Sharma 9 | * @param 10 | * @param 11 | */ 12 | public abstract class BaseService extends ReadOnlyBaseService { 13 | 14 | private Repository _repository; 15 | 16 | BaseService(Repository repository) { 17 | super(repository); 18 | _repository = repository; 19 | } 20 | 21 | /** 22 | * 23 | * @param entity 24 | * @throws Exception 25 | */ 26 | public void add(TE entity) throws Exception { 27 | _repository.add(entity); 28 | } 29 | 30 | /** 31 | * 32 | * @return 33 | */ 34 | public Collection getAll() { 35 | return _repository.getAll(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Chapter04/restaurant-service/src/main/java/com/packtpub/mmj/restaurant/domain/service/ReadOnlyBaseService.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.restaurant.domain.service; 2 | 3 | import com.packtpub.mmj.restaurant.domain.repository.ReadOnlyRepository; 4 | 5 | /** 6 | * 7 | * @author Sourabh Sharma 8 | * @param 9 | * @param 10 | */ 11 | public abstract class ReadOnlyBaseService { 12 | 13 | private ReadOnlyRepository repository; 14 | 15 | ReadOnlyBaseService(ReadOnlyRepository repository) { 16 | this.repository = repository; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter04/restaurant-service/src/main/java/com/packtpub/mmj/restaurant/domain/service/RestaurantService.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.restaurant.domain.service; 2 | 3 | import com.packtpub.mmj.restaurant.domain.model.entity.Entity; 4 | import com.packtpub.mmj.restaurant.domain.model.entity.Restaurant; 5 | import java.util.ArrayList; 6 | import java.util.Collection; 7 | import java.util.Map; 8 | 9 | /** 10 | * 11 | * @author Sourabh Sharma 12 | */ 13 | public interface RestaurantService { 14 | 15 | /** 16 | * 17 | * @param restaurant 18 | * @throws Exception 19 | */ 20 | public void add(Restaurant restaurant) throws Exception; 21 | 22 | /** 23 | * 24 | * @param restaurant 25 | * @throws Exception 26 | */ 27 | public void update(Restaurant restaurant) throws Exception; 28 | 29 | /** 30 | * 31 | * @param id 32 | * @throws Exception 33 | */ 34 | public void delete(String id) throws Exception; 35 | 36 | /** 37 | * 38 | * @param restaurantId 39 | * @return 40 | * @throws Exception 41 | */ 42 | public Entity findById(String restaurantId) throws Exception; 43 | 44 | /** 45 | * 46 | * @param name 47 | * @return 48 | * @throws Exception 49 | */ 50 | public Collection findByName(String name) throws Exception; 51 | 52 | /** 53 | * 54 | * @param name 55 | * @return 56 | * @throws Exception 57 | */ 58 | public Collection findByCriteria(Map> name) throws Exception; 59 | } 60 | -------------------------------------------------------------------------------- /Chapter04/restaurant-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | # Spring properties 2 | spring: 3 | application: 4 | name: restaurant-service # Service registers under this name 5 | freemarker: 6 | enabled: false # Ignore Eureka dashboard FreeMarker templates 7 | thymeleaf: 8 | cache: false # Allow Thymeleaf templates to be reloaded at runtime 9 | 10 | # Map the error path to error template (for Thymeleaf) 11 | error: 12 | path=/error 13 | 14 | # Discovery Server Access 15 | eureka: 16 | client: 17 | serviceUrl: 18 | defaultZone: http://localhost:8761/eureka/ 19 | 20 | # HTTP Server 21 | server: 22 | port: 2222 # HTTP (Tomcat) port 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Chapter04/restaurant-service/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: restaurant-service -------------------------------------------------------------------------------- /Chapter04/restaurant-service/src/test/resources/application.yml: -------------------------------------------------------------------------------- 1 | # Spring properties 2 | spring: 3 | cloud: 4 | discovery: 5 | enabled: false 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Chapter04/user-service/nbactions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CUSTOM-clean and package 5 | clean and package 6 | 7 | clean 8 | package 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Chapter04/user-service/src/main/java/com/packtpub/mmj/user/UsersApp.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.user; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | 7 | /** 8 | * 9 | * @author Sourabh Sharma 10 | */ 11 | @SpringBootApplication 12 | @EnableEurekaClient 13 | public class UsersApp { 14 | 15 | /** 16 | * 17 | * @param args 18 | */ 19 | public static void main(String[] args) { 20 | SpringApplication.run(UsersApp.class, args); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /Chapter04/user-service/src/main/java/com/packtpub/mmj/user/domain/model/entity/BaseEntity.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.user.domain.model.entity; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | * @param 7 | */ 8 | public abstract class BaseEntity extends Entity { 9 | 10 | private boolean isModified; 11 | 12 | /** 13 | * 14 | * @param id 15 | * @param name 16 | */ 17 | public BaseEntity(T id, String name) { 18 | super.id = id; 19 | super.name = name; 20 | isModified = false; 21 | } 22 | 23 | /** 24 | * 25 | * @return 26 | */ 27 | public boolean isIsModified() { 28 | return isModified; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Chapter04/user-service/src/main/java/com/packtpub/mmj/user/domain/model/entity/Entity.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.user.domain.model.entity; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | * @param 7 | */ 8 | public abstract class Entity { 9 | 10 | T id; 11 | String name; 12 | 13 | /** 14 | * 15 | * @return 16 | */ 17 | public T getId() { 18 | return id; 19 | } 20 | 21 | /** 22 | * 23 | * @param id 24 | */ 25 | public void setId(T id) { 26 | this.id = id; 27 | } 28 | 29 | /** 30 | * 31 | * @return 32 | */ 33 | public String getName() { 34 | return name; 35 | } 36 | 37 | /** 38 | * 39 | * @param name 40 | */ 41 | public void setName(String name) { 42 | this.name = name; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /Chapter04/user-service/src/main/java/com/packtpub/mmj/user/domain/repository/ReadOnlyRepository.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.user.domain.repository; 2 | 3 | import java.util.Collection; 4 | 5 | /** 6 | * 7 | * @author Sourabh Sharma 8 | * @param 9 | * @param 10 | */ 11 | public interface ReadOnlyRepository { 12 | 13 | //long Count; 14 | /** 15 | * 16 | * @param id 17 | * @return 18 | */ 19 | boolean contains(T id); 20 | 21 | /** 22 | * 23 | * @param id 24 | * @return 25 | */ 26 | TE get(T id); 27 | 28 | /** 29 | * 30 | * @return 31 | */ 32 | Collection getAll(); 33 | } 34 | -------------------------------------------------------------------------------- /Chapter04/user-service/src/main/java/com/packtpub/mmj/user/domain/repository/Repository.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.user.domain.repository; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | * @param 7 | * @param 8 | */ 9 | public interface Repository extends ReadOnlyRepository { 10 | 11 | /** 12 | * 13 | * @param entity 14 | */ 15 | void add(TE entity); 16 | 17 | /** 18 | * 19 | * @param id 20 | */ 21 | void remove(T id); 22 | 23 | /** 24 | * 25 | * @param entity 26 | */ 27 | void update(TE entity); 28 | } 29 | -------------------------------------------------------------------------------- /Chapter04/user-service/src/main/java/com/packtpub/mmj/user/domain/repository/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.user.domain.repository; 2 | 3 | import java.util.Collection; 4 | 5 | /** 6 | * 7 | * @author Sourabh Sharma 8 | * @param 9 | * @param 10 | */ 11 | public interface UserRepository extends Repository { 12 | 13 | /** 14 | * 15 | * @param name 16 | * @return 17 | */ 18 | boolean containsName(String name); 19 | 20 | /** 21 | * 22 | * @param name 23 | * @return 24 | * @throws Exception 25 | */ 26 | public Collection findByName(String name) throws Exception; 27 | } 28 | -------------------------------------------------------------------------------- /Chapter04/user-service/src/main/java/com/packtpub/mmj/user/domain/service/BaseService.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.user.domain.service; 2 | 3 | import com.packtpub.mmj.user.domain.repository.Repository; 4 | import java.util.Collection; 5 | 6 | /** 7 | * 8 | * @author Sourabh Sharma 9 | * @param 10 | * @param 11 | */ 12 | public abstract class BaseService extends ReadOnlyBaseService { 13 | 14 | private Repository _repository; 15 | 16 | BaseService(Repository repository) { 17 | super(repository); 18 | _repository = repository; 19 | } 20 | 21 | /** 22 | * 23 | * @param entity 24 | * @throws Exception 25 | */ 26 | public void add(TE entity) throws Exception { 27 | _repository.add(entity); 28 | } 29 | 30 | /** 31 | * 32 | * @return 33 | */ 34 | public Collection getAll() { 35 | return _repository.getAll(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Chapter04/user-service/src/main/java/com/packtpub/mmj/user/domain/service/ReadOnlyBaseService.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.user.domain.service; 2 | 3 | import com.packtpub.mmj.user.domain.repository.ReadOnlyRepository; 4 | 5 | /** 6 | * 7 | * @author Sourabh Sharma 8 | * @param 9 | * @param 10 | */ 11 | public abstract class ReadOnlyBaseService { 12 | 13 | private ReadOnlyRepository repository; 14 | 15 | ReadOnlyBaseService(ReadOnlyRepository repository) { 16 | this.repository = repository; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter04/user-service/src/main/java/com/packtpub/mmj/user/domain/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.user.domain.service; 2 | 3 | import com.packtpub.mmj.user.domain.model.entity.Entity; 4 | import com.packtpub.mmj.user.domain.model.entity.User; 5 | import java.util.ArrayList; 6 | import java.util.Collection; 7 | import java.util.Map; 8 | 9 | /** 10 | * 11 | * @author Sourabh Sharma 12 | */ 13 | public interface UserService { 14 | 15 | /** 16 | * 17 | * @param booking 18 | * @throws Exception 19 | */ 20 | public void add(User booking) throws Exception; 21 | 22 | /** 23 | * 24 | * @param booking 25 | * @throws Exception 26 | */ 27 | public void update(User booking) throws Exception; 28 | 29 | /** 30 | * 31 | * @param id 32 | * @throws Exception 33 | */ 34 | public void delete(String id) throws Exception; 35 | 36 | /** 37 | * 38 | * @param id 39 | * @return 40 | * @throws Exception 41 | */ 42 | public Entity findById(String id) throws Exception; 43 | 44 | /** 45 | * 46 | * @param name 47 | * @return 48 | * @throws Exception 49 | */ 50 | public Collection findByName(String name) throws Exception; 51 | 52 | /** 53 | * 54 | * @param name 55 | * @return 56 | * @throws Exception 57 | */ 58 | public Collection findByCriteria(Map> name) throws Exception; 59 | } 60 | -------------------------------------------------------------------------------- /Chapter04/user-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | # Spring properties 2 | spring: 3 | application: 4 | name: user-service # Service registers under this name 5 | freemarker: 6 | enabled: false # Ignore Eureka dashboard FreeMarker templates 7 | thymeleaf: 8 | cache: false # Allow Thymeleaf templates to be reloaded at runtime 9 | 10 | # Map the error path to error template (for Thymeleaf) 11 | error: 12 | path=/error 13 | 14 | # Discovery Server Access 15 | eureka: 16 | client: 17 | serviceUrl: 18 | defaultZone: http://localhost:8761/eureka/ 19 | 20 | # HTTP Server 21 | server: 22 | port: 2224 # HTTP (Tomcat) port 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Chapter04/user-service/src/test/resources/application.yml: -------------------------------------------------------------------------------- 1 | # Spring properties 2 | spring: 3 | cloud: 4 | discovery: 5 | enabled: false 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Chapter05/api-service/nbactions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CUSTOM-package 5 | clean and package 6 | 7 | clean 8 | package 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Chapter05/booking-service/nbactions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CUSTOM-clean and package 5 | clean and package 6 | 7 | clean 8 | package 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Chapter05/booking-service/src/main/java/com/packtpub/mmj/booking/BookingApp.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.booking; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | 7 | /** 8 | * 9 | * @author Sourabh Sharma 10 | */ 11 | @SpringBootApplication 12 | @EnableEurekaClient 13 | public class BookingApp { 14 | 15 | /** 16 | * 17 | * @param args 18 | */ 19 | public static void main(String[] args) { 20 | SpringApplication.run(BookingApp.class, args); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /Chapter05/booking-service/src/main/java/com/packtpub/mmj/booking/domain/model/entity/BaseEntity.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.booking.domain.model.entity; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | * @param 7 | */ 8 | public abstract class BaseEntity extends Entity { 9 | 10 | private boolean isModified; 11 | 12 | /** 13 | * 14 | * @param id 15 | * @param name 16 | */ 17 | public BaseEntity(T id, String name) { 18 | super.id = id; 19 | super.name = name; 20 | isModified = false; 21 | } 22 | 23 | /** 24 | * 25 | * @return 26 | */ 27 | public boolean isIsModified() { 28 | return isModified; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Chapter05/booking-service/src/main/java/com/packtpub/mmj/booking/domain/model/entity/Entity.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.booking.domain.model.entity; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | * @param 7 | */ 8 | public abstract class Entity { 9 | 10 | T id; 11 | String name; 12 | 13 | /** 14 | * 15 | * @return 16 | */ 17 | public T getId() { 18 | return id; 19 | } 20 | 21 | /** 22 | * 23 | * @param id 24 | */ 25 | public void setId(T id) { 26 | this.id = id; 27 | } 28 | 29 | /** 30 | * 31 | * @return 32 | */ 33 | public String getName() { 34 | return name; 35 | } 36 | 37 | /** 38 | * 39 | * @param name 40 | */ 41 | public void setName(String name) { 42 | this.name = name; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /Chapter05/booking-service/src/main/java/com/packtpub/mmj/booking/domain/repository/BookingRepository.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.booking.domain.repository; 2 | 3 | import java.util.Collection; 4 | 5 | /** 6 | * 7 | * @author Sourabh Sharma 8 | * @param 9 | * @param 10 | */ 11 | public interface BookingRepository extends Repository { 12 | 13 | /** 14 | * 15 | * @param name 16 | * @return 17 | */ 18 | boolean containsName(String name); 19 | 20 | /** 21 | * 22 | * @param name 23 | * @return 24 | * @throws Exception 25 | */ 26 | public Collection findByName(String name) throws Exception; 27 | } 28 | -------------------------------------------------------------------------------- /Chapter05/booking-service/src/main/java/com/packtpub/mmj/booking/domain/repository/ReadOnlyRepository.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.booking.domain.repository; 2 | 3 | import java.util.Collection; 4 | 5 | /** 6 | * 7 | * @author Sourabh Sharma 8 | * @param 9 | * @param 10 | */ 11 | public interface ReadOnlyRepository { 12 | 13 | //long Count; 14 | /** 15 | * 16 | * @param id 17 | * @return 18 | */ 19 | boolean contains(T id); 20 | 21 | /** 22 | * 23 | * @param id 24 | * @return 25 | */ 26 | TE get(T id); 27 | 28 | /** 29 | * 30 | * @return 31 | */ 32 | Collection getAll(); 33 | } 34 | -------------------------------------------------------------------------------- /Chapter05/booking-service/src/main/java/com/packtpub/mmj/booking/domain/repository/Repository.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.booking.domain.repository; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | * @param 7 | * @param 8 | */ 9 | public interface Repository extends ReadOnlyRepository { 10 | 11 | /** 12 | * 13 | * @param entity 14 | */ 15 | void add(TE entity); 16 | 17 | /** 18 | * 19 | * @param id 20 | */ 21 | void remove(T id); 22 | 23 | /** 24 | * 25 | * @param entity 26 | */ 27 | void update(TE entity); 28 | } 29 | -------------------------------------------------------------------------------- /Chapter05/booking-service/src/main/java/com/packtpub/mmj/booking/domain/service/BaseService.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.booking.domain.service; 2 | 3 | import com.packtpub.mmj.booking.domain.repository.Repository; 4 | import java.util.Collection; 5 | 6 | /** 7 | * 8 | * @author Sourabh Sharma 9 | * @param 10 | * @param 11 | */ 12 | public abstract class BaseService extends ReadOnlyBaseService { 13 | 14 | private Repository _repository; 15 | 16 | BaseService(Repository repository) { 17 | super(repository); 18 | _repository = repository; 19 | } 20 | 21 | /** 22 | * 23 | * @param entity 24 | * @throws Exception 25 | */ 26 | public void add(TE entity) throws Exception { 27 | _repository.add(entity); 28 | } 29 | 30 | /** 31 | * 32 | * @return 33 | */ 34 | public Collection getAll() { 35 | return _repository.getAll(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Chapter05/booking-service/src/main/java/com/packtpub/mmj/booking/domain/service/BookingService.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.booking.domain.service; 2 | 3 | import com.packtpub.mmj.booking.domain.model.entity.Booking; 4 | import com.packtpub.mmj.booking.domain.model.entity.Entity; 5 | import java.util.ArrayList; 6 | import java.util.Collection; 7 | import java.util.Map; 8 | 9 | /** 10 | * 11 | * @author Sourabh Sharma 12 | */ 13 | public interface BookingService { 14 | 15 | /** 16 | * 17 | * @param booking 18 | * @throws Exception 19 | */ 20 | public void add(Booking booking) throws Exception; 21 | 22 | /** 23 | * 24 | * @param booking 25 | * @throws Exception 26 | */ 27 | public void update(Booking booking) throws Exception; 28 | 29 | /** 30 | * 31 | * @param id 32 | * @throws Exception 33 | */ 34 | public void delete(String id) throws Exception; 35 | 36 | /** 37 | * 38 | * @param id 39 | * @return 40 | * @throws Exception 41 | */ 42 | public Entity findById(String id) throws Exception; 43 | 44 | /** 45 | * 46 | * @param name 47 | * @return 48 | * @throws Exception 49 | */ 50 | public Collection findByName(String name) throws Exception; 51 | 52 | /** 53 | * 54 | * @param name 55 | * @return 56 | * @throws Exception 57 | */ 58 | public Collection findByCriteria(Map> name) throws Exception; 59 | } 60 | -------------------------------------------------------------------------------- /Chapter05/booking-service/src/main/java/com/packtpub/mmj/booking/domain/service/ReadOnlyBaseService.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.booking.domain.service; 2 | 3 | import com.packtpub.mmj.booking.domain.repository.ReadOnlyRepository; 4 | 5 | /** 6 | * 7 | * @author Sourabh Sharma 8 | * @param 9 | * @param 10 | */ 11 | public abstract class ReadOnlyBaseService { 12 | 13 | private ReadOnlyRepository repository; 14 | 15 | ReadOnlyBaseService(ReadOnlyRepository repository) { 16 | this.repository = repository; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter05/booking-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | # Spring properties 2 | spring: 3 | application: 4 | name: booking-service # Service registers under this name 5 | # Added to fix - java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut hystrixCommandAnnotationPointcut 6 | aop: 7 | auto: false 8 | 9 | # Map the error path to error template (for Thymeleaf) 10 | error: 11 | path=/error 12 | 13 | # Discovery Server Access 14 | eureka: 15 | client: 16 | serviceUrl: 17 | defaultZone: http://localhost:8761/eureka/ 18 | 19 | # HTTP Server 20 | server: 21 | port: 0 # HTTP (Tomcat) port 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Chapter05/booking-service/src/test/resources/application.yml: -------------------------------------------------------------------------------- 1 | # Spring properties 2 | spring: 3 | cloud: 4 | discovery: 5 | enabled: false 6 | aop: 7 | auto: false 8 | # config: 9 | # enabled: false 10 | # server: 11 | # health: 12 | # enabled: false 13 | # 14 | #hystrix: 15 | # command: 16 | # default: 17 | # circuitBreaker: 18 | # enabled: false 19 | # fallback: 20 | # enabled: false -------------------------------------------------------------------------------- /Chapter05/common/nbactions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CUSTOM-clean package 5 | clean package 6 | 7 | clean 8 | package 9 | 10 | 11 | 12 | CUSTOM-install 13 | install 14 | 15 | clean 16 | install 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Chapter05/common/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | com.packtpub.mmj 6 | 6392_chapter5 7 | MMJ-ED2-SNAPSHOT 8 | 9 | online-table-reservation-common 10 | jar 11 | online-table-reservation:common 12 | 13 | 14 | org.springframework.cloud 15 | spring-cloud-starter-hystrix 16 | 17 | 18 | org.springframework.boot 19 | spring-boot-starter-web 20 | 21 | 22 | 23 | 1.8 24 | 1.8 25 | 26 | -------------------------------------------------------------------------------- /Chapter05/common/src/main/java/com/packtpub/mmj/common/MDCConcurrentCallable.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.common; 2 | 3 | import java.util.Map; 4 | import java.util.concurrent.Callable; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.slf4j.MDC; 8 | 9 | public class MDCConcurrentCallable implements Callable { 10 | 11 | private static final Logger LOG = LoggerFactory.getLogger(MDCConcurrentCallable.class); 12 | 13 | private final Callable actual; 14 | private final Map parentMDC; 15 | 16 | public MDCConcurrentCallable(Callable actual) { 17 | LOG.debug("Init MDCHystrixContextCallable..."); 18 | this.actual = actual; 19 | this.parentMDC = MDC.getCopyOfContextMap(); 20 | LOG.debug("actual --> " + actual); 21 | LOG.debug("this.parentMDC --> " + this.parentMDC); 22 | } 23 | 24 | @Override 25 | public K call() throws Exception { 26 | LOG.debug("Call using MDCHystrixContextCallable..."); 27 | Map childMDC = MDC.getCopyOfContextMap(); 28 | LOG.debug("childMDC --> " + childMDC); 29 | try { 30 | if (parentMDC != null) { 31 | MDC.setContextMap(parentMDC); 32 | } 33 | LOG.debug("parentMDC --> " + parentMDC); 34 | return actual.call(); 35 | } finally { 36 | if (childMDC != null) { 37 | MDC.setContextMap(childMDC); 38 | } 39 | } 40 | } 41 | 42 | public static void main(String[] args) { 43 | System.out.println("Non-Executable"); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Chapter05/common/src/main/java/com/packtpub/mmj/common/MDCHystrixConcurrencyStrategy.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.common; 2 | 3 | import com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy; 4 | import java.util.concurrent.Callable; 5 | 6 | public class MDCHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy { 7 | 8 | @Override 9 | public Callable wrapCallable(Callable callable) { 10 | return new MDCConcurrentCallable<>(callable); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Chapter05/dashboard-server/nbactions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CUSTOM-clean package 5 | clean package 6 | 7 | clean 8 | package 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Chapter05/dashboard-server/src/main/java/com/packtpub/mmj/dashboard/DashboardApp.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.dashboard; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.builder.SpringApplicationBuilder; 6 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; 7 | import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; 8 | import org.springframework.stereotype.Controller; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | 11 | @SpringBootApplication 12 | @Controller 13 | @EnableHystrixDashboard 14 | public class DashboardApp extends SpringBootServletInitializer { 15 | 16 | @RequestMapping("/") 17 | public String home() { 18 | return "forward:/hystrix"; 19 | } 20 | 21 | @Override 22 | protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 23 | return application.sources(DashboardApp.class).web(true); 24 | } 25 | 26 | public static void main(String[] args) { 27 | SpringApplication.run(DashboardApp.class, args); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Chapter05/dashboard-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | # Hystrix Dashboard properties 2 | spring: 3 | application: 4 | name: dashboard-server 5 | 6 | endpoints: 7 | restart: 8 | enabled: true 9 | shutdown: 10 | enabled: true 11 | 12 | server: 13 | port: 7979 14 | 15 | eureka: 16 | instance: 17 | leaseRenewalIntervalInSeconds: 3 18 | metadataMap: 19 | instanceId: ${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${random.value}}} 20 | 21 | client: 22 | # Default values comes from org.springframework.cloud.netflix.eurek.EurekaClientConfigBean 23 | registryFetchIntervalSeconds: 5 24 | instanceInfoReplicationIntervalSeconds: 5 25 | initialInstanceInfoReplicationIntervalSeconds: 5 26 | serviceUrl: 27 | defaultZone: http://localhost:8761/eureka/ 28 | fetchRegistry: false 29 | 30 | logging: 31 | level: 32 | ROOT: WARN 33 | org.springframework.web: WARN 34 | -------------------------------------------------------------------------------- /Chapter05/dashboard-server/src/main/resources/hystrixdashboard/stream/hystrix.stream: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Chapter05/docker-compose.yml: -------------------------------------------------------------------------------- 1 | 2 | eureka: 3 | image: localhost:5000/sourabhh/eureka-server:PACKT-SNAPSHOT 4 | ports: 5 | - "8761:8761" 6 | 7 | restaurant-service: 8 | image: localhost:5000/sourabhh/restaurant-service:PACKT-SNAPSHOT 9 | ports: 10 | - "8080:8080" 11 | links: 12 | - eureka 13 | -------------------------------------------------------------------------------- /Chapter05/docker/docker-assembly.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | ${project.artifactId} 5 | 6 | 7 | target/${project.build.finalName}.jar 8 | / 9 | 10 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Chapter05/eureka-server/nbactions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CUSTOM-clean and package 5 | clean and package 6 | 7 | clean 8 | package 9 | 10 | 11 | 12 | CUSTOM-docker:build 13 | docker:build 14 | 15 | docker:build 16 | 17 | 18 | 19 | CUSTOM-docker-start 20 | docker:start 21 | 22 | docker:start 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Chapter05/eureka-server/src/main/docker/docker-assembly.xml: -------------------------------------------------------------------------------- 1 | 5 | ${project.artifactId} 6 | 7 | 8 | target/${project.build.finalName}.jar 9 | / 10 | 11 | 12 | src/main/resources/docker-config.yml 13 | / 14 | 15 | 16 | -------------------------------------------------------------------------------- /Chapter05/eureka-server/src/main/java/com/packtpub/mmj/eureka/service/App.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.eureka.service; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | /** 10 | * 11 | * @author Sourabh Sharma 12 | */ 13 | @SpringBootApplication 14 | @Configuration 15 | @EnableAutoConfiguration 16 | @EnableEurekaServer 17 | public class App { 18 | 19 | /** 20 | * 21 | * @param args 22 | */ 23 | public static void main(String[] args) { 24 | SpringApplication.run(App.class, args); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Chapter05/eureka-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | # Yureka Server Configuration 2 | server: 3 | port: ${vcap.application.port:8761} # HTTP port 4 | 5 | info: 6 | component: Discovery Server 7 | 8 | eureka: 9 | instance: 10 | hostname: localhost 11 | client: 12 | registerWithEureka: false 13 | fetchRegistry: false 14 | serviceUrl: 15 | defaultZone: ${vcap.services.${PREFIX:}eureka.credentials.uri:http://user:password@localhost:8761}/eureka/ 16 | server: 17 | waitTimeInMsWhenSyncEmpty: 0 18 | enableSelfPreservation: false 19 | 20 | spring: 21 | thymeleaf: 22 | enabled: false # Disable Thymeleaf 23 | 24 | --- 25 | # For deployment in Docker containers 26 | spring: 27 | profiles: docker 28 | 29 | server: 30 | port: ${vcap.application.port:8761} 31 | 32 | eureka: 33 | instance: 34 | hostname: eureka 35 | client: 36 | registerWithEureka: false 37 | fetchRegistry: false 38 | serviceUrl: 39 | defaultZone: http://eureka:8761/eureka/ 40 | server: 41 | waitTimeInMsWhenSyncEmpty: 0 42 | enableSelfPreservation: false -------------------------------------------------------------------------------- /Chapter05/eureka-server/src/main/resources/docker-config.yml: -------------------------------------------------------------------------------- 1 | FROM java:8-jre 2 | MAINTAINER sourabhh 3 | EXPOSE 8080 4 | COPY maven /maven/ 5 | CMD java -Dspring.profiles.active="docker" -jar \ 6 | /maven/eureka-server.jar server \ 7 | /maven/docker-config.yml -------------------------------------------------------------------------------- /Chapter05/nbactions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CUSTOM-clean and package 5 | clean and package 6 | 7 | clean 8 | package 9 | 10 | 11 | 12 | CUSTOM-clearn package docker 13 | clearn package docker 14 | 15 | clearn 16 | package 17 | 18 | 19 | docker 20 | 21 | 22 | 23 | CUSTOM-install 24 | install 25 | 26 | install 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /Chapter05/restaurant-service/nbactions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CUSTOM-clean and package 5 | clean and package 6 | 7 | clean 8 | package 9 | 10 | 11 | 12 | CUSTOM-docker:build 13 | docker:build 14 | 15 | docker:build 16 | 17 | 18 | 19 | CUSTOM-docker-start 20 | docker:start 21 | 22 | docker:start 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Chapter05/restaurant-service/src/main/docker/docker-assembly.xml: -------------------------------------------------------------------------------- 1 | 5 | ${project.artifactId} 6 | 7 | 8 | target/${project.build.finalName}.jar 9 | / 10 | 11 | 12 | src/main/resources/docker-config.yml 13 | / 14 | 15 | 16 | -------------------------------------------------------------------------------- /Chapter05/restaurant-service/src/main/java/com/packtpub/mmj/restaurant/RestaurantApp.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.restaurant; 2 | 3 | import com.rabbitmq.client.ConnectionFactory; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; 7 | import org.springframework.beans.factory.annotation.Value; 8 | import org.springframework.boot.SpringApplication; 9 | import org.springframework.boot.autoconfigure.SpringBootApplication; 10 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; 11 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 12 | import org.springframework.context.annotation.Bean; 13 | 14 | @SpringBootApplication 15 | @EnableEurekaClient 16 | @EnableCircuitBreaker 17 | public class RestaurantApp { 18 | 19 | private static final Logger LOG = LoggerFactory.getLogger(RestaurantApp.class); 20 | 21 | @Value("${app.rabbitmq.host:localhost}") 22 | String rabbitMqHost; 23 | 24 | @Bean 25 | public ConnectionFactory connectionFactory() { 26 | LOG.info("Create RabbitMqCF for host: {}", rabbitMqHost); 27 | CachingConnectionFactory connectionFactory = new CachingConnectionFactory(rabbitMqHost); 28 | return connectionFactory.getRabbitConnectionFactory(); 29 | } 30 | 31 | /** 32 | * 33 | * @param args 34 | */ 35 | public static void main(String[] args) { 36 | SpringApplication.run(RestaurantApp.class, args); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Chapter05/restaurant-service/src/main/java/com/packtpub/mmj/restaurant/domain/model/entity/BaseEntity.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.restaurant.domain.model.entity; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | * @param 7 | */ 8 | public abstract class BaseEntity extends Entity { 9 | 10 | private boolean isModified; 11 | 12 | /** 13 | * 14 | * @param id 15 | * @param name 16 | */ 17 | public BaseEntity(T id, String name) { 18 | super.id = id; 19 | super.name = name; 20 | isModified = false; 21 | } 22 | 23 | /** 24 | * 25 | * @return 26 | */ 27 | public boolean isIsModified() { 28 | return isModified; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Chapter05/restaurant-service/src/main/java/com/packtpub/mmj/restaurant/domain/model/entity/Entity.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.restaurant.domain.model.entity; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | * @param 7 | */ 8 | public abstract class Entity { 9 | 10 | T id; 11 | String name; 12 | 13 | /** 14 | * 15 | * @return 16 | */ 17 | public T getId() { 18 | return id; 19 | } 20 | 21 | /** 22 | * 23 | * @param id 24 | */ 25 | public void setId(T id) { 26 | this.id = id; 27 | } 28 | 29 | /** 30 | * 31 | * @return 32 | */ 33 | public String getName() { 34 | return name; 35 | } 36 | 37 | /** 38 | * 39 | * @param name 40 | */ 41 | public void setName(String name) { 42 | this.name = name; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /Chapter05/restaurant-service/src/main/java/com/packtpub/mmj/restaurant/domain/model/entity/Table.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.restaurant.domain.model.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import java.math.BigInteger; 5 | 6 | /** 7 | * 8 | * @author Sourabh Sharma 9 | */ 10 | public class Table extends BaseEntity { 11 | 12 | private int capacity; 13 | 14 | /** 15 | * 16 | * @param name 17 | * @param id 18 | * @param capacity 19 | */ 20 | public Table(@JsonProperty("name") String name, @JsonProperty("id") BigInteger id, @JsonProperty("capacity") int capacity) { 21 | super(id, name); 22 | this.capacity = capacity; 23 | } 24 | 25 | /** 26 | * 27 | * @param capacity 28 | */ 29 | public void setCapacity(int capacity) { 30 | this.capacity = capacity; 31 | } 32 | 33 | /** 34 | * 35 | * @return 36 | */ 37 | public int getCapacity() { 38 | return capacity; 39 | } 40 | 41 | /** 42 | * Overridden toString() method that return String presentation of the 43 | * Object 44 | * 45 | * @return 46 | */ 47 | @Override 48 | public String toString() { 49 | return String.format("{id: %s, name: %s, capacity: %s}", 50 | this.getId(), this.getName(), this.getCapacity()); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /Chapter05/restaurant-service/src/main/java/com/packtpub/mmj/restaurant/domain/repository/ReadOnlyRepository.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.restaurant.domain.repository; 2 | 3 | import java.util.Collection; 4 | 5 | /** 6 | * 7 | * @author Sourabh Sharma 8 | * @param 9 | * @param 10 | */ 11 | public interface ReadOnlyRepository { 12 | 13 | //long Count; 14 | /** 15 | * 16 | * @param id 17 | * @return 18 | */ 19 | boolean contains(T id); 20 | 21 | /** 22 | * 23 | * @param id 24 | * @return 25 | */ 26 | TE get(T id); 27 | 28 | /** 29 | * 30 | * @return 31 | */ 32 | Collection getAll(); 33 | } 34 | -------------------------------------------------------------------------------- /Chapter05/restaurant-service/src/main/java/com/packtpub/mmj/restaurant/domain/repository/Repository.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.restaurant.domain.repository; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | * @param 7 | * @param 8 | */ 9 | public interface Repository extends ReadOnlyRepository { 10 | 11 | /** 12 | * 13 | * @param entity 14 | */ 15 | void add(TE entity); 16 | 17 | /** 18 | * 19 | * @param id 20 | */ 21 | void remove(T id); 22 | 23 | /** 24 | * 25 | * @param entity 26 | */ 27 | void update(TE entity); 28 | } 29 | -------------------------------------------------------------------------------- /Chapter05/restaurant-service/src/main/java/com/packtpub/mmj/restaurant/domain/repository/RestaurantRepository.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.restaurant.domain.repository; 2 | 3 | import java.util.Collection; 4 | 5 | /** 6 | * 7 | * @author Sourabh Sharma 8 | * @param 9 | * @param 10 | */ 11 | public interface RestaurantRepository extends Repository { 12 | 13 | /** 14 | * 15 | * @param name 16 | * @return 17 | */ 18 | boolean containsName(String name); 19 | 20 | /** 21 | * 22 | * @param name 23 | * @return 24 | * @throws Exception 25 | */ 26 | public Collection findByName(String name) throws Exception; 27 | } 28 | -------------------------------------------------------------------------------- /Chapter05/restaurant-service/src/main/java/com/packtpub/mmj/restaurant/domain/service/BaseService.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.restaurant.domain.service; 2 | 3 | import com.packtpub.mmj.restaurant.domain.repository.Repository; 4 | import java.util.Collection; 5 | 6 | /** 7 | * 8 | * @author Sourabh Sharma 9 | * @param 10 | * @param 11 | */ 12 | public abstract class BaseService extends ReadOnlyBaseService { 13 | 14 | private Repository _repository; 15 | 16 | BaseService(Repository repository) { 17 | super(repository); 18 | _repository = repository; 19 | } 20 | 21 | /** 22 | * 23 | * @param entity 24 | * @throws Exception 25 | */ 26 | public void add(TE entity) throws Exception { 27 | _repository.add(entity); 28 | } 29 | 30 | /** 31 | * 32 | * @return 33 | */ 34 | public Collection getAll() { 35 | return _repository.getAll(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Chapter05/restaurant-service/src/main/java/com/packtpub/mmj/restaurant/domain/service/ReadOnlyBaseService.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.restaurant.domain.service; 2 | 3 | import com.packtpub.mmj.restaurant.domain.repository.ReadOnlyRepository; 4 | 5 | /** 6 | * 7 | * @author Sourabh Sharma 8 | * @param 9 | * @param 10 | */ 11 | public abstract class ReadOnlyBaseService { 12 | 13 | private ReadOnlyRepository repository; 14 | 15 | ReadOnlyBaseService(ReadOnlyRepository repository) { 16 | this.repository = repository; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter05/restaurant-service/src/main/java/com/packtpub/mmj/restaurant/domain/service/RestaurantService.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.restaurant.domain.service; 2 | 3 | import com.packtpub.mmj.restaurant.domain.model.entity.Entity; 4 | import com.packtpub.mmj.restaurant.domain.model.entity.Restaurant; 5 | import java.util.ArrayList; 6 | import java.util.Collection; 7 | import java.util.Map; 8 | 9 | /** 10 | * 11 | * @author Sourabh Sharma 12 | */ 13 | public interface RestaurantService { 14 | 15 | /** 16 | * 17 | * @param restaurant 18 | * @throws Exception 19 | */ 20 | public void add(Restaurant restaurant) throws Exception; 21 | 22 | /** 23 | * 24 | * @param restaurant 25 | * @throws Exception 26 | */ 27 | public void update(Restaurant restaurant) throws Exception; 28 | 29 | /** 30 | * 31 | * @param id 32 | * @throws Exception 33 | */ 34 | public void delete(String id) throws Exception; 35 | 36 | /** 37 | * 38 | * @param restaurantId 39 | * @return 40 | * @throws Exception 41 | */ 42 | public Entity findById(String restaurantId) throws Exception; 43 | 44 | /** 45 | * 46 | * @param name 47 | * @return 48 | * @throws Exception 49 | */ 50 | public Collection findByName(String name) throws Exception; 51 | 52 | /** 53 | * 54 | * @param name 55 | * @return 56 | * @throws Exception 57 | */ 58 | public Collection findByCriteria(Map> name) throws Exception; 59 | } 60 | -------------------------------------------------------------------------------- /Chapter05/restaurant-service/src/main/resources/docker-config.yml: -------------------------------------------------------------------------------- 1 | FROM java:8-jre 2 | MAINTAINER sourabhh 3 | EXPOSE 8080 4 | COPY maven /maven/ 5 | CMD java -Dspring.profiles.active="docker" -jar \ 6 | /maven/restaurant-service.jar server \ 7 | /maven/docker-config.yml -------------------------------------------------------------------------------- /Chapter05/restaurant-service/src/test/java/com/packtpub/mmj/restaurant/resources/docker/DockerIT.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.restaurant.resources.docker; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | */ 7 | public interface DockerIT { 8 | // Marker for Docker integratino Tests 9 | } 10 | -------------------------------------------------------------------------------- /Chapter05/restaurant-service/src/test/java/com/packtpub/mmj/restaurant/resources/docker/RestaurantAppDockerIT.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.restaurant.resources.docker; 2 | 3 | import java.io.IOException; 4 | import java.net.HttpURLConnection; 5 | import java.net.URL; 6 | import static org.junit.Assert.assertEquals; 7 | import org.junit.Test; 8 | import org.junit.experimental.categories.Category; 9 | 10 | /** 11 | * 12 | * @author Sourabh Sharma 13 | */ 14 | @Category(DockerIT.class) 15 | public class RestaurantAppDockerIT { 16 | 17 | /** 18 | * 19 | * @throws IOException 20 | */ 21 | @Test 22 | public void testConnection() throws IOException { 23 | String baseUrl = System.getProperty("service.url"); 24 | URL serviceUrl = new URL(baseUrl + "v1/restaurants/1"); 25 | HttpURLConnection connection = (HttpURLConnection) serviceUrl.openConnection(); 26 | int responseCode = connection.getResponseCode(); 27 | assertEquals(200, responseCode); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Chapter05/restaurant-service/src/test/resources/application.yml: -------------------------------------------------------------------------------- 1 | # Spring properties 2 | spring: 3 | cloud: 4 | discovery: 5 | enabled: false 6 | aop: 7 | auto: false 8 | # config: 9 | # enabled: false 10 | # server: 11 | # health: 12 | # enabled: false 13 | # 14 | #hystrix: 15 | # command: 16 | # default: 17 | # circuitBreaker: 18 | # enabled: false 19 | # fallback: 20 | # enabled: false -------------------------------------------------------------------------------- /Chapter05/security-service/nbactions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CUSTOM-clean package 5 | clean package 6 | 7 | clean 8 | package 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Chapter05/security-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | com.packtpub.mmj 6 | 4801_chapter6 7 | PACKT-SNAPSHOT 8 | 9 | security-service 10 | jar 11 | 12 | 13 | org.springframework.cloud 14 | spring-cloud-starter-security 15 | 16 | 17 | org.springframework.cloud 18 | spring-cloud-starter-oauth2 19 | 20 | 21 | online-table-reservation:security-service 22 | 23 | 1.8 24 | 1.8 25 | 26 | -------------------------------------------------------------------------------- /Chapter05/security-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | info: 2 | component: 3 | Security Server 4 | 5 | server: 6 | port: 9001 7 | ssl: 8 | key-store: classpath:keystore.jks 9 | key-store-password: password 10 | key-password: password 11 | contextPath: /auth 12 | 13 | security: 14 | user: 15 | password: password 16 | 17 | logging: 18 | level: 19 | org.springframework.security: DEBUG -------------------------------------------------------------------------------- /Chapter05/security-service/src/main/resources/keystore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Mastering-Microservices-with-Java-9-Second-Edition/73136020a45456bd99d377051d1ae3401f56a10d/Chapter05/security-service/src/main/resources/keystore.jks -------------------------------------------------------------------------------- /Chapter05/security-service/src/main/resources/templates/authorize.ftl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
7 |

Please Confirm

8 | 9 |

10 | Do you authorize "${authorizationRequest.clientId}" at "${authorizationRequest.redirectUri}" to access your protected resources 11 | with scope ${authorizationRequest.scope?join(", ")}. 12 |

13 |
15 | 16 | 17 | 18 | 19 |
21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | -------------------------------------------------------------------------------- /Chapter05/security-service/src/main/resources/templates/login.ftl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
7 |
8 |
9 | 10 | 11 |
12 |
13 | 14 | 15 |
16 | 17 | 18 | 19 |
20 | 21 | 22 | -------------------------------------------------------------------------------- /Chapter05/security-service/src/main/wro/main.less: -------------------------------------------------------------------------------- 1 | @brand-primary: #de8579; -------------------------------------------------------------------------------- /Chapter05/security-service/src/main/wro/wro.properties: -------------------------------------------------------------------------------- 1 | #List of preProcessors 2 | preProcessors=lessCssImport 3 | #List of postProcessors 4 | postProcessors=less4j,jsMin -------------------------------------------------------------------------------- /Chapter05/security-service/src/main/wro/wro.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | webjar:bootstrap/3.2.0/less/bootstrap.less 4 | file:${project.basedir}/src/main/wro/main.less 5 | webjar:jquery/2.1.1/jquery.min.js 6 | 7 | -------------------------------------------------------------------------------- /Chapter05/turbine-server/nbactions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CUSTOM-clean package 5 | clean package 6 | 7 | clean 8 | package 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Chapter05/turbine-server/src/main/java/com/packtpub/mmj/turbine/server/TurbineApp.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.turbine.server; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; 6 | import org.springframework.amqp.rabbit.connection.ConnectionFactory; 7 | import org.springframework.beans.factory.annotation.Value; 8 | import org.springframework.boot.SpringApplication; 9 | import org.springframework.boot.autoconfigure.SpringBootApplication; 10 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 11 | import org.springframework.cloud.netflix.turbine.stream.EnableTurbineStream; 12 | import org.springframework.context.annotation.Bean; 13 | 14 | @SpringBootApplication 15 | @EnableTurbineStream 16 | @EnableEurekaClient 17 | public class TurbineApp { 18 | 19 | private static final Logger LOG = LoggerFactory.getLogger(TurbineApp.class); 20 | @Value("${app.rabbitmq.host:localhost}") 21 | String rabbitMQHost; 22 | 23 | @Bean 24 | public ConnectionFactory connectionFactory() { 25 | LOG.info("Creating RabbitMQHost ConnectionFactory for host: {}", rabbitMQHost); 26 | CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(rabbitMQHost); 27 | return cachingConnectionFactory; 28 | } 29 | 30 | public static void main(String[] args) { 31 | SpringApplication.run(TurbineApp.class, args); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Chapter05/turbine-server/src/main/resources/applicaton.yml: -------------------------------------------------------------------------------- 1 | info: 2 | component: Turbine Server 3 | 4 | server: 5 | port: 8989 6 | 7 | management: 8 | port: 8990 9 | 10 | turbine: 11 | aggregator: 12 | clusterConfig: USER-SERVICE,RESTAURANT-SERVICE 13 | # clusterNameExpression: new String("default") 14 | appConfig: user-service,restaurant-service 15 | # clusterNameExpression: 'default' 16 | # InstanceMonitor: 17 | # eventStream: 18 | # skipLineLogic: false 19 | 20 | eureka: 21 | instance: 22 | leaseRenewalIntervalInSeconds: 10 23 | metadataMap: 24 | instanceId: ${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${random.value}}} 25 | client: 26 | serviceUrl: 27 | defaultZone: ${vcap.services.${PREFIX:}eureka.credentials.uri:http://user:password@localhost:8761}/eureka/ 28 | #http://localhost:8761/eureka/ 29 | fetchRegistry: true 30 | 31 | logging: 32 | level: 33 | root: INFO 34 | com.netflix.discovery: 'OFF' 35 | org.springframework.integration: DEBUG 36 | -------------------------------------------------------------------------------- /Chapter05/user-service/nbactions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CUSTOM-clean and package 5 | clean and package 6 | 7 | clean 8 | package 9 | 10 | 11 | 12 | CUSTOM-docker:build 13 | docker:build 14 | 15 | docker:build 16 | 17 | 18 | 19 | CUSTOM-docker-start 20 | docker-start 21 | 22 | docker:start 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Chapter05/user-service/src/main/docker/docker-assembly.xml: -------------------------------------------------------------------------------- 1 | 5 | ${project.artifactId} 6 | 7 | 8 | target/${project.build.finalName}.jar 9 | / 10 | 11 | 12 | src/main/resources/docker-config.yml 13 | / 14 | 15 | 16 | -------------------------------------------------------------------------------- /Chapter05/user-service/src/main/java/com/packtpub/mmj/user/UsersApp.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.user; 2 | 3 | import com.rabbitmq.client.ConnectionFactory; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; 7 | import org.springframework.beans.factory.annotation.Value; 8 | import org.springframework.boot.SpringApplication; 9 | import org.springframework.boot.autoconfigure.SpringBootApplication; 10 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; 11 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 12 | import org.springframework.context.annotation.Bean; 13 | import org.springframework.context.annotation.ComponentScan; 14 | 15 | @SpringBootApplication 16 | @EnableEurekaClient 17 | @EnableCircuitBreaker 18 | @ComponentScan({"com.packtpub.mmj.user", "com.packtpub.mmj.common"}) 19 | public class UsersApp { 20 | 21 | private static final Logger LOG = LoggerFactory.getLogger(UsersApp.class); 22 | 23 | @Value("${app.rabbitmq.host:localhost}") 24 | String rabbitMqHost; 25 | 26 | @Bean 27 | public ConnectionFactory connectionFactory() { 28 | LOG.info("Create RabbitMqCF for host: {}", rabbitMqHost); 29 | CachingConnectionFactory connectionFactory = new CachingConnectionFactory(rabbitMqHost); 30 | return connectionFactory.getRabbitConnectionFactory(); 31 | } 32 | 33 | public static void main(String[] args) { 34 | SpringApplication.run(UsersApp.class, args); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Chapter05/user-service/src/main/java/com/packtpub/mmj/user/domain/model/entity/BaseEntity.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.user.domain.model.entity; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | * @param 7 | */ 8 | public abstract class BaseEntity extends Entity { 9 | 10 | private boolean isModified; 11 | 12 | /** 13 | * 14 | * @param id 15 | * @param name 16 | */ 17 | public BaseEntity(T id, String name) { 18 | super.id = id; 19 | super.name = name; 20 | isModified = false; 21 | } 22 | 23 | /** 24 | * 25 | * @return 26 | */ 27 | public boolean isIsModified() { 28 | return isModified; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Chapter05/user-service/src/main/java/com/packtpub/mmj/user/domain/model/entity/Entity.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.user.domain.model.entity; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | * @param 7 | */ 8 | public abstract class Entity { 9 | 10 | T id; 11 | String name; 12 | 13 | /** 14 | * 15 | * @return 16 | */ 17 | public T getId() { 18 | return id; 19 | } 20 | 21 | /** 22 | * 23 | * @param id 24 | */ 25 | public void setId(T id) { 26 | this.id = id; 27 | } 28 | 29 | /** 30 | * 31 | * @return 32 | */ 33 | public String getName() { 34 | return name; 35 | } 36 | 37 | /** 38 | * 39 | * @param name 40 | */ 41 | public void setName(String name) { 42 | this.name = name; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /Chapter05/user-service/src/main/java/com/packtpub/mmj/user/domain/repository/ReadOnlyRepository.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.user.domain.repository; 2 | 3 | import java.util.Collection; 4 | 5 | /** 6 | * 7 | * @author Sourabh Sharma 8 | * @param 9 | * @param 10 | */ 11 | public interface ReadOnlyRepository { 12 | 13 | //long Count; 14 | /** 15 | * 16 | * @param id 17 | * @return 18 | */ 19 | boolean contains(T id); 20 | 21 | /** 22 | * 23 | * @param id 24 | * @return 25 | */ 26 | TE get(T id); 27 | 28 | /** 29 | * 30 | * @return 31 | */ 32 | Collection getAll(); 33 | } 34 | -------------------------------------------------------------------------------- /Chapter05/user-service/src/main/java/com/packtpub/mmj/user/domain/repository/Repository.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.user.domain.repository; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | * @param 7 | * @param 8 | */ 9 | public interface Repository extends ReadOnlyRepository { 10 | 11 | /** 12 | * 13 | * @param entity 14 | */ 15 | void add(TE entity); 16 | 17 | /** 18 | * 19 | * @param id 20 | */ 21 | void remove(T id); 22 | 23 | /** 24 | * 25 | * @param entity 26 | */ 27 | void update(TE entity); 28 | } 29 | -------------------------------------------------------------------------------- /Chapter05/user-service/src/main/java/com/packtpub/mmj/user/domain/repository/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.user.domain.repository; 2 | 3 | import java.util.Collection; 4 | 5 | /** 6 | * 7 | * @author Sourabh Sharma 8 | * @param 9 | * @param 10 | */ 11 | public interface UserRepository extends Repository { 12 | 13 | /** 14 | * 15 | * @param name 16 | * @return 17 | */ 18 | boolean containsName(String name); 19 | 20 | /** 21 | * 22 | * @param name 23 | * @return 24 | * @throws Exception 25 | */ 26 | public Collection findByName(String name) throws Exception; 27 | } 28 | -------------------------------------------------------------------------------- /Chapter05/user-service/src/main/java/com/packtpub/mmj/user/domain/service/BaseService.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.user.domain.service; 2 | 3 | import com.packtpub.mmj.user.domain.repository.Repository; 4 | import java.util.Collection; 5 | 6 | /** 7 | * 8 | * @author Sourabh Sharma 9 | * @param 10 | * @param 11 | */ 12 | public abstract class BaseService extends ReadOnlyBaseService { 13 | 14 | private Repository _repository; 15 | 16 | BaseService(Repository repository) { 17 | super(repository); 18 | _repository = repository; 19 | } 20 | 21 | /** 22 | * 23 | * @param entity 24 | * @throws Exception 25 | */ 26 | public void add(TE entity) throws Exception { 27 | _repository.add(entity); 28 | } 29 | 30 | /** 31 | * 32 | * @return 33 | */ 34 | public Collection getAll() { 35 | return _repository.getAll(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Chapter05/user-service/src/main/java/com/packtpub/mmj/user/domain/service/ReadOnlyBaseService.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.user.domain.service; 2 | 3 | import com.packtpub.mmj.user.domain.repository.ReadOnlyRepository; 4 | 5 | /** 6 | * 7 | * @author Sourabh Sharma 8 | * @param 9 | * @param 10 | */ 11 | public abstract class ReadOnlyBaseService { 12 | 13 | private ReadOnlyRepository repository; 14 | 15 | ReadOnlyBaseService(ReadOnlyRepository repository) { 16 | this.repository = repository; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter05/user-service/src/main/java/com/packtpub/mmj/user/domain/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.user.domain.service; 2 | 3 | import com.packtpub.mmj.user.domain.model.entity.User; 4 | import com.packtpub.mmj.user.domain.model.entity.Entity; 5 | import java.util.ArrayList; 6 | import java.util.Collection; 7 | import java.util.Map; 8 | 9 | /** 10 | * 11 | * @author Sourabh Sharma 12 | */ 13 | public interface UserService { 14 | 15 | /** 16 | * 17 | * @param booking 18 | * @throws Exception 19 | */ 20 | public void add(User booking) throws Exception; 21 | 22 | /** 23 | * 24 | * @param booking 25 | * @throws Exception 26 | */ 27 | public void update(User booking) throws Exception; 28 | 29 | /** 30 | * 31 | * @param id 32 | * @throws Exception 33 | */ 34 | public void delete(String id) throws Exception; 35 | 36 | /** 37 | * 38 | * @param restaurantId 39 | * @return 40 | * @throws Exception 41 | */ 42 | public Entity findById(String restaurantId) throws Exception; 43 | 44 | /** 45 | * 46 | * @param name 47 | * @return 48 | * @throws Exception 49 | */ 50 | public Collection findByName(String name) throws Exception; 51 | 52 | /** 53 | * 54 | * @param name 55 | * @return 56 | * @throws Exception 57 | */ 58 | public Collection findByCriteria(Map> name) throws Exception; 59 | } 60 | -------------------------------------------------------------------------------- /Chapter05/user-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | # Spring properties 2 | spring: 3 | application: 4 | name: user-service 5 | # Added to fix - java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut hystrixCommandAnnotationPointcut 6 | aop: 7 | auto: false 8 | 9 | # HTTP Server 10 | server: 11 | port: 7770 12 | 13 | # Discovery Server Access 14 | eureka: 15 | instance: 16 | leaseRenewalIntervalInSeconds: 3 17 | metadataMap: 18 | instanceId: ${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${random.value}}} 19 | 20 | client: 21 | registryFetchIntervalSeconds: 5 22 | instanceInfoReplicationIntervalSeconds: 5 23 | initialInstanceInfoReplicationIntervalSeconds: 5 24 | serviceUrl: 25 | defaultZone: ${vcap.services.${PREFIX:}eureka.credentials.uri:http://user:password@localhost:8761}/eureka/ 26 | fetchRegistry: true 27 | 28 | logging: 29 | level: 30 | root: INFO 31 | com.netflix.hystrix: INFO 32 | 33 | 34 | --- 35 | # For deployment in Docker containers 36 | spring: 37 | profiles: docker 38 | 39 | server: 40 | port: 8080 41 | 42 | eureka: 43 | instance: 44 | preferIpAddress: true 45 | client: 46 | serviceUrl: 47 | defaultZone: http://eureka:8761/eureka/ 48 | -------------------------------------------------------------------------------- /Chapter05/user-service/src/main/resources/docker-config.yml: -------------------------------------------------------------------------------- 1 | FROM java:8-jre 2 | MAINTAINER sourabhh 3 | EXPOSE 8080 4 | COPY maven /maven/ 5 | CMD java -Dspring.profiles.active="docker" -jar \ 6 | /maven/user-service.jar server \ 7 | /maven/docker-config.yml -------------------------------------------------------------------------------- /Chapter05/user-service/src/test/java/com/packtpub/mmj/user/resources/docker/DockerIntegrationTest.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.user.resources.docker; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | */ 7 | public interface DockerIntegrationTest { 8 | // Marker for Docker integratino Tests 9 | } 10 | -------------------------------------------------------------------------------- /Chapter05/user-service/src/test/java/com/packtpub/mmj/user/resources/docker/UserAppDockerIT.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.user.resources.docker; 2 | 3 | import java.io.IOException; 4 | import java.net.HttpURLConnection; 5 | import java.net.URL; 6 | import static org.junit.Assert.assertEquals; 7 | import org.junit.Test; 8 | import org.junit.experimental.categories.Category; 9 | import static org.junit.Assert.assertEquals; 10 | 11 | /** 12 | * 13 | * @author Sourabh Sharma 14 | */ 15 | @Category(DockerIntegrationTest.class) 16 | public class UserAppDockerIT { 17 | 18 | @Test 19 | public void testConnection() throws IOException { 20 | String baseUrl = System.getProperty("service.url"); 21 | URL serviceUrl = new URL(baseUrl + "v1/restaurants/1"); 22 | HttpURLConnection connection = (HttpURLConnection) serviceUrl.openConnection(); 23 | int responseCode = connection.getResponseCode(); 24 | assertEquals(200, responseCode); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Chapter05/user-service/src/test/resources/application.yml: -------------------------------------------------------------------------------- 1 | # Spring properties 2 | spring: 3 | cloud: 4 | discovery: 5 | enabled: false 6 | aop: 7 | auto: false 8 | # config: 9 | # enabled: false 10 | # server: 11 | # health: 12 | # enabled: false 13 | # 14 | #hystrix: 15 | # command: 16 | # default: 17 | # circuitBreaker: 18 | # enabled: false 19 | # fallback: 20 | # enabled: false -------------------------------------------------------------------------------- /Chapter05/zuul-server/nbactions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CUSTOM-clean package 5 | clean package 6 | 7 | clean 8 | package 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Chapter05/zuul-server/src/main/resources/keystore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Mastering-Microservices-with-Java-9-Second-Edition/73136020a45456bd99d377051d1ae3401f56a10d/Chapter05/zuul-server/src/main/resources/keystore.jks -------------------------------------------------------------------------------- /Chapter06/billing-service/nbactions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CUSTOM-clean and package 5 | clean and package 6 | 7 | clean 8 | package 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Chapter06/billing-service/src/main/java/com/packtpub/mmj/billing/BillingApp.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.billing; 2 | 3 | import com.packtpub.mmj.billing.domain.message.BillingMessageChannels; 4 | import com.packtpub.mmj.billing.domain.message.EventListener; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.cloud.stream.annotation.EnableBinding; 8 | import org.springframework.context.annotation.Bean; 9 | 10 | /** 11 | * 12 | * @author Sourabh Sharma 13 | */ 14 | @SpringBootApplication(scanBasePackages = {"com.packtpub.mmj.billing", "com.packtpub.mmj.booking"}) 15 | @EnableBinding({BillingMessageChannels.class}) 16 | public class BillingApp { 17 | 18 | public static void main(String[] args) { 19 | SpringApplication.run(BillingApp.class, args); 20 | } 21 | 22 | @Bean 23 | public EventListener eventListener() { 24 | return new EventListener(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Chapter06/billing-service/src/main/java/com/packtpub/mmj/billing/domain/message/BillingMessageChannels.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.billing.domain.message; 2 | 3 | import org.springframework.cloud.stream.annotation.Input; 4 | import org.springframework.messaging.MessageChannel; 5 | 6 | public interface BillingMessageChannels { 7 | 8 | public final static String BOOKING_ORDER_INPUT = "bookingOrderInput"; 9 | 10 | @Input(BOOKING_ORDER_INPUT) 11 | MessageChannel bookingOrderInput(); 12 | } 13 | -------------------------------------------------------------------------------- /Chapter06/billing-service/src/main/java/com/packtpub/mmj/billing/domain/message/EventListener.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.billing.domain.message; 2 | 3 | import com.packtpub.mmj.booking.domain.valueobject.avro.BookingOrder; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.cloud.stream.annotation.StreamListener; 7 | 8 | public class EventListener { 9 | 10 | private static final Logger LOG = LoggerFactory.getLogger(EventListener.class); 11 | 12 | @StreamListener(BillingMessageChannels.BOOKING_ORDER_INPUT) 13 | public void consumeBookingOrder(BookingOrder bookingOrder) { 14 | LOG.info("Received BookingOrder: {}", bookingOrder); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Chapter06/billing-service/src/main/java/com/packtpub/mmj/billing/domain/model/entity/BaseEntity.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.billing.domain.model.entity; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | * @param 7 | */ 8 | public abstract class BaseEntity extends Entity { 9 | 10 | private boolean isModified; 11 | 12 | /** 13 | * 14 | * @param id 15 | * @param name 16 | */ 17 | public BaseEntity(T id, String name) { 18 | super.id = id; 19 | super.name = name; 20 | isModified = false; 21 | } 22 | 23 | /** 24 | * 25 | * @return 26 | */ 27 | public boolean isIsModified() { 28 | return isModified; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Chapter06/billing-service/src/main/java/com/packtpub/mmj/billing/domain/model/entity/Entity.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.billing.domain.model.entity; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | * @param 7 | */ 8 | public abstract class Entity { 9 | 10 | T id; 11 | String name; 12 | 13 | /** 14 | * 15 | * @return 16 | */ 17 | public T getId() { 18 | return id; 19 | } 20 | 21 | /** 22 | * 23 | * @param id 24 | */ 25 | public void setId(T id) { 26 | this.id = id; 27 | } 28 | 29 | /** 30 | * 31 | * @return 32 | */ 33 | public String getName() { 34 | return name; 35 | } 36 | 37 | /** 38 | * 39 | * @param name 40 | */ 41 | public void setName(String name) { 42 | this.name = name; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /Chapter06/billing-service/src/main/java/com/packtpub/mmj/billing/domain/repository/BookingRepository.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.billing.domain.repository; 2 | 3 | import java.util.Collection; 4 | 5 | /** 6 | * 7 | * @author Sourabh Sharma 8 | * @param 9 | * @param 10 | */ 11 | public interface BookingRepository extends Repository { 12 | 13 | /** 14 | * 15 | * @param name 16 | * @return 17 | */ 18 | boolean containsName(String name); 19 | 20 | /** 21 | * 22 | * @param name 23 | * @return 24 | * @throws Exception 25 | */ 26 | public Collection findByName(String name) throws Exception; 27 | } 28 | -------------------------------------------------------------------------------- /Chapter06/billing-service/src/main/java/com/packtpub/mmj/billing/domain/repository/ReadOnlyRepository.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.billing.domain.repository; 2 | 3 | import java.util.Collection; 4 | 5 | /** 6 | * 7 | * @author Sourabh Sharma 8 | * @param 9 | * @param 10 | */ 11 | public interface ReadOnlyRepository { 12 | 13 | //long Count; 14 | /** 15 | * 16 | * @param id 17 | * @return 18 | */ 19 | boolean contains(T id); 20 | 21 | /** 22 | * 23 | * @param id 24 | * @return 25 | */ 26 | TE get(T id); 27 | 28 | /** 29 | * 30 | * @return 31 | */ 32 | Collection getAll(); 33 | } 34 | -------------------------------------------------------------------------------- /Chapter06/billing-service/src/main/java/com/packtpub/mmj/billing/domain/repository/Repository.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.billing.domain.repository; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | * @param 7 | * @param 8 | */ 9 | public interface Repository extends ReadOnlyRepository { 10 | 11 | /** 12 | * 13 | * @param entity 14 | */ 15 | void add(TE entity); 16 | 17 | /** 18 | * 19 | * @param id 20 | */ 21 | void remove(T id); 22 | 23 | /** 24 | * 25 | * @param entity 26 | */ 27 | void update(TE entity); 28 | } 29 | -------------------------------------------------------------------------------- /Chapter06/billing-service/src/main/java/com/packtpub/mmj/billing/domain/service/BaseService.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.billing.domain.service; 2 | 3 | import com.packtpub.mmj.billing.domain.repository.Repository; 4 | import java.util.Collection; 5 | 6 | /** 7 | * 8 | * @author Sourabh Sharma 9 | * @param 10 | * @param 11 | */ 12 | public abstract class BaseService extends ReadOnlyBaseService { 13 | 14 | private Repository _repository; 15 | 16 | BaseService(Repository repository) { 17 | super(repository); 18 | _repository = repository; 19 | } 20 | 21 | /** 22 | * 23 | * @param entity 24 | * @throws Exception 25 | */ 26 | public void add(TE entity) throws Exception { 27 | _repository.add(entity); 28 | } 29 | 30 | /** 31 | * 32 | * @return 33 | */ 34 | public Collection getAll() { 35 | return _repository.getAll(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Chapter06/billing-service/src/main/java/com/packtpub/mmj/billing/domain/service/BookingService.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.billing.domain.service; 2 | 3 | import com.packtpub.mmj.billing.domain.model.entity.Booking; 4 | import com.packtpub.mmj.billing.domain.model.entity.Entity; 5 | import java.util.ArrayList; 6 | import java.util.Collection; 7 | import java.util.Map; 8 | 9 | /** 10 | * 11 | * @author Sourabh Sharma 12 | */ 13 | public interface BookingService { 14 | 15 | /** 16 | * 17 | * @param booking 18 | * @throws Exception 19 | */ 20 | public void add(Booking booking) throws Exception; 21 | 22 | /** 23 | * 24 | * @param booking 25 | * @throws Exception 26 | */ 27 | public void update(Booking booking) throws Exception; 28 | 29 | /** 30 | * 31 | * @param id 32 | * @throws Exception 33 | */ 34 | public void delete(String id) throws Exception; 35 | 36 | /** 37 | * 38 | * @param id 39 | * @return 40 | * @throws Exception 41 | */ 42 | public Entity findById(String id) throws Exception; 43 | 44 | /** 45 | * 46 | * @param name 47 | * @return 48 | * @throws Exception 49 | */ 50 | public Collection findByName(String name) throws Exception; 51 | 52 | /** 53 | * 54 | * @param name 55 | * @return 56 | * @throws Exception 57 | */ 58 | public Collection findByCriteria(Map> name) throws Exception; 59 | } 60 | -------------------------------------------------------------------------------- /Chapter06/billing-service/src/main/java/com/packtpub/mmj/billing/domain/service/ReadOnlyBaseService.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.billing.domain.service; 2 | 3 | import com.packtpub.mmj.billing.domain.repository.ReadOnlyRepository; 4 | 5 | /** 6 | * 7 | * @author Sourabh Sharma 8 | * @param 9 | * @param 10 | */ 11 | public abstract class ReadOnlyBaseService { 12 | 13 | private ReadOnlyRepository repository; 14 | 15 | ReadOnlyBaseService(ReadOnlyRepository repository) { 16 | this.repository = repository; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter06/billing-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | # Spring properties 2 | spring: 3 | application: 4 | name: booking-service # Service registers under this name 5 | # Added to fix - java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut hystrixCommandAnnotationPointcut 6 | aop: 7 | auto: false 8 | cloud: 9 | stream: 10 | bindings: 11 | bookingOrderInput: 12 | destination: amp.bookingOrdered 13 | consumer: 14 | resetOffsets: true 15 | group: 16 | ${bookingConsumerGroup} 17 | tweetInput: 18 | destination: tweet 19 | consumer: 20 | resetOffsets: true 21 | group: 22 | ${bookingConsumerGroup} 23 | kafka: 24 | binder: 25 | zkNodes: localhost 26 | binder: 27 | brokers: localhost 28 | 29 | bookingConsumerGroup: "booking-service" 30 | 31 | # HTTP Server 32 | server: 33 | port: 7051 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /Chapter06/billing-service/src/main/resources/avro/bookingOrder.avsc: -------------------------------------------------------------------------------- 1 | {"namespace": "com.packtpub.mmj.booking.domain.valueobject.avro", 2 | "type": "record", 3 | "name": "BookingOrder", 4 | "fields": [ 5 | {"name": "id", "type": "string"}, 6 | {"name": "name", "type": "string", "default": ""}, 7 | {"name": "userId", "type": "string", "default": ""}, 8 | {"name": "restaurantId", "type": "string", "default": ""}, 9 | {"name": "tableId", "type": "string", "default": ""}, 10 | {"name": "date", "type": ["null", "string"], "default": null}, 11 | {"name": "time", "type": ["null", "string"], "default": null} 12 | ] 13 | } -------------------------------------------------------------------------------- /Chapter06/billing-service/src/test/resources/application.yml: -------------------------------------------------------------------------------- 1 | # Spring properties 2 | spring: 3 | cloud: 4 | discovery: 5 | enabled: false 6 | aop: 7 | auto: false 8 | # config: 9 | # enabled: false 10 | # server: 11 | # health: 12 | # enabled: false 13 | # 14 | #hystrix: 15 | # command: 16 | # default: 17 | # circuitBreaker: 18 | # enabled: false 19 | # fallback: 20 | # enabled: false -------------------------------------------------------------------------------- /Chapter06/booking-service/nbactions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CUSTOM-clean and package 5 | clean and package 6 | 7 | clean 8 | package 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Chapter06/booking-service/src/main/java/com/packtpub/mmj/booking/BookingApp.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.booking; 2 | 3 | import java.io.IOException; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.boot.SpringApplication; 7 | import org.springframework.boot.autoconfigure.SpringBootApplication; 8 | import org.springframework.cloud.stream.schema.avro.AvroSchemaMessageConverter; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.core.io.ClassPathResource; 11 | import org.springframework.messaging.converter.MessageConverter; 12 | import org.springframework.util.MimeType; 13 | 14 | @SpringBootApplication 15 | public class BookingApp { 16 | 17 | private static final Logger LOG = LoggerFactory.getLogger(BookingApp.class); 18 | 19 | public static void main(String[] args) { 20 | SpringApplication.run(BookingApp.class, args); 21 | } 22 | 23 | @Bean 24 | public MessageConverter bookingOrderMessageConverter() throws IOException { 25 | LOG.info("avro message converter bean initialized."); 26 | AvroSchemaMessageConverter avroSchemaMessageConverter = new AvroSchemaMessageConverter(MimeType.valueOf("application/bookingOrder.v1+avro")); 27 | avroSchemaMessageConverter.setSchemaLocation(new ClassPathResource("avro/bookingOrder.avsc")); 28 | return avroSchemaMessageConverter; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Chapter06/booking-service/src/main/java/com/packtpub/mmj/booking/domain/message/BookingMessageChannels.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.booking.domain.message; 2 | 3 | import org.springframework.cloud.stream.annotation.Output; 4 | import org.springframework.messaging.MessageChannel; 5 | 6 | public interface BookingMessageChannels { 7 | 8 | public final static String BOOKING_ORDER_OUTPUT = "bookingOrderOutput"; 9 | 10 | @Output(BOOKING_ORDER_OUTPUT) 11 | MessageChannel bookingOrderOutput(); 12 | } 13 | -------------------------------------------------------------------------------- /Chapter06/booking-service/src/main/java/com/packtpub/mmj/booking/domain/model/entity/BaseEntity.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.booking.domain.model.entity; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | * @param 7 | */ 8 | public abstract class BaseEntity extends Entity { 9 | 10 | private boolean isModified; 11 | 12 | /** 13 | * 14 | * @param id 15 | * @param name 16 | */ 17 | public BaseEntity(T id, String name) { 18 | super.id = id; 19 | super.name = name; 20 | isModified = false; 21 | } 22 | 23 | /** 24 | * 25 | * @return 26 | */ 27 | public boolean isIsModified() { 28 | return isModified; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Chapter06/booking-service/src/main/java/com/packtpub/mmj/booking/domain/model/entity/Entity.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.booking.domain.model.entity; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | * @param 7 | */ 8 | public abstract class Entity { 9 | 10 | T id; 11 | String name; 12 | 13 | /** 14 | * 15 | * @return 16 | */ 17 | public T getId() { 18 | return id; 19 | } 20 | 21 | /** 22 | * 23 | * @param id 24 | */ 25 | public void setId(T id) { 26 | this.id = id; 27 | } 28 | 29 | /** 30 | * 31 | * @return 32 | */ 33 | public String getName() { 34 | return name; 35 | } 36 | 37 | /** 38 | * 39 | * @param name 40 | */ 41 | public void setName(String name) { 42 | this.name = name; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /Chapter06/booking-service/src/main/java/com/packtpub/mmj/booking/domain/repository/BookingRepository.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.booking.domain.repository; 2 | 3 | import java.util.Collection; 4 | 5 | /** 6 | * 7 | * @author Sourabh Sharma 8 | * @param 9 | * @param 10 | */ 11 | public interface BookingRepository extends Repository { 12 | 13 | /** 14 | * 15 | * @param name 16 | * @return 17 | */ 18 | boolean containsName(String name); 19 | 20 | /** 21 | * 22 | * @param name 23 | * @return 24 | * @throws Exception 25 | */ 26 | public Collection findByName(String name) throws Exception; 27 | } 28 | -------------------------------------------------------------------------------- /Chapter06/booking-service/src/main/java/com/packtpub/mmj/booking/domain/repository/ReadOnlyRepository.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.booking.domain.repository; 2 | 3 | import java.util.Collection; 4 | 5 | /** 6 | * 7 | * @author Sourabh Sharma 8 | * @param 9 | * @param 10 | */ 11 | public interface ReadOnlyRepository { 12 | 13 | //long Count; 14 | /** 15 | * 16 | * @param id 17 | * @return 18 | */ 19 | boolean contains(T id); 20 | 21 | /** 22 | * 23 | * @param id 24 | * @return 25 | */ 26 | TE get(T id); 27 | 28 | /** 29 | * 30 | * @return 31 | */ 32 | Collection getAll(); 33 | } 34 | -------------------------------------------------------------------------------- /Chapter06/booking-service/src/main/java/com/packtpub/mmj/booking/domain/repository/Repository.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.booking.domain.repository; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | * @param 7 | * @param 8 | */ 9 | public interface Repository extends ReadOnlyRepository { 10 | 11 | /** 12 | * 13 | * @param entity 14 | */ 15 | void add(TE entity); 16 | 17 | /** 18 | * 19 | * @param id 20 | */ 21 | void remove(T id); 22 | 23 | /** 24 | * 25 | * @param entity 26 | */ 27 | void update(TE entity); 28 | } 29 | -------------------------------------------------------------------------------- /Chapter06/booking-service/src/main/java/com/packtpub/mmj/booking/domain/service/BaseService.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.booking.domain.service; 2 | 3 | import com.packtpub.mmj.booking.domain.repository.Repository; 4 | import java.util.Collection; 5 | 6 | /** 7 | * 8 | * @author Sourabh Sharma 9 | * @param 10 | * @param 11 | */ 12 | public abstract class BaseService extends ReadOnlyBaseService { 13 | 14 | private Repository _repository; 15 | 16 | BaseService(Repository repository) { 17 | super(repository); 18 | _repository = repository; 19 | } 20 | 21 | /** 22 | * 23 | * @param entity 24 | * @throws Exception 25 | */ 26 | public void add(TE entity) throws Exception { 27 | _repository.add(entity); 28 | } 29 | 30 | /** 31 | * 32 | * @return 33 | */ 34 | public Collection getAll() { 35 | return _repository.getAll(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Chapter06/booking-service/src/main/java/com/packtpub/mmj/booking/domain/service/ReadOnlyBaseService.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.booking.domain.service; 2 | 3 | import com.packtpub.mmj.booking.domain.repository.ReadOnlyRepository; 4 | 5 | /** 6 | * 7 | * @author Sourabh Sharma 8 | * @param 9 | * @param 10 | */ 11 | public abstract class ReadOnlyBaseService { 12 | 13 | private ReadOnlyRepository repository; 14 | 15 | ReadOnlyBaseService(ReadOnlyRepository repository) { 16 | this.repository = repository; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter06/booking-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | # Spring properties 2 | spring: 3 | application: 4 | name: booking-service # Service registers under this name 5 | # Added to fix - java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut hystrixCommandAnnotationPointcut 6 | aop: 7 | auto: false 8 | 9 | cloud: 10 | stream: 11 | bindings: 12 | bookingOrderOutput: 13 | destination: amp.bookingOrdered 14 | tweetOutput: 15 | destination: tweet 16 | # content-type: application/*+avro 17 | kafka: 18 | binder: 19 | zkNodes: localhost 20 | binder: 21 | brokers: localhost 22 | 23 | # HTTP Server 24 | server: 25 | port: 7052 -------------------------------------------------------------------------------- /Chapter06/booking-service/src/main/resources/avro/bookingOrder.avsc: -------------------------------------------------------------------------------- 1 | {"namespace": "com.packtpub.mmj.booking.domain.valueobject.avro", 2 | "type": "record", 3 | "name": "BookingOrder", 4 | "fields": [ 5 | {"name": "id", "type": "string"}, 6 | {"name": "name", "type": "string", "default": ""}, 7 | {"name": "userId", "type": "string", "default": ""}, 8 | {"name": "restaurantId", "type": "string", "default": ""}, 9 | {"name": "tableId", "type": "string", "default": ""}, 10 | {"name": "date", "type": ["null", "string"], "default": null}, 11 | {"name": "time", "type": ["null", "string"], "default": null} 12 | ] 13 | } -------------------------------------------------------------------------------- /Chapter06/booking-service/src/test/resources/application.yml: -------------------------------------------------------------------------------- 1 | # Spring properties 2 | spring: 3 | cloud: 4 | discovery: 5 | enabled: false 6 | aop: 7 | auto: false 8 | -------------------------------------------------------------------------------- /Chapter06/nbactions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CUSTOM-clean and package 5 | clean and package 6 | 7 | clean 8 | package 9 | 10 | 11 | 12 | CUSTOM-install 13 | install 14 | 15 | install 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Chapter07/api-service/nbactions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CUSTOM-package 5 | clean and package 6 | 7 | clean 8 | package 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Chapter07/booking-service/nbactions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CUSTOM-clean and package 5 | clean and package 6 | 7 | clean 8 | package 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Chapter07/booking-service/src/main/java/com/packtpub/mmj/booking/BookingApp.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.booking; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | 7 | /** 8 | * 9 | * @author Sourabh Sharma 10 | */ 11 | @SpringBootApplication 12 | @EnableEurekaClient 13 | public class BookingApp { 14 | 15 | /** 16 | * 17 | * @param args 18 | */ 19 | public static void main(String[] args) { 20 | SpringApplication.run(BookingApp.class, args); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /Chapter07/booking-service/src/main/java/com/packtpub/mmj/booking/domain/model/entity/BaseEntity.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.booking.domain.model.entity; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | * @param 7 | */ 8 | public abstract class BaseEntity extends Entity { 9 | 10 | private boolean isModified; 11 | 12 | /** 13 | * 14 | * @param id 15 | * @param name 16 | */ 17 | public BaseEntity(T id, String name) { 18 | super.id = id; 19 | super.name = name; 20 | isModified = false; 21 | } 22 | 23 | /** 24 | * 25 | * @return 26 | */ 27 | public boolean isIsModified() { 28 | return isModified; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Chapter07/booking-service/src/main/java/com/packtpub/mmj/booking/domain/model/entity/Entity.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.booking.domain.model.entity; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | * @param 7 | */ 8 | public abstract class Entity { 9 | 10 | T id; 11 | String name; 12 | 13 | /** 14 | * 15 | * @return 16 | */ 17 | public T getId() { 18 | return id; 19 | } 20 | 21 | /** 22 | * 23 | * @param id 24 | */ 25 | public void setId(T id) { 26 | this.id = id; 27 | } 28 | 29 | /** 30 | * 31 | * @return 32 | */ 33 | public String getName() { 34 | return name; 35 | } 36 | 37 | /** 38 | * 39 | * @param name 40 | */ 41 | public void setName(String name) { 42 | this.name = name; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /Chapter07/booking-service/src/main/java/com/packtpub/mmj/booking/domain/repository/BookingRepository.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.booking.domain.repository; 2 | 3 | import java.util.Collection; 4 | 5 | /** 6 | * 7 | * @author Sourabh Sharma 8 | * @param 9 | * @param 10 | */ 11 | public interface BookingRepository extends Repository { 12 | 13 | /** 14 | * 15 | * @param name 16 | * @return 17 | */ 18 | boolean containsName(String name); 19 | 20 | /** 21 | * 22 | * @param name 23 | * @return 24 | * @throws Exception 25 | */ 26 | public Collection findByName(String name) throws Exception; 27 | } 28 | -------------------------------------------------------------------------------- /Chapter07/booking-service/src/main/java/com/packtpub/mmj/booking/domain/repository/ReadOnlyRepository.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.booking.domain.repository; 2 | 3 | import java.util.Collection; 4 | 5 | /** 6 | * 7 | * @author Sourabh Sharma 8 | * @param 9 | * @param 10 | */ 11 | public interface ReadOnlyRepository { 12 | 13 | //long Count; 14 | /** 15 | * 16 | * @param id 17 | * @return 18 | */ 19 | boolean contains(T id); 20 | 21 | /** 22 | * 23 | * @param id 24 | * @return 25 | */ 26 | TE get(T id); 27 | 28 | /** 29 | * 30 | * @return 31 | */ 32 | Collection getAll(); 33 | } 34 | -------------------------------------------------------------------------------- /Chapter07/booking-service/src/main/java/com/packtpub/mmj/booking/domain/repository/Repository.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.booking.domain.repository; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | * @param 7 | * @param 8 | */ 9 | public interface Repository extends ReadOnlyRepository { 10 | 11 | /** 12 | * 13 | * @param entity 14 | */ 15 | void add(TE entity); 16 | 17 | /** 18 | * 19 | * @param id 20 | */ 21 | void remove(T id); 22 | 23 | /** 24 | * 25 | * @param entity 26 | */ 27 | void update(TE entity); 28 | } 29 | -------------------------------------------------------------------------------- /Chapter07/booking-service/src/main/java/com/packtpub/mmj/booking/domain/service/BaseService.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.booking.domain.service; 2 | 3 | import com.packtpub.mmj.booking.domain.repository.Repository; 4 | import java.util.Collection; 5 | 6 | /** 7 | * 8 | * @author Sourabh Sharma 9 | * @param 10 | * @param 11 | */ 12 | public abstract class BaseService extends ReadOnlyBaseService { 13 | 14 | private Repository _repository; 15 | 16 | BaseService(Repository repository) { 17 | super(repository); 18 | _repository = repository; 19 | } 20 | 21 | /** 22 | * 23 | * @param entity 24 | * @throws Exception 25 | */ 26 | public void add(TE entity) throws Exception { 27 | _repository.add(entity); 28 | } 29 | 30 | /** 31 | * 32 | * @return 33 | */ 34 | public Collection getAll() { 35 | return _repository.getAll(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Chapter07/booking-service/src/main/java/com/packtpub/mmj/booking/domain/service/BookingService.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.booking.domain.service; 2 | 3 | import com.packtpub.mmj.booking.domain.model.entity.Booking; 4 | import com.packtpub.mmj.booking.domain.model.entity.Entity; 5 | import java.util.ArrayList; 6 | import java.util.Collection; 7 | import java.util.Map; 8 | 9 | /** 10 | * 11 | * @author Sourabh Sharma 12 | */ 13 | public interface BookingService { 14 | 15 | /** 16 | * 17 | * @param booking 18 | * @throws Exception 19 | */ 20 | public void add(Booking booking) throws Exception; 21 | 22 | /** 23 | * 24 | * @param booking 25 | * @throws Exception 26 | */ 27 | public void update(Booking booking) throws Exception; 28 | 29 | /** 30 | * 31 | * @param id 32 | * @throws Exception 33 | */ 34 | public void delete(String id) throws Exception; 35 | 36 | /** 37 | * 38 | * @param id 39 | * @return 40 | * @throws Exception 41 | */ 42 | public Entity findById(String id) throws Exception; 43 | 44 | /** 45 | * 46 | * @param name 47 | * @return 48 | * @throws Exception 49 | */ 50 | public Collection findByName(String name) throws Exception; 51 | 52 | /** 53 | * 54 | * @param name 55 | * @return 56 | * @throws Exception 57 | */ 58 | public Collection findByCriteria(Map> name) throws Exception; 59 | } 60 | -------------------------------------------------------------------------------- /Chapter07/booking-service/src/main/java/com/packtpub/mmj/booking/domain/service/ReadOnlyBaseService.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.booking.domain.service; 2 | 3 | import com.packtpub.mmj.booking.domain.repository.ReadOnlyRepository; 4 | 5 | /** 6 | * 7 | * @author Sourabh Sharma 8 | * @param 9 | * @param 10 | */ 11 | public abstract class ReadOnlyBaseService { 12 | 13 | private ReadOnlyRepository repository; 14 | 15 | ReadOnlyBaseService(ReadOnlyRepository repository) { 16 | this.repository = repository; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter07/booking-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | # Spring properties 2 | spring: 3 | application: 4 | name: booking-service # Service registers under this name 5 | # Added to fix - java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut hystrixCommandAnnotationPointcut 6 | aop: 7 | auto: false 8 | 9 | # Map the error path to error template (for Thymeleaf) 10 | error: 11 | path=/error 12 | 13 | # Discovery Server Access 14 | eureka: 15 | client: 16 | serviceUrl: 17 | defaultZone: http://localhost:8761/eureka/ 18 | 19 | # HTTP Server 20 | server: 21 | port: 0 # HTTP (Tomcat) port 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Chapter07/booking-service/src/test/resources/application.yml: -------------------------------------------------------------------------------- 1 | # Spring properties 2 | spring: 3 | cloud: 4 | discovery: 5 | enabled: false 6 | aop: 7 | auto: false 8 | # config: 9 | # enabled: false 10 | # server: 11 | # health: 12 | # enabled: false 13 | # 14 | #hystrix: 15 | # command: 16 | # default: 17 | # circuitBreaker: 18 | # enabled: false 19 | # fallback: 20 | # enabled: false -------------------------------------------------------------------------------- /Chapter07/common/nbactions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CUSTOM-clean package 5 | clean package 6 | 7 | clean 8 | package 9 | 10 | 11 | 12 | CUSTOM-install 13 | install 14 | 15 | clean 16 | install 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Chapter07/common/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | com.packtpub.mmj 6 | 6392_chapter7 7 | MMJ-ED2-SNAPSHOT 8 | 9 | online-table-reservation-common 10 | jar 11 | online-table-reservation:common 12 | 13 | 14 | org.springframework.cloud 15 | spring-cloud-starter-hystrix 16 | 17 | 18 | org.springframework.boot 19 | spring-boot-starter-web 20 | 21 | 22 | 23 | 1.8 24 | 1.8 25 | 26 | 27 | -------------------------------------------------------------------------------- /Chapter07/common/src/main/java/com/packtpub/mmj/common/MDCConcurrentCallable.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.common; 2 | 3 | import java.util.Map; 4 | import java.util.concurrent.Callable; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.slf4j.MDC; 8 | 9 | public class MDCConcurrentCallable implements Callable { 10 | 11 | private static final Logger LOG = LoggerFactory.getLogger(MDCConcurrentCallable.class); 12 | 13 | private final Callable actual; 14 | private final Map parentMDC; 15 | 16 | public MDCConcurrentCallable(Callable actual) { 17 | LOG.debug("Init MDCHystrixContextCallable..."); 18 | this.actual = actual; 19 | this.parentMDC = MDC.getCopyOfContextMap(); 20 | LOG.debug("actual --> " + actual); 21 | LOG.debug("this.parentMDC --> " + this.parentMDC); 22 | } 23 | 24 | @Override 25 | public K call() throws Exception { 26 | LOG.debug("Call using MDCHystrixContextCallable..."); 27 | Map childMDC = MDC.getCopyOfContextMap(); 28 | LOG.debug("childMDC --> " + childMDC); 29 | try { 30 | if (parentMDC != null) { 31 | MDC.setContextMap(parentMDC); 32 | } 33 | LOG.debug("parentMDC --> " + parentMDC); 34 | return actual.call(); 35 | } finally { 36 | if (childMDC != null) { 37 | MDC.setContextMap(childMDC); 38 | } 39 | } 40 | } 41 | 42 | public static void main(String[] args) { 43 | System.out.println("Non-Executable"); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Chapter07/common/src/main/java/com/packtpub/mmj/common/MDCHystrixConcurrencyStrategy.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.common; 2 | 3 | import com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy; 4 | import java.util.concurrent.Callable; 5 | 6 | public class MDCHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy { 7 | 8 | @Override 9 | public Callable wrapCallable(Callable callable) { 10 | return new MDCConcurrentCallable<>(callable); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Chapter07/dashboard-server/nbactions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CUSTOM-clean package 5 | clean package 6 | 7 | clean 8 | package 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Chapter07/dashboard-server/src/main/java/com/packtpub/mmj/dashboard/DashboardApp.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.dashboard; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.builder.SpringApplicationBuilder; 6 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; 7 | import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; 8 | import org.springframework.stereotype.Controller; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | 11 | @SpringBootApplication 12 | @Controller 13 | @EnableHystrixDashboard 14 | public class DashboardApp extends SpringBootServletInitializer { 15 | 16 | @RequestMapping("/") 17 | public String home() { 18 | return "forward:/hystrix"; 19 | } 20 | 21 | @Override 22 | protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 23 | return application.sources(DashboardApp.class).web(true); 24 | } 25 | 26 | public static void main(String[] args) { 27 | SpringApplication.run(DashboardApp.class, args); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Chapter07/dashboard-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | # Hystrix Dashboard properties 2 | spring: 3 | application: 4 | name: dashboard-server 5 | 6 | endpoints: 7 | restart: 8 | enabled: true 9 | shutdown: 10 | enabled: true 11 | 12 | server: 13 | port: 7979 14 | 15 | eureka: 16 | instance: 17 | leaseRenewalIntervalInSeconds: 3 18 | metadataMap: 19 | instanceId: ${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${random.value}}} 20 | 21 | client: 22 | # Default values comes from org.springframework.cloud.netflix.eurek.EurekaClientConfigBean 23 | registryFetchIntervalSeconds: 5 24 | instanceInfoReplicationIntervalSeconds: 5 25 | initialInstanceInfoReplicationIntervalSeconds: 5 26 | serviceUrl: 27 | defaultZone: http://localhost:8761/eureka/ 28 | fetchRegistry: false 29 | 30 | logging: 31 | level: 32 | ROOT: WARN 33 | org.springframework.web: WARN 34 | -------------------------------------------------------------------------------- /Chapter07/dashboard-server/src/main/resources/hystrixdashboard/stream/hystrix.stream: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Chapter07/docker-compose.yml: -------------------------------------------------------------------------------- 1 | 2 | eureka: 3 | image: localhost:5000/sourabhh/eureka-server:PACKT-SNAPSHOT 4 | ports: 5 | - "8761:8761" 6 | 7 | restaurant-service: 8 | image: localhost:5000/sourabhh/restaurant-service:PACKT-SNAPSHOT 9 | ports: 10 | - "8080:8080" 11 | links: 12 | - eureka 13 | -------------------------------------------------------------------------------- /Chapter07/docker/docker-assembly.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | ${project.artifactId} 5 | 6 | 7 | target/${project.build.finalName}.jar 8 | / 9 | 10 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Chapter07/eureka-server/nbactions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CUSTOM-clean and package 5 | clean and package 6 | 7 | clean 8 | package 9 | 10 | 11 | 12 | CUSTOM-docker:build 13 | docker:build 14 | 15 | docker:build 16 | 17 | 18 | 19 | CUSTOM-docker-start 20 | docker:start 21 | 22 | docker:start 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Chapter07/eureka-server/src/main/docker/docker-assembly.xml: -------------------------------------------------------------------------------- 1 | 5 | ${project.artifactId} 6 | 7 | 8 | target/${project.build.finalName}.jar 9 | / 10 | 11 | 12 | src/main/resources/docker-config.yml 13 | / 14 | 15 | 16 | -------------------------------------------------------------------------------- /Chapter07/eureka-server/src/main/java/com/packtpub/mmj/eureka/service/App.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.eureka.service; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | /** 10 | * 11 | * @author Sourabh Sharma 12 | */ 13 | @SpringBootApplication 14 | @Configuration 15 | @EnableAutoConfiguration 16 | @EnableEurekaServer 17 | public class App { 18 | 19 | /** 20 | * 21 | * @param args 22 | */ 23 | public static void main(String[] args) { 24 | SpringApplication.run(App.class, args); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Chapter07/eureka-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | # Yureka Server Configuration 2 | server: 3 | port: ${vcap.application.port:8761} # HTTP port 4 | 5 | info: 6 | component: Discovery Server 7 | 8 | eureka: 9 | instance: 10 | hostname: localhost 11 | client: 12 | registerWithEureka: false 13 | fetchRegistry: false 14 | serviceUrl: 15 | defaultZone: ${vcap.services.${PREFIX:}eureka.credentials.uri:http://user:password@localhost:8761}/eureka/ 16 | server: 17 | waitTimeInMsWhenSyncEmpty: 0 18 | enableSelfPreservation: false 19 | 20 | spring: 21 | thymeleaf: 22 | enabled: false # Disable Thymeleaf 23 | 24 | --- 25 | # For deployment in Docker containers 26 | spring: 27 | profiles: docker 28 | 29 | server: 30 | port: ${vcap.application.port:8761} 31 | 32 | eureka: 33 | instance: 34 | hostname: eureka 35 | client: 36 | registerWithEureka: false 37 | fetchRegistry: false 38 | serviceUrl: 39 | defaultZone: http://eureka:8761/eureka/ 40 | server: 41 | waitTimeInMsWhenSyncEmpty: 0 42 | enableSelfPreservation: false -------------------------------------------------------------------------------- /Chapter07/eureka-server/src/main/resources/docker-config.yml: -------------------------------------------------------------------------------- 1 | FROM java:8-jre 2 | MAINTAINER sourabhh 3 | EXPOSE 8080 4 | COPY maven /maven/ 5 | CMD java -Dspring.profiles.active="docker" -jar \ 6 | /maven/eureka-server.jar server \ 7 | /maven/docker-config.yml -------------------------------------------------------------------------------- /Chapter07/nb-configuration.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 16 | true 17 | JDK_1.8 18 | 19 | 20 | -------------------------------------------------------------------------------- /Chapter07/nbactions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CUSTOM-clean and package 5 | clean and package 6 | 7 | clean 8 | package 9 | 10 | 11 | 12 | CUSTOM-clearn package docker 13 | clearn package docker 14 | 15 | clearn 16 | package 17 | 18 | 19 | docker 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Chapter07/restaurant-service/nbactions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CUSTOM-clean and package 5 | clean and package 6 | 7 | clean 8 | package 9 | 10 | 11 | 12 | CUSTOM-docker:build 13 | docker:build 14 | 15 | docker:build 16 | 17 | 18 | 19 | CUSTOM-docker-start 20 | docker:start 21 | 22 | docker:start 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Chapter07/restaurant-service/src/main/docker/docker-assembly.xml: -------------------------------------------------------------------------------- 1 | 5 | ${project.artifactId} 6 | 7 | 8 | target/${project.build.finalName}.jar 9 | / 10 | 11 | 12 | src/main/resources/docker-config.yml 13 | / 14 | 15 | 16 | -------------------------------------------------------------------------------- /Chapter07/restaurant-service/src/main/java/com/packtpub/mmj/restaurant/RestaurantApp.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.restaurant; 2 | 3 | import com.rabbitmq.client.ConnectionFactory; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; 7 | import org.springframework.beans.factory.annotation.Value; 8 | import org.springframework.boot.SpringApplication; 9 | import org.springframework.boot.autoconfigure.SpringBootApplication; 10 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; 11 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 12 | import org.springframework.context.annotation.Bean; 13 | 14 | @SpringBootApplication 15 | @EnableEurekaClient 16 | @EnableCircuitBreaker 17 | public class RestaurantApp { 18 | 19 | private static final Logger LOG = LoggerFactory.getLogger(RestaurantApp.class); 20 | 21 | @Value("${app.rabbitmq.host:localhost}") 22 | String rabbitMqHost; 23 | 24 | @Bean 25 | public ConnectionFactory connectionFactory() { 26 | LOG.info("Create RabbitMqCF for host: {}", rabbitMqHost); 27 | CachingConnectionFactory connectionFactory = new CachingConnectionFactory(rabbitMqHost); 28 | return connectionFactory.getRabbitConnectionFactory(); 29 | } 30 | 31 | /** 32 | * 33 | * @param args 34 | */ 35 | public static void main(String[] args) { 36 | SpringApplication.run(RestaurantApp.class, args); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Chapter07/restaurant-service/src/main/java/com/packtpub/mmj/restaurant/domain/model/entity/BaseEntity.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.restaurant.domain.model.entity; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | * @param 7 | */ 8 | public abstract class BaseEntity extends Entity { 9 | 10 | private boolean isModified; 11 | 12 | /** 13 | * 14 | * @param id 15 | * @param name 16 | */ 17 | public BaseEntity(T id, String name) { 18 | super.id = id; 19 | super.name = name; 20 | isModified = false; 21 | } 22 | 23 | /** 24 | * 25 | * @return 26 | */ 27 | public boolean isIsModified() { 28 | return isModified; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Chapter07/restaurant-service/src/main/java/com/packtpub/mmj/restaurant/domain/model/entity/Entity.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.restaurant.domain.model.entity; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | * @param 7 | */ 8 | public abstract class Entity { 9 | 10 | T id; 11 | String name; 12 | 13 | /** 14 | * 15 | * @return 16 | */ 17 | public T getId() { 18 | return id; 19 | } 20 | 21 | /** 22 | * 23 | * @param id 24 | */ 25 | public void setId(T id) { 26 | this.id = id; 27 | } 28 | 29 | /** 30 | * 31 | * @return 32 | */ 33 | public String getName() { 34 | return name; 35 | } 36 | 37 | /** 38 | * 39 | * @param name 40 | */ 41 | public void setName(String name) { 42 | this.name = name; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /Chapter07/restaurant-service/src/main/java/com/packtpub/mmj/restaurant/domain/model/entity/Table.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.restaurant.domain.model.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import java.math.BigInteger; 5 | 6 | /** 7 | * 8 | * @author Sourabh Sharma 9 | */ 10 | public class Table extends BaseEntity { 11 | 12 | private int capacity; 13 | 14 | /** 15 | * 16 | * @param name 17 | * @param id 18 | * @param capacity 19 | */ 20 | public Table(@JsonProperty("name") String name, @JsonProperty("id") BigInteger id, @JsonProperty("capacity") int capacity) { 21 | super(id, name); 22 | this.capacity = capacity; 23 | } 24 | 25 | /** 26 | * 27 | * @param capacity 28 | */ 29 | public void setCapacity(int capacity) { 30 | this.capacity = capacity; 31 | } 32 | 33 | /** 34 | * 35 | * @return 36 | */ 37 | public int getCapacity() { 38 | return capacity; 39 | } 40 | 41 | /** 42 | * Overridden toString() method that return String presentation of the 43 | * Object 44 | * 45 | * @return 46 | */ 47 | @Override 48 | public String toString() { 49 | return String.format("{id: %s, name: %s, capacity: %s}", 50 | this.getId(), this.getName(), this.getCapacity()); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /Chapter07/restaurant-service/src/main/java/com/packtpub/mmj/restaurant/domain/repository/ReadOnlyRepository.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.restaurant.domain.repository; 2 | 3 | import java.util.Collection; 4 | 5 | /** 6 | * 7 | * @author Sourabh Sharma 8 | * @param 9 | * @param 10 | */ 11 | public interface ReadOnlyRepository { 12 | 13 | //long Count; 14 | /** 15 | * 16 | * @param id 17 | * @return 18 | */ 19 | boolean contains(T id); 20 | 21 | /** 22 | * 23 | * @param id 24 | * @return 25 | */ 26 | TE get(T id); 27 | 28 | /** 29 | * 30 | * @return 31 | */ 32 | Collection getAll(); 33 | } 34 | -------------------------------------------------------------------------------- /Chapter07/restaurant-service/src/main/java/com/packtpub/mmj/restaurant/domain/repository/Repository.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.restaurant.domain.repository; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | * @param 7 | * @param 8 | */ 9 | public interface Repository extends ReadOnlyRepository { 10 | 11 | /** 12 | * 13 | * @param entity 14 | */ 15 | void add(TE entity); 16 | 17 | /** 18 | * 19 | * @param id 20 | */ 21 | void remove(T id); 22 | 23 | /** 24 | * 25 | * @param entity 26 | */ 27 | void update(TE entity); 28 | } 29 | -------------------------------------------------------------------------------- /Chapter07/restaurant-service/src/main/java/com/packtpub/mmj/restaurant/domain/repository/RestaurantRepository.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.restaurant.domain.repository; 2 | 3 | import java.util.Collection; 4 | 5 | /** 6 | * 7 | * @author Sourabh Sharma 8 | * @param 9 | * @param 10 | */ 11 | public interface RestaurantRepository extends Repository { 12 | 13 | /** 14 | * 15 | * @param name 16 | * @return 17 | */ 18 | boolean containsName(String name); 19 | 20 | /** 21 | * 22 | * @param name 23 | * @return 24 | * @throws Exception 25 | */ 26 | public Collection findByName(String name) throws Exception; 27 | } 28 | -------------------------------------------------------------------------------- /Chapter07/restaurant-service/src/main/java/com/packtpub/mmj/restaurant/domain/service/BaseService.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.restaurant.domain.service; 2 | 3 | import com.packtpub.mmj.restaurant.domain.repository.Repository; 4 | import java.util.Collection; 5 | 6 | /** 7 | * 8 | * @author Sourabh Sharma 9 | * @param 10 | * @param 11 | */ 12 | public abstract class BaseService extends ReadOnlyBaseService { 13 | 14 | private Repository _repository; 15 | 16 | BaseService(Repository repository) { 17 | super(repository); 18 | _repository = repository; 19 | } 20 | 21 | /** 22 | * 23 | * @param entity 24 | * @throws Exception 25 | */ 26 | public void add(TE entity) throws Exception { 27 | _repository.add(entity); 28 | } 29 | 30 | /** 31 | * 32 | * @return 33 | */ 34 | public Collection getAll() { 35 | return _repository.getAll(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Chapter07/restaurant-service/src/main/java/com/packtpub/mmj/restaurant/domain/service/ReadOnlyBaseService.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.restaurant.domain.service; 2 | 3 | import com.packtpub.mmj.restaurant.domain.repository.ReadOnlyRepository; 4 | 5 | /** 6 | * 7 | * @author Sourabh Sharma 8 | * @param 9 | * @param 10 | */ 11 | public abstract class ReadOnlyBaseService { 12 | 13 | private ReadOnlyRepository repository; 14 | 15 | ReadOnlyBaseService(ReadOnlyRepository repository) { 16 | this.repository = repository; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter07/restaurant-service/src/main/java/com/packtpub/mmj/restaurant/domain/service/RestaurantService.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.restaurant.domain.service; 2 | 3 | import com.packtpub.mmj.restaurant.domain.model.entity.Entity; 4 | import com.packtpub.mmj.restaurant.domain.model.entity.Restaurant; 5 | import java.util.ArrayList; 6 | import java.util.Collection; 7 | import java.util.Map; 8 | 9 | /** 10 | * 11 | * @author Sourabh Sharma 12 | */ 13 | public interface RestaurantService { 14 | 15 | /** 16 | * 17 | * @param restaurant 18 | * @throws Exception 19 | */ 20 | public void add(Restaurant restaurant) throws Exception; 21 | 22 | /** 23 | * 24 | * @param restaurant 25 | * @throws Exception 26 | */ 27 | public void update(Restaurant restaurant) throws Exception; 28 | 29 | /** 30 | * 31 | * @param id 32 | * @throws Exception 33 | */ 34 | public void delete(String id) throws Exception; 35 | 36 | /** 37 | * 38 | * @param restaurantId 39 | * @return 40 | * @throws Exception 41 | */ 42 | public Entity findById(String restaurantId) throws Exception; 43 | 44 | /** 45 | * 46 | * @param name 47 | * @return 48 | * @throws Exception 49 | */ 50 | public Collection findByName(String name) throws Exception; 51 | 52 | /** 53 | * 54 | * @param name 55 | * @return 56 | * @throws Exception 57 | */ 58 | public Collection findByCriteria(Map> name) throws Exception; 59 | } 60 | -------------------------------------------------------------------------------- /Chapter07/restaurant-service/src/main/resources/docker-config.yml: -------------------------------------------------------------------------------- 1 | FROM java:8-jre 2 | MAINTAINER sourabhh 3 | EXPOSE 8080 4 | COPY maven /maven/ 5 | CMD java -Dspring.profiles.active="docker" -jar \ 6 | /maven/restaurant-service.jar server \ 7 | /maven/docker-config.yml -------------------------------------------------------------------------------- /Chapter07/restaurant-service/src/test/java/com/packtpub/mmj/restaurant/resources/docker/DockerIT.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.restaurant.resources.docker; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | */ 7 | public interface DockerIT { 8 | // Marker for Docker integratino Tests 9 | } 10 | -------------------------------------------------------------------------------- /Chapter07/restaurant-service/src/test/java/com/packtpub/mmj/restaurant/resources/docker/RestaurantAppDockerIT.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.restaurant.resources.docker; 2 | 3 | import java.io.IOException; 4 | import java.net.HttpURLConnection; 5 | import java.net.URL; 6 | import static org.junit.Assert.assertEquals; 7 | import org.junit.Test; 8 | import org.junit.experimental.categories.Category; 9 | 10 | /** 11 | * 12 | * @author Sourabh Sharma 13 | */ 14 | @Category(DockerIT.class) 15 | public class RestaurantAppDockerIT { 16 | 17 | /** 18 | * 19 | * @throws IOException 20 | */ 21 | @Test 22 | public void testConnection() throws IOException { 23 | String baseUrl = System.getProperty("service.url"); 24 | URL serviceUrl = new URL(baseUrl + "v1/restaurants/1"); 25 | HttpURLConnection connection = (HttpURLConnection) serviceUrl.openConnection(); 26 | int responseCode = connection.getResponseCode(); 27 | assertEquals(200, responseCode); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Chapter07/restaurant-service/src/test/resources/application.yml: -------------------------------------------------------------------------------- 1 | # Spring properties 2 | spring: 3 | cloud: 4 | discovery: 5 | enabled: false 6 | aop: 7 | auto: false 8 | # config: 9 | # enabled: false 10 | # server: 11 | # health: 12 | # enabled: false 13 | # 14 | #hystrix: 15 | # command: 16 | # default: 17 | # circuitBreaker: 18 | # enabled: false 19 | # fallback: 20 | # enabled: false -------------------------------------------------------------------------------- /Chapter07/security-service/nb-configuration.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 16 | JDK_1.8 17 | 18 | 19 | -------------------------------------------------------------------------------- /Chapter07/security-service/nbactions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CUSTOM-clean package 5 | clean package 6 | 7 | clean 8 | package 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Chapter07/security-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | com.packtpub.mmj 6 | 6392_chapter7 7 | MMJ-ED2-SNAPSHOT 8 | 9 | security-service 10 | online-table-reservation:security-service 11 | jar 12 | 13 | 14 | org.springframework.cloud 15 | spring-cloud-starter-security 16 | 17 | 18 | org.springframework.cloud 19 | spring-cloud-starter-oauth2 20 | 21 | 22 | -------------------------------------------------------------------------------- /Chapter07/security-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | info: 2 | component: 3 | Security Server 4 | 5 | server: 6 | port: 9001 7 | ssl: 8 | key-store: classpath:keystore.jks 9 | key-store-password: password 10 | key-password: password 11 | contextPath: /auth 12 | 13 | security: 14 | user: 15 | password: password 16 | 17 | logging: 18 | level: 19 | org.springframework.security: DEBUG -------------------------------------------------------------------------------- /Chapter07/security-service/src/main/resources/keystore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Mastering-Microservices-with-Java-9-Second-Edition/73136020a45456bd99d377051d1ae3401f56a10d/Chapter07/security-service/src/main/resources/keystore.jks -------------------------------------------------------------------------------- /Chapter07/security-service/src/main/wro/main.less: -------------------------------------------------------------------------------- 1 | @brand-primary: #de8579; -------------------------------------------------------------------------------- /Chapter07/security-service/src/main/wro/wro.properties: -------------------------------------------------------------------------------- 1 | #List of preProcessors 2 | preProcessors=lessCssImport 3 | #List of postProcessors 4 | postProcessors=less4j,jsMin -------------------------------------------------------------------------------- /Chapter07/security-service/src/main/wro/wro.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | webjar:bootstrap/3.2.0/less/bootstrap.less 4 | file:${project.basedir}/src/main/wro/main.less 5 | webjar:jquery/2.1.1/jquery.min.js 6 | 7 | -------------------------------------------------------------------------------- /Chapter07/turbine-server/nbactions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CUSTOM-clean package 5 | clean package 6 | 7 | clean 8 | package 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Chapter07/turbine-server/src/main/java/com/packtpub/mmj/turbine/server/TurbineApp.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.turbine.server; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; 6 | import org.springframework.amqp.rabbit.connection.ConnectionFactory; 7 | import org.springframework.beans.factory.annotation.Value; 8 | import org.springframework.boot.SpringApplication; 9 | import org.springframework.boot.autoconfigure.SpringBootApplication; 10 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 11 | import org.springframework.cloud.netflix.turbine.stream.EnableTurbineStream; 12 | import org.springframework.context.annotation.Bean; 13 | 14 | @SpringBootApplication 15 | @EnableTurbineStream 16 | @EnableEurekaClient 17 | public class TurbineApp { 18 | 19 | private static final Logger LOG = LoggerFactory.getLogger(TurbineApp.class); 20 | @Value("${app.rabbitmq.host:localhost}") 21 | String rabbitMQHost; 22 | 23 | @Bean 24 | public ConnectionFactory connectionFactory() { 25 | LOG.info("Creating RabbitMQHost ConnectionFactory for host: {}", rabbitMQHost); 26 | CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(rabbitMQHost); 27 | return cachingConnectionFactory; 28 | } 29 | 30 | public static void main(String[] args) { 31 | SpringApplication.run(TurbineApp.class, args); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Chapter07/turbine-server/src/main/resources/applicaton.yml: -------------------------------------------------------------------------------- 1 | info: 2 | component: Turbine Server 3 | 4 | server: 5 | port: 8989 6 | 7 | management: 8 | port: 8990 9 | 10 | turbine: 11 | aggregator: 12 | clusterConfig: USER-SERVICE,RESTAURANT-SERVICE 13 | # clusterNameExpression: new String("default") 14 | appConfig: user-service,restaurant-service 15 | # clusterNameExpression: 'default' 16 | # InstanceMonitor: 17 | # eventStream: 18 | # skipLineLogic: false 19 | 20 | eureka: 21 | instance: 22 | leaseRenewalIntervalInSeconds: 10 23 | metadataMap: 24 | instanceId: ${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${random.value}}} 25 | client: 26 | serviceUrl: 27 | defaultZone: ${vcap.services.${PREFIX:}eureka.credentials.uri:http://user:password@localhost:8761}/eureka/ 28 | #http://localhost:8761/eureka/ 29 | fetchRegistry: true 30 | 31 | logging: 32 | level: 33 | root: INFO 34 | com.netflix.discovery: 'OFF' 35 | org.springframework.integration: DEBUG 36 | -------------------------------------------------------------------------------- /Chapter07/user-service/nbactions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CUSTOM-clean and package 5 | clean and package 6 | 7 | clean 8 | package 9 | 10 | 11 | 12 | CUSTOM-docker:build 13 | docker:build 14 | 15 | docker:build 16 | 17 | 18 | 19 | CUSTOM-docker-start 20 | docker-start 21 | 22 | docker:start 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Chapter07/user-service/src/main/docker/docker-assembly.xml: -------------------------------------------------------------------------------- 1 | 5 | ${project.artifactId} 6 | 7 | 8 | target/${project.build.finalName}.jar 9 | / 10 | 11 | 12 | src/main/resources/docker-config.yml 13 | / 14 | 15 | 16 | -------------------------------------------------------------------------------- /Chapter07/user-service/src/main/java/com/packtpub/mmj/user/UsersApp.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.user; 2 | 3 | import com.rabbitmq.client.ConnectionFactory; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; 7 | import org.springframework.beans.factory.annotation.Value; 8 | import org.springframework.boot.SpringApplication; 9 | import org.springframework.boot.autoconfigure.SpringBootApplication; 10 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; 11 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 12 | import org.springframework.context.annotation.Bean; 13 | import org.springframework.context.annotation.ComponentScan; 14 | 15 | @SpringBootApplication 16 | @EnableEurekaClient 17 | @EnableCircuitBreaker 18 | @ComponentScan({"com.packtpub.mmj.user", "com.packtpub.mmj.common"}) 19 | public class UsersApp { 20 | 21 | private static final Logger LOG = LoggerFactory.getLogger(UsersApp.class); 22 | 23 | @Value("${app.rabbitmq.host:localhost}") 24 | String rabbitMqHost; 25 | 26 | @Bean 27 | public ConnectionFactory connectionFactory() { 28 | LOG.info("Create RabbitMqCF for host: {}", rabbitMqHost); 29 | CachingConnectionFactory connectionFactory = new CachingConnectionFactory(rabbitMqHost); 30 | return connectionFactory.getRabbitConnectionFactory(); 31 | } 32 | 33 | public static void main(String[] args) { 34 | SpringApplication.run(UsersApp.class, args); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Chapter07/user-service/src/main/java/com/packtpub/mmj/user/domain/model/entity/BaseEntity.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.user.domain.model.entity; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | * @param 7 | */ 8 | public abstract class BaseEntity extends Entity { 9 | 10 | private boolean isModified; 11 | 12 | /** 13 | * 14 | * @param id 15 | * @param name 16 | */ 17 | public BaseEntity(T id, String name) { 18 | super.id = id; 19 | super.name = name; 20 | isModified = false; 21 | } 22 | 23 | /** 24 | * 25 | * @return 26 | */ 27 | public boolean isIsModified() { 28 | return isModified; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Chapter07/user-service/src/main/java/com/packtpub/mmj/user/domain/model/entity/Entity.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.user.domain.model.entity; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | * @param 7 | */ 8 | public abstract class Entity { 9 | 10 | T id; 11 | String name; 12 | 13 | /** 14 | * 15 | * @return 16 | */ 17 | public T getId() { 18 | return id; 19 | } 20 | 21 | /** 22 | * 23 | * @param id 24 | */ 25 | public void setId(T id) { 26 | this.id = id; 27 | } 28 | 29 | /** 30 | * 31 | * @return 32 | */ 33 | public String getName() { 34 | return name; 35 | } 36 | 37 | /** 38 | * 39 | * @param name 40 | */ 41 | public void setName(String name) { 42 | this.name = name; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /Chapter07/user-service/src/main/java/com/packtpub/mmj/user/domain/repository/ReadOnlyRepository.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.user.domain.repository; 2 | 3 | import java.util.Collection; 4 | 5 | /** 6 | * 7 | * @author Sourabh Sharma 8 | * @param 9 | * @param 10 | */ 11 | public interface ReadOnlyRepository { 12 | 13 | //long Count; 14 | /** 15 | * 16 | * @param id 17 | * @return 18 | */ 19 | boolean contains(T id); 20 | 21 | /** 22 | * 23 | * @param id 24 | * @return 25 | */ 26 | TE get(T id); 27 | 28 | /** 29 | * 30 | * @return 31 | */ 32 | Collection getAll(); 33 | } 34 | -------------------------------------------------------------------------------- /Chapter07/user-service/src/main/java/com/packtpub/mmj/user/domain/repository/Repository.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.user.domain.repository; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | * @param 7 | * @param 8 | */ 9 | public interface Repository extends ReadOnlyRepository { 10 | 11 | /** 12 | * 13 | * @param entity 14 | */ 15 | void add(TE entity); 16 | 17 | /** 18 | * 19 | * @param id 20 | */ 21 | void remove(T id); 22 | 23 | /** 24 | * 25 | * @param entity 26 | */ 27 | void update(TE entity); 28 | } 29 | -------------------------------------------------------------------------------- /Chapter07/user-service/src/main/java/com/packtpub/mmj/user/domain/repository/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.user.domain.repository; 2 | 3 | import java.util.Collection; 4 | 5 | /** 6 | * 7 | * @author Sourabh Sharma 8 | * @param 9 | * @param 10 | */ 11 | public interface UserRepository extends Repository { 12 | 13 | /** 14 | * 15 | * @param name 16 | * @return 17 | */ 18 | boolean containsName(String name); 19 | 20 | /** 21 | * 22 | * @param name 23 | * @return 24 | * @throws Exception 25 | */ 26 | public Collection findByName(String name) throws Exception; 27 | } 28 | -------------------------------------------------------------------------------- /Chapter07/user-service/src/main/java/com/packtpub/mmj/user/domain/service/BaseService.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.user.domain.service; 2 | 3 | import com.packtpub.mmj.user.domain.repository.Repository; 4 | import java.util.Collection; 5 | 6 | /** 7 | * 8 | * @author Sourabh Sharma 9 | * @param 10 | * @param 11 | */ 12 | public abstract class BaseService extends ReadOnlyBaseService { 13 | 14 | private Repository _repository; 15 | 16 | BaseService(Repository repository) { 17 | super(repository); 18 | _repository = repository; 19 | } 20 | 21 | /** 22 | * 23 | * @param entity 24 | * @throws Exception 25 | */ 26 | public void add(TE entity) throws Exception { 27 | _repository.add(entity); 28 | } 29 | 30 | /** 31 | * 32 | * @return 33 | */ 34 | public Collection getAll() { 35 | return _repository.getAll(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Chapter07/user-service/src/main/java/com/packtpub/mmj/user/domain/service/ReadOnlyBaseService.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.user.domain.service; 2 | 3 | import com.packtpub.mmj.user.domain.repository.ReadOnlyRepository; 4 | 5 | /** 6 | * 7 | * @author Sourabh Sharma 8 | * @param 9 | * @param 10 | */ 11 | public abstract class ReadOnlyBaseService { 12 | 13 | private ReadOnlyRepository repository; 14 | 15 | ReadOnlyBaseService(ReadOnlyRepository repository) { 16 | this.repository = repository; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter07/user-service/src/main/java/com/packtpub/mmj/user/domain/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.user.domain.service; 2 | 3 | import com.packtpub.mmj.user.domain.model.entity.User; 4 | import com.packtpub.mmj.user.domain.model.entity.Entity; 5 | import java.util.ArrayList; 6 | import java.util.Collection; 7 | import java.util.Map; 8 | 9 | /** 10 | * 11 | * @author Sourabh Sharma 12 | */ 13 | public interface UserService { 14 | 15 | /** 16 | * 17 | * @param booking 18 | * @throws Exception 19 | */ 20 | public void add(User booking) throws Exception; 21 | 22 | /** 23 | * 24 | * @param booking 25 | * @throws Exception 26 | */ 27 | public void update(User booking) throws Exception; 28 | 29 | /** 30 | * 31 | * @param id 32 | * @throws Exception 33 | */ 34 | public void delete(String id) throws Exception; 35 | 36 | /** 37 | * 38 | * @param restaurantId 39 | * @return 40 | * @throws Exception 41 | */ 42 | public Entity findById(String restaurantId) throws Exception; 43 | 44 | /** 45 | * 46 | * @param name 47 | * @return 48 | * @throws Exception 49 | */ 50 | public Collection findByName(String name) throws Exception; 51 | 52 | /** 53 | * 54 | * @param name 55 | * @return 56 | * @throws Exception 57 | */ 58 | public Collection findByCriteria(Map> name) throws Exception; 59 | } 60 | -------------------------------------------------------------------------------- /Chapter07/user-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | # Spring properties 2 | spring: 3 | application: 4 | name: user-service 5 | # Added to fix - java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut hystrixCommandAnnotationPointcut 6 | aop: 7 | auto: false 8 | 9 | # HTTP Server 10 | server: 11 | port: 7770 12 | 13 | # Discovery Server Access 14 | eureka: 15 | instance: 16 | leaseRenewalIntervalInSeconds: 3 17 | metadataMap: 18 | instanceId: ${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${random.value}}} 19 | 20 | client: 21 | registryFetchIntervalSeconds: 5 22 | instanceInfoReplicationIntervalSeconds: 5 23 | initialInstanceInfoReplicationIntervalSeconds: 5 24 | serviceUrl: 25 | defaultZone: ${vcap.services.${PREFIX:}eureka.credentials.uri:http://user:password@localhost:8761}/eureka/ 26 | fetchRegistry: true 27 | 28 | logging: 29 | level: 30 | root: INFO 31 | com.netflix.hystrix: INFO 32 | 33 | 34 | --- 35 | # For deployment in Docker containers 36 | spring: 37 | profiles: docker 38 | 39 | server: 40 | port: 8080 41 | 42 | eureka: 43 | instance: 44 | preferIpAddress: true 45 | client: 46 | serviceUrl: 47 | defaultZone: http://eureka:8761/eureka/ 48 | -------------------------------------------------------------------------------- /Chapter07/user-service/src/main/resources/docker-config.yml: -------------------------------------------------------------------------------- 1 | FROM java:8-jre 2 | MAINTAINER sourabhh 3 | EXPOSE 8080 4 | COPY maven /maven/ 5 | CMD java -Dspring.profiles.active="docker" -jar \ 6 | /maven/user-service.jar server \ 7 | /maven/docker-config.yml -------------------------------------------------------------------------------- /Chapter07/user-service/src/test/java/com/packtpub/mmj/user/resources/docker/DockerIntegrationTest.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.user.resources.docker; 2 | 3 | /** 4 | * 5 | * @author Sourabh Sharma 6 | */ 7 | public interface DockerIntegrationTest { 8 | // Marker for Docker integratino Tests 9 | } 10 | -------------------------------------------------------------------------------- /Chapter07/user-service/src/test/java/com/packtpub/mmj/user/resources/docker/UserAppDockerIT.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.mmj.user.resources.docker; 2 | 3 | import java.io.IOException; 4 | import java.net.HttpURLConnection; 5 | import java.net.URL; 6 | import static org.junit.Assert.assertEquals; 7 | import org.junit.Test; 8 | import org.junit.experimental.categories.Category; 9 | import static org.junit.Assert.assertEquals; 10 | 11 | /** 12 | * 13 | * @author Sourabh Sharma 14 | */ 15 | @Category(DockerIntegrationTest.class) 16 | public class UserAppDockerIT { 17 | 18 | @Test 19 | public void testConnection() throws IOException { 20 | String baseUrl = System.getProperty("service.url"); 21 | URL serviceUrl = new URL(baseUrl + "v1/restaurants/1"); 22 | HttpURLConnection connection = (HttpURLConnection) serviceUrl.openConnection(); 23 | int responseCode = connection.getResponseCode(); 24 | assertEquals(200, responseCode); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Chapter07/user-service/src/test/resources/application.yml: -------------------------------------------------------------------------------- 1 | # Spring properties 2 | spring: 3 | cloud: 4 | discovery: 5 | enabled: false 6 | aop: 7 | auto: false 8 | # config: 9 | # enabled: false 10 | # server: 11 | # health: 12 | # enabled: false 13 | # 14 | #hystrix: 15 | # command: 16 | # default: 17 | # circuitBreaker: 18 | # enabled: false 19 | # fallback: 20 | # enabled: false -------------------------------------------------------------------------------- /Chapter07/zuul-server/nbactions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CUSTOM-clean package 5 | clean package 6 | 7 | clean 8 | package 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Chapter07/zuul-server/src/main/resources/keystore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Mastering-Microservices-with-Java-9-Second-Edition/73136020a45456bd99d377051d1ae3401f56a10d/Chapter07/zuul-server/src/main/resources/keystore.jks -------------------------------------------------------------------------------- /Chapter08/OTRS_UI/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2010-2014 Google, Inc. http://angularjs.org 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /Chapter08/OTRS_UI/app/components/version/interpolate-filter.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | angular.module('myApp.version.interpolate-filter', []) 4 | 5 | .filter('interpolate', ['version', function(version) { 6 | return function(text) { 7 | return String(text).replace(/\%VERSION\%/mg, version); 8 | }; 9 | }]); 10 | -------------------------------------------------------------------------------- /Chapter08/OTRS_UI/app/components/version/interpolate-filter_test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | describe('myApp.version module', function() { 4 | beforeEach(module('myApp.version')); 5 | 6 | describe('interpolate filter', function() { 7 | beforeEach(module(function($provide) { 8 | $provide.value('version', 'TEST_VER'); 9 | })); 10 | 11 | it('should replace VERSION', inject(function(interpolateFilter) { 12 | expect(interpolateFilter('before %VERSION% after')).toEqual('before TEST_VER after'); 13 | })); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /Chapter08/OTRS_UI/app/components/version/version-directive.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | angular.module('myApp.version.version-directive', []) 4 | 5 | .directive('appVersion', ['version', function(version) { 6 | return function(scope, elm, attrs) { 7 | elm.text(version); 8 | }; 9 | }]); 10 | -------------------------------------------------------------------------------- /Chapter08/OTRS_UI/app/components/version/version-directive_test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | describe('myApp.version module', function() { 4 | beforeEach(module('myApp.version')); 5 | 6 | describe('app-version directive', function() { 7 | it('should print current version', function() { 8 | module(function($provide) { 9 | $provide.value('version', 'TEST_VER'); 10 | }); 11 | inject(function($compile, $rootScope) { 12 | var element = $compile('')($rootScope); 13 | expect(element.text()).toEqual('TEST_VER'); 14 | }); 15 | }); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /Chapter08/OTRS_UI/app/components/version/version.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | angular.module('myApp.version', [ 4 | 'myApp.version.interpolate-filter', 5 | 'myApp.version.version-directive' 6 | ]) 7 | 8 | .value('version', '0.1'); 9 | -------------------------------------------------------------------------------- /Chapter08/OTRS_UI/app/components/version/version_test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | describe('myApp.version module', function() { 4 | beforeEach(module('myApp.version')); 5 | 6 | describe('version service', function() { 7 | it('should return current version', inject(function(version) { 8 | expect(version).toEqual('0.1'); 9 | })); 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /Chapter08/OTRS_UI/app/src/scripts/AjaxHandler.js: -------------------------------------------------------------------------------- 1 | angular.module('otrsApp').factory('AjaxHandler', ['$injector', function ($injector) { 2 | 3 | var log = $injector.get('$log'); 4 | var location = $injector.get('$location'); 5 | var http = $injector.get('$http'); 6 | var showSpinner = false; 7 | 8 | var ajaxHandler = {}; 9 | 10 | var restBaseUrl; 11 | if (location.$$absUrl.indexOf('file://') === 0) { 12 | restBaseUrl = 'https://localhost:8765/api/v1'; 13 | log.debug('local REST services'); 14 | } else { 15 | restBaseUrl = 'https://localhost:8765/api/v1'; 16 | log.debug('remote REST services'); 17 | } 18 | 19 | ajaxHandler.getRestBaseUrl = function () { 20 | return restBaseUrl; 21 | }; 22 | 23 | ajaxHandler.activateApi = function () { 24 | return http.get(restBaseUrl + '/utility/activate', null); 25 | }; 26 | 27 | 28 | ajaxHandler.get = function (api) { 29 | return http.get(restBaseUrl + api, null) 30 | }; 31 | 32 | ajaxHandler.startSpinner = function () { 33 | showSpinner = true; 34 | }; 35 | 36 | ajaxHandler.stopSpinner = function () { 37 | showSpinner = false; 38 | }; 39 | 40 | ajaxHandler.getSpinnerStatus = function () { 41 | return showSpinner; 42 | }; 43 | 44 | return ajaxHandler; 45 | }]); 46 | -------------------------------------------------------------------------------- /Chapter08/OTRS_UI/app/src/styles/application.scss: -------------------------------------------------------------------------------- 1 | $icon-font-path: "../../../bower_components/bootstrap-sass-official/assets/fonts/bootstrap/"; 2 | @import "../../../bower_components/bootstrap-sass-official/assets/stylesheets/bootstrap"; 3 | 4 | .bs-docs-footer { 5 | padding-top: 40px; 6 | padding-bottom: 40px; 7 | margin-top: 100px; 8 | color: #777; 9 | text-align: center; 10 | border-top: 1px solid #e5e5e5; 11 | } 12 | 13 | div.navbar-collapse.collapse { 14 | display: block; 15 | overflow: hidden; 16 | max-height: 0px; 17 | -webkit-transition: max-height .3s ease; 18 | -moz-transition: max-height .3s ease; 19 | -o-transition: max-height .3s ease; 20 | transition: max-height .3s ease; 21 | } 22 | div.navbar-collapse.collapse.in { 23 | max-height: 2000px; 24 | } 25 | -------------------------------------------------------------------------------- /Chapter08/OTRS_UI/app/src/views/httperror/httperror.html: -------------------------------------------------------------------------------- 1 |
2 |

{{errorMessage}}

3 |
4 | -------------------------------------------------------------------------------- /Chapter08/OTRS_UI/app/src/views/login/login.html: -------------------------------------------------------------------------------- 1 |
2 |

Login

3 |
4 | 10 |
11 |
12 | 13 | 14 |
15 |
16 | 17 | 18 |
19 |
20 | 21 | 22 |
23 | 24 |
25 |
-------------------------------------------------------------------------------- /Chapter08/OTRS_UI/app/src/views/restaurants/restaurants.html: -------------------------------------------------------------------------------- 1 |

Famous Gourmet Restaurants in Paris

2 |
3 |
4 |
5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 |
#IdNameAddress
{{rest.id}}{{rest.name}}{{rest.address}}
20 | 21 | 22 | -------------------------------------------------------------------------------- /Chapter08/OTRS_UI/bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "otrs-ui", 3 | "description": "OTRS-UI", 4 | "version": "0.0.1", 5 | "license": "MIT", 6 | "private": true, 7 | "dependencies": { 8 | "angular": "~1.5.0", 9 | "angular-ui-router": "~0.2.18", 10 | "angular-mocks": "~1.5.0", 11 | "angular-bootstrap": "~1.2.1", 12 | "angular-touch": "~1.5.0", 13 | "bootstrap-sass-official": "~3.3.6", 14 | "angular-route": "~1.5.0", 15 | "angular-loader": "~1.5.0", 16 | "ngstorage": "^0.3.10", 17 | "angular-resource": "^1.5.0", 18 | "html5-boilerplate": "~5.2.0" 19 | }, 20 | "resolutions": { 21 | "angular": "~1.5.0" 22 | }, 23 | "install": { 24 | "path": "bower_components" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Chapter08/OTRS_UI/e2e-tests/protractor.conf.js: -------------------------------------------------------------------------------- 1 | exports.config = { 2 | allScriptsTimeout: 11000, 3 | 4 | specs: [ 5 | '*.js' 6 | ], 7 | 8 | capabilities: { 9 | 'browserName': 'chrome' 10 | }, 11 | 12 | baseUrl: 'http://localhost:8000/app/', 13 | 14 | framework: 'jasmine', 15 | 16 | jasmineNodeOpts: { 17 | defaultTimeoutInterval: 30000 18 | } 19 | }; 20 | -------------------------------------------------------------------------------- /Chapter08/OTRS_UI/e2e-tests/scenarios.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /* https://github.com/angular/protractor/blob/master/docs/toc.md */ 4 | 5 | describe('my app', function() { 6 | 7 | 8 | it('should automatically redirect to /view1 when location hash/fragment is empty', function() { 9 | browser.get('index.html'); 10 | expect(browser.getLocationAbsUrl()).toMatch("/view1"); 11 | }); 12 | 13 | 14 | describe('view1', function() { 15 | 16 | beforeEach(function() { 17 | browser.get('index.html#/view1'); 18 | }); 19 | 20 | 21 | it('should render view1 when user navigates to /view1', function() { 22 | expect(element.all(by.css('[ng-view] p')).first().getText()). 23 | toMatch(/partial for view 1/); 24 | }); 25 | 26 | }); 27 | 28 | 29 | describe('view2', function() { 30 | 31 | beforeEach(function() { 32 | browser.get('index.html#/view2'); 33 | }); 34 | 35 | 36 | it('should render view2 when user navigates to /view2', function() { 37 | expect(element.all(by.css('[ng-view] p')).first().getText()). 38 | toMatch(/partial for view 2/); 39 | }); 40 | 41 | }); 42 | }); 43 | -------------------------------------------------------------------------------- /Chapter08/OTRS_UI/gulpfile.js: -------------------------------------------------------------------------------- 1 | require('coffee-script/register'); 2 | require('./gulpfile.coffee'); -------------------------------------------------------------------------------- /Chapter08/OTRS_UI/karma.conf.js: -------------------------------------------------------------------------------- 1 | module.exports = function(config){ 2 | config.set({ 3 | 4 | basePath : './', 5 | 6 | files : [ 7 | 'app/bower_components/angular/angular.js', 8 | 'app/bower_components/angular-route/angular-route.js', 9 | 'app/bower_components/angular-mocks/angular-mocks.js', 10 | 'app/components/**/*.js', 11 | 'app/view*/**/*.js' 12 | ], 13 | 14 | autoWatch : true, 15 | 16 | frameworks: ['jasmine'], 17 | 18 | browsers : ['Chrome'], 19 | 20 | plugins : [ 21 | 'karma-chrome-launcher', 22 | 'karma-firefox-launcher', 23 | 'karma-jasmine', 24 | 'karma-junit-reporter' 25 | ], 26 | 27 | junitReporter : { 28 | outputFile: 'test_out/unit.xml', 29 | suite: 'unit' 30 | } 31 | 32 | }); 33 | }; 34 | -------------------------------------------------------------------------------- /Chapter08/OTRS_UI/nbproject/private/private.properties: -------------------------------------------------------------------------------- 1 | auxiliary.org-netbeans-modules-javascript-karma.config=karma.conf.js 2 | auxiliary.org-netbeans-modules-javascript-karma.enabled=true 3 | auxiliary.org-netbeans-modules-selenium2-webclient-protractor.enabled=true 4 | browser=Chrome.INTEGRATED 5 | -------------------------------------------------------------------------------- /Chapter08/OTRS_UI/nbproject/private/private.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | file:/D:/devspace/ws/Mastering-Microservices-with-Java/Chapter%207/OTRS_UI/gulpfile.coffee 7 | file:/D:/devspace/ws/Mastering-Microservices-with-Java/Chapter%207/OTRS_UI/gulpfile.js 8 | file:/D:/devspace/ws/Mastering-Microservices-with-Java/Chapter%207/OTRS_UI/app/src/scripts/app.js 9 | file:/D:/devspace/ws/Mastering-Microservices-with-Java/Chapter%207/OTRS_UI/app/src/index.html 10 | file:/D:/devspace/ws/Mastering-Microservices-with-Java/Chapter%207/OTRS_UI/app/src/styles/application.scss 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Chapter08/OTRS_UI/nbproject/project.properties: -------------------------------------------------------------------------------- 1 | auxiliary.org-netbeans-modules-css-prep.sass_2e_configured=true 2 | auxiliary.org-netbeans-modules-css-prep.sass_2e_enabled=true 3 | auxiliary.org-netbeans-modules-css-prep.sass_2e_mappings=/scss:/css 4 | file.reference.OTRS_UI-app=app 5 | file.reference.OTRS_UI-e2e-tests=e2e-tests 6 | file.reference.OTRS_UI-test=test 7 | files.encoding=UTF-8 8 | site.root.folder=${file.reference.OTRS_UI-app} 9 | test.folder=${file.reference.OTRS_UI-test} 10 | test.selenium.folder=${file.reference.OTRS_UI-e2e-tests} 11 | -------------------------------------------------------------------------------- /Chapter08/OTRS_UI/nbproject/project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.netbeans.modules.web.clientproject 4 | 5 | 6 | OTRS_UI 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Packt 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Software_Hardware_list.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Mastering-Microservices-with-Java-9-Second-Edition/73136020a45456bd99d377051d1ae3401f56a10d/Software_Hardware_list.pdf --------------------------------------------------------------------------------