2 years ago
#48053
Apex
Fall Back methods are not called in cloud gateway when a service is down using hystrix and eureka
I am new to microservices using boot. I have a project with only 2 microservices (school and student, just a learning project) , I have created the registry service with eureka and the cloud gateway too and all seems to work fine but when I try to stop a service the cloud gateway returns a 405 response status instead of calling the fallback method for the service that is shut down defined in controller. here is my application.yml for cloud gateway:
application:
name: API-GATEWAY
cloud:
gateway:
routes:
- id: STUDENT-SERVICE
uri: lb://STUDENT-SERVICE
predicates:
- Path=/student/**
filters:
- name: CircuitBreaker
args:
name: STUDENT-SERVICE
fallbackuri: forward:/fallback/student
- id: SCHOOL-SERVICE
uri: lb://SCHOOL-SERVICE
predicates:
- Path=/school/**
filters:
- name: CircuitBreaker
args:
name: SCHOOL-SERVICE
fallbackuri: forward:/fallback/school
Also the controller :
@RestController
@RequestMapping("/fallback")
public class FallBackMethodController {
@GetMapping("/school")
public String schoolServiceFallBackMethod(){
return "School service is taking too long . Retry later.";
}
@GetMapping("/student")
public String studentServiceFallBackMethod(){
return "Student service is taking too long . Retry later.";
}
}
My pom.xml file :
<properties>
<java.version>11</java.version>
<spring-cloud.version>2021.0.0</spring-cloud.version>
</properties>
<dependencies>
<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>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
<version>2.2.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-circuitbreaker-reactor-resilience4j</artifactId>
<version>2.1.0</version>
</dependency>
</dependencies>
<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>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
is something missing here?
spring-boot
spring-cloud
netflix-eureka
hystrix
0 Answers
Your Answer