Hystrix fallback method does not run
Asked Answered
I

1

5

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<>();
}
Indican answered 6/6, 2017 at 13:36 Comment(2)
Ah, to enable annotation you have to call your method from another bean.Melburn
:O, ty man, perfectIndican
M
11

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

Melburn answered 6/6, 2017 at 13:55 Comment(3)
Thanks, can you please suggest the reason behind?Demolish
don't know why it is like that. kinda weird.Helwig
@Demolish aspects works like a proxy and proxy mechanism in Spring are working only between beansMelburn

© 2022 - 2024 — McMap. All rights reserved.