【问题标题】:Hysterix Javanica AsyncResult Future.get Throwing ExceptionHysterix Javanica AsyncResult Future.get 抛出异常
【发布时间】:2016-11-20 15:01:28
【问题描述】:

我有一个 Spring Cloud 设置在我的本地 tomcat 上运行。我正在使用 feign 客户端调用封装在 Hysterix 命令中的远程服务,一个直接,另一个异步,如下所示。

@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();
        }
    };
}

当我调用 getEmployeesAsync().get() 我遇到了异常

java.lang.UnsupportedOperationException: AsyncResult 只是一个小插曲,不能用作 Future 的完整实现

类似于下面的问题:-

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

根据文档,解决方案是配置 HystrixCommandAspect 类,我这样做如下:-

@Configuration
@EnableAspectJAutoProxy
public class HystrixConfiguration {

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

}

但我仍然遇到同样的异常。看来我缺少一些配置。 注意:- 我的同步方法运行良好。

【问题讨论】:

  • 您能否发布客户端代码,在哪里测试调用?

标签: java hystrix spring-cloud-netflix


【解决方案1】:

你可以尝试在另一个类中调用getEmployeesAsync,它用getEmployeesAsync 注入了类的实例。我也有这个例外。然后我就这样成功了。

【讨论】:

  • 在另一个类中调用它会有什么不同?你能详细说明一下吗?
猜你喜欢
  • 2013-05-24
  • 2019-06-22
  • 2011-05-30
  • 1970-01-01
  • 2011-02-25
  • 2012-01-24
  • 1970-01-01
相关资源
最近更新 更多