1
我正在用spring-cloud brixton.m5做一些工作,並試圖讓AsyncRestTemplate工作以異步地將多個微服務調用合成爲協調服務響應。我發現斯潘塞·吉布的MyFeed github上的項目,得到AsyncRestTemplate絲帶這裏https://github.com/spencergibb/myfeed/blob/master/myfeed-core/src/main/java/myfeed/core工作,但我有麻煩時,我有@HystrixCommand返回CompletableFuture,這樣註解的方法:spring-cloud hystrix CompletableFuture
public List<Order> getCustomerOrdersFallback(int customerId) {
return Collections.emptyList();
}
@HystrixCommand(fallbackMethod = "getCustomerOrdersFallback")
@Override
public CompletableFuture<List<Order>> getCustomerOrders(int customerId) {
ListenableFuture<ResponseEntity<List<Order>>> ordersFuture = restTemplate.exchange(
"http://order-service/orders?customerId={customerId}", HttpMethod.GET, null,
new ParameterizedTypeReference<List<Order>>() {
}, customerId);
return CompletableFutureUtils.convert(ordersFuture);
}
我得到的以下情況例外,當這種方法被稱爲:
java.lang.ClassCastException: rx.internal.operators.BlockingOperatorToFuture$2 cannot be cast to java.util.concurrent.CompletableFuture
at com.sun.proxy.$Proxy86.getCustomerOrders(Unknown Source) ~[na:na]
at com.build.coordination.service.CustomerServiceImpl.getCustomerOrderView(CustomerServiceImpl.java:50) ~[classes/:na]
at com.build.coordination.customer.CustomerController.getCustomerOrderView(CustomerController.java:45) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_72-internal]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_72-internal]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_72-internal]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_72-internal]
如果我參加了@HystrixCommand註釋關閉getCustomerOrders,呼叫工作正常,但我當然失去錐功能。
我不確定'@ HystrixCommand'支持返回'CompletableFuture'。有關有效執行模式,請參閱https://github.com/Netflix/Hystrix/tree/master/hystrix-contrib/hystrix-javanica#how-to-use。 – spencergibb
我的餵養項目有一段時間沒有更新,所以可能會有更新版本的問題。 – spencergibb