【发布时间】: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