I'm doing some work with spring-cloud brixton.m5 and trying to get AsyncRestTemplate working to asynchronously compose multiple microservice calls into a coordination service response. I've found spencer gibb's MyFeed github project that gets AsyncRestTemplate working with ribbon here https://github.com/spencergibb/myfeed/blob/master/myfeed-core/src/main/java/myfeed/core, but I'm having trouble when I have a method annotated with @HystrixCommand that returns CompletableFuture, like this:
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);
}
I get the following exception when this method is called:
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]
If I take the @HystrixCommand annotation off getCustomerOrders, the call works fine, but of course I lose hystrix functionality.