diff --git a/ApiGateway/pom.xml b/ApiGateway/pom.xml new file mode 100644 index 0000000..92f2d99 --- /dev/null +++ b/ApiGateway/pom.xml @@ -0,0 +1,125 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.7.6 + + + com.mdtalalwasim.gateway + ApiGateway + 0.0.1-SNAPSHOT + ApiGateway + This is the implementation of API Gateway. + + + + + + + + + + + + + + + 17 + 2021.0.8 + + + + + org.springframework.boot + spring-boot-starter-webflux + + + org.springframework.cloud + spring-cloud-starter + + + org.springframework.cloud + spring-cloud-starter-gateway + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + + + org.springframework.cloud + spring-cloud-starter-loadbalancer + + + org.springframework.boot + spring-boot-devtools + runtime + true + + + + org.springframework.boot + spring-boot-starter-test + test + + + io.projectreactor + reactor-test + test + + + org.springframework.boot + spring-boot-starter-actuator + + + + org.springframework.cloud + spring-cloud-starter-config + + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + org.projectlombok + lombok + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + + + diff --git a/ApiGateway/src/main/java/com/mdtalalwasim/gateway/ApiGatewayApplication.java b/ApiGateway/src/main/java/com/mdtalalwasim/gateway/ApiGatewayApplication.java new file mode 100644 index 0000000..8080b0d --- /dev/null +++ b/ApiGateway/src/main/java/com/mdtalalwasim/gateway/ApiGatewayApplication.java @@ -0,0 +1,13 @@ +package com.mdtalalwasim.gateway; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class ApiGatewayApplication { + + public static void main(String[] args) { + SpringApplication.run(ApiGatewayApplication.class, args); + } + +} diff --git a/ApiGateway/src/main/resources/application.properties b/ApiGateway/src/main/resources/application.properties new file mode 100644 index 0000000..1316ebd --- /dev/null +++ b/ApiGateway/src/main/resources/application.properties @@ -0,0 +1 @@ +#spring.application.name=ApiGateway diff --git a/ApiGateway/src/main/resources/application.yml b/ApiGateway/src/main/resources/application.yml index f8714af..fe64163 100644 --- a/ApiGateway/src/main/resources/application.yml +++ b/ApiGateway/src/main/resources/application.yml @@ -8,6 +8,7 @@ spring: gateway: routes: - id: USER-SERVICE +# uri: lb://CONFIG-DEFAULT uri: lb://USER-SERVICE predicates: - Path=/api/v1/users/** @@ -23,12 +24,14 @@ spring: - Path=/api/v1/ratings/** - -eureka: - client: - fetch-registry: true #by default, it was true - register-with-eureka: true #by default, it was true - service-url: - defaultZone: http://localhost:8761/eureka - instance: - prefer-ip-address: true \ No newline at end of file + config: + import: configserver:http://localhost:8085 + +#eureka: +# client: +# fetch-registry: true #by default, it was true +# register-with-eureka: true #by default, it was true +# service-url: +# defaultZone: http://localhost:8761/eureka +# instance: +# prefer-ip-address: true \ No newline at end of file diff --git a/ApiGateway/src/test/java/com/mdtalalwasim/gateway/ApiGatewayApplicationTests.java b/ApiGateway/src/test/java/com/mdtalalwasim/gateway/ApiGatewayApplicationTests.java new file mode 100644 index 0000000..246d8e1 --- /dev/null +++ b/ApiGateway/src/test/java/com/mdtalalwasim/gateway/ApiGatewayApplicationTests.java @@ -0,0 +1,13 @@ +package com.mdtalalwasim.gateway; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class ApiGatewayApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/ConfigServer/pom.xml b/ConfigServer/pom.xml new file mode 100644 index 0000000..d3382d3 --- /dev/null +++ b/ConfigServer/pom.xml @@ -0,0 +1,72 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.7.6 + + + + com.mdtalalwasim.config.server + ConfigServer + 0.0.1-SNAPSHOT + ConfigServer + This is the implementation of Configuration Server + + + + + + + + + + + + + + + 17 + 2021.0.8 + + + + + org.springframework.cloud + spring-cloud-config-server + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/ConfigServer/src/main/java/com/mdtalalwasim/config/server/ConfigServerApplication.java b/ConfigServer/src/main/java/com/mdtalalwasim/config/server/ConfigServerApplication.java new file mode 100644 index 0000000..6713e15 --- /dev/null +++ b/ConfigServer/src/main/java/com/mdtalalwasim/config/server/ConfigServerApplication.java @@ -0,0 +1,15 @@ +package com.mdtalalwasim.config.server; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.config.server.EnableConfigServer; + +@EnableConfigServer +@SpringBootApplication +public class ConfigServerApplication { + + public static void main(String[] args) { + SpringApplication.run(ConfigServerApplication.class, args); + } + +} diff --git a/ConfigServer/src/main/resources/application.properties b/ConfigServer/src/main/resources/application.properties new file mode 100644 index 0000000..c95fb84 --- /dev/null +++ b/ConfigServer/src/main/resources/application.properties @@ -0,0 +1 @@ +#spring.application.name=ConfigServer diff --git a/ConfigServer/src/main/resources/application.yml b/ConfigServer/src/main/resources/application.yml index 5eb82ad..d3e668c 100644 --- a/ConfigServer/src/main/resources/application.yml +++ b/ConfigServer/src/main/resources/application.yml @@ -1 +1,13 @@ -spring.application.name=ConfigServer +server: + port: 8085 +spring: + application: + name: CONFIG-SERVER + cloud: + config: + server: + git: + uri: https://github.com/mdtalalwasim/Git-Config-Microservice-HRP + clone-on-start: true + default-label: main + diff --git a/ConfigServer/src/test/java/com/mdtalalwasim/config/server/ConfigServerApplicationTests.java b/ConfigServer/src/test/java/com/mdtalalwasim/config/server/ConfigServerApplicationTests.java new file mode 100644 index 0000000..3d53c56 --- /dev/null +++ b/ConfigServer/src/test/java/com/mdtalalwasim/config/server/ConfigServerApplicationTests.java @@ -0,0 +1,13 @@ +package com.mdtalalwasim.config.server; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class ConfigServerApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/HotelService/pom.xml b/HotelService/pom.xml index c17c2c4..deb90d8 100644 --- a/HotelService/pom.xml +++ b/HotelService/pom.xml @@ -64,6 +64,12 @@ org.springframework.boot spring-boot-starter-actuator + + + org.springframework.cloud + spring-cloud-starter-config + + diff --git a/RatingService/pom.xml b/RatingService/pom.xml index 21d2989..c0f412f 100644 --- a/RatingService/pom.xml +++ b/RatingService/pom.xml @@ -45,6 +45,11 @@ spring-cloud-starter-netflix-eureka-client + + org.springframework.cloud + spring-cloud-starter-config + + org.projectlombok lombok diff --git a/UserService/pom.xml b/UserService/pom.xml index 749c540..f733f95 100644 --- a/UserService/pom.xml +++ b/UserService/pom.xml @@ -69,7 +69,28 @@ spring-boot-starter-actuator - + + org.springframework.boot + spring-boot-starter-aop + + + + + io.github.resilience4j + resilience4j-spring-boot2 + 2.3.0 + + + + org.springframework.cloud + spring-cloud-starter-config + + + + diff --git a/UserService/src/main/java/com/mdtalalwasim/user/service/controllers/UserController.java b/UserService/src/main/java/com/mdtalalwasim/user/service/controllers/UserController.java index d4f2aa0..955cf6e 100644 --- a/UserService/src/main/java/com/mdtalalwasim/user/service/controllers/UserController.java +++ b/UserService/src/main/java/com/mdtalalwasim/user/service/controllers/UserController.java @@ -2,7 +2,9 @@ import com.mdtalalwasim.user.service.entities.User; import com.mdtalalwasim.user.service.services.UserService; +import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -13,6 +15,7 @@ @RestController @RequestMapping("/api/v1/users") @RequiredArgsConstructor +@Slf4j public class UserController { private final UserService userService; @@ -26,11 +29,23 @@ public ResponseEntity createUser(@RequestBody User user){ //get singleUser @GetMapping("/{userId}") + @CircuitBreaker(name = "userRatingHotelServiceBreaker", fallbackMethod = "userRatingHotelServiceFallBack") public ResponseEntity getSingleUser(@PathVariable String userId){ User user = userService.getUser(userId); return ResponseEntity.ok(user); } + //userRatingHotelServiceFallBack fallback method + public ResponseEntity userRatingHotelServiceFallBack(@PathVariable String userId, Exception ex){ + log.info("Fallback method called because Service is Down: "+ex.getMessage()); + User user = User.builder() + .email("myemail@gmail.com") + .name("name") + .userId("12345654321") + .build(); + return ResponseEntity.ok(user); + } + //fetch All user @GetMapping public ResponseEntity> getAllUser(){