Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hystrix fallback method does not run

I run a call to an endpoint that is off, however the hystrix does not execute the fallback method, and throws an exception:

java.util.concurrent.ExecutionException: org.springframework.web.client.ResourceAccessException: 
I/O error on GET request for "http://localhost:8080/wallet/customers/100/cards/": Conexão recusada (Connection refused); nested exception is java.net.ConnectException: Conexão recusada (Connection refused)

Anyone know if any configuration is missing?

My main

@EnableCircuitBreaker
@SpringBootApplication
public class WalletPaymentApplication {

    public static void main(String[] args) {
        SpringApplication.run(WalletPaymentApplication.class, args);
    }
}

and my service:

public PaymentMethodsData setUpPaymentMethods(String customerId) {
    return new PaymentMethodsData(getCardList(customerId));
}

@HystrixCommand(fallbackMethod = "getCardListCircuitBreaker")
public List<SummaryCardData> getCardList(String customerId) {
    return template.getForObject(configureUrl(cardUrl), CardRows.class, customerId).getRows();
}

public List<SummaryCardData> getCardListCircuitBreaker(String customerId){
    return new ArrayList<>();
}
like image 953
Tiago Costa Avatar asked Jun 06 '17 13:06

Tiago Costa


People also ask

How does fallback work in Hystrix?

The principle is analogous to electronics: Hystrix is watching methods for failing calls to related services. If there is such a failure, it will open the circuit and forward the call to a fallback method. The library will tolerate failures up to a threshold. Beyond that, it leaves the circuit open.

How do you catch exceptions in Hystrix fallback?

Simply add a Throwable parameter to the fallback method and it will receive the exception which the original command produced. For Throwable e , it can show me the real reason, like FAILURE/SHORTCIRCUITED/TIMEOUT/BAD_REQUEST/SEMAPHORE_REJECTED/THREAD_POOL_REJECTED.

How do I retry with Hystrix?

I have a hystrix command that encapsulates a REST call. In case of failure(e.g. timeout), I want to make a single retry and return an appropriate error if it still fails. As I can see, Hystrix doesn't support retries. The only way to do it with Hystrix is to put the main logic into getFallback() method.

Is Netflix hystrix deprecated?

Spring Cloud Hystrix project is deprecated. So new applications should not use this project.


1 Answers

To enable @HystrixCommand(fallbackMethod = "getCardListCircuitBreaker") you have to call your method from another bean. Then annotation will work properly.

like image 124
ByeBye Avatar answered Sep 29 '22 22:09

ByeBye