server:
port: 9091
eureka:
client:
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http://localhost:9090/eureka
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
server:
port: 8081
spring:
application:
name: ORDER-SERVICE
datasource:
url: jdbc:h2:mem:testdb
h2:
console:
enabled: true
eureka:
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://localhost:9090/eureka
<spring-cloud.version>2021.0.3</spring-cloud.version>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
server:
port: 8080
spring:
application:
name: API-GATEWAY
cloud:
gateway:
routes:
- id: order-service
uri: lb://ORDER-SERVICE
predicates:
- Path=/orders/**
- id: payment-service
uri: lb://PAYMENT-SERVICE
predicates:
- Path=/payments/**
eureka:
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://localhost:9090/eureka
instance:
hostname: localhost
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
hystrix:
command:
default:
execution:
isolation:
thread:
timeoutInMilliseconds: 10000
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
<version>1.2.5.RELEASE</version>
</dependency>
@Override
@HystrixCommand(fallbackMethod = "orderFallBack")
public OrderResponse findOrderById(Integer orderId) {
Optional<Order> order = orderRepository.findById(orderId);
if (!order.isPresent()) {
throw new OrderNotFoundException("Order Not Found for provided id");
}
PaymentResponse paymentResponse = restTemplate.getForObject("http://PAYMENT-SERVICE/payments/" + orderId, PaymentResponse.class);
return parseOrderToOrderResponse(order.get(), paymentResponse);
}
public OrderResponse orderFallBack(Integer orderId) {
//TODO: RETURN SOMETHING GOOD HERE
return null;
}
spring:
application:
name: CONFIG-SERVER
cloud:
config:
server:
git:
uri: https://github.com/bijay-shrestha/SpringBootMicroservicesCloud.git
server:
port: 7070
eureka:
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://localhost:9090/eureka
instance:
hostname: localhost
spring:
cloud:
config:
uri:
- http://localhost:7070
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
@EnableFeignClients
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
@Component
@FeignClient("order-service")
public interface OrderFeignInterface {
@PostMapping("/api/v1/orders/checkout")
String checkout(@RequestBody OrderRequestDTO orderRequestDTO);
}
@PutMapping("/api/v1/stock/{productNumber}")
StockResponseDTO updateProduct(@PathVariable String productNumber, @RequestBody StockRequestDTO stockRequestDTO);
private final OrderFeignInterface orderFeignInterface;