When using OpenFeign I implement fallbacks returning empty results so lists should simply appear as being empty. E.g. such as
@FeignClient(name = "objects", fallback = ObjectsClientFallback.class)
public interface ObjectsClient {
@RequestMapping("/objects/count")
Long count();
}
and
@Component
public class ObjectsClientFallback implements ObjectsClient {
@Override
public Long count() {
return 0L;
}
}
However, if the service is not started the application produces the ServiceUnavailableException when calling objectsClient.count()
instead of using the fallback.
What is the correct way to use the fallback as @EnableCircuitBreaker
has been deprecated recently? I do not want to add try-catch blocks if possible, especially in the context of lambdas or wrap this in service methods.
The application uses the @EnableDiscoveryClient
annotation, like so
@SpringBootApplication
@EnableJpaRepositories
@EnableFeignClients
@EnableDiscoveryClient
@ServletComponentScan
public class Application {
//..
}
I've seen this question and checked the mentioned documentation, but it didn't help. Library versions are Spring-Boot 2.6.2 and Spring-Cloud 2021.0.0