Search code examples
javahystrixspring-cloud-netflix

Hysterix Javanica AsyncResult Future.get Throwing Exception


I have a Spring Cloud set up running on my local tomcat. I am using feign client to invoke a remote service wrapped inside Hysterix command one direct and other async as below.

@HystrixCommand(fallbackMethod = "fallBackEmployeeCall")
    public List<EmployeeBean> getEmployees() {
        //Call through Feign Client
        return empInterface.getEmployees();
    }

    //Async Version
    @HystrixCommand(fallbackMethod = "fallBackEmployeeCall")
public Future<List<EmployeeBean>> getEmployeesAsync() {
    return new AsyncResult<List<EmployeeBean>>() {
        @Override
        public List<EmployeeBean> invoke() {
            return empInterface.getEmployees();
        }
    };
}

When I am calling getEmployeesAsync().get() I am getting below exception

java.lang.UnsupportedOperationException: AsyncResult is just a stab and cannot be used as complete implementation of Future

It is similar to below issue :-

[https://github.com/Netflix/Hystrix/issues/1179][1]

According to docs the solution is to configure HystrixCommandAspect class, which I did as below :-

@Configuration
@EnableAspectJAutoProxy
public class HystrixConfiguration {

    @Bean
    public HystrixCommandAspect hystrixAspect() {
        return new HystrixCommandAspect();
    }

}

But I am still getting the same exception. It seems I am missing some configuration. Note :- my sync method is working fine.


Solution

  • you can try call getEmployeesAsync in the other class, which injected the instance of the class with getEmployeesAsync. I had this exception, too. Then I do it like this successful.