2

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.

gadams00
  • 771
  • 1
  • 10
  • 24
  • 1
    I'm not sure `@HystrixCommand` supports returning `CompletableFuture`. See https://github.com/Netflix/Hystrix/tree/master/hystrix-contrib/hystrix-javanica#how-to-use for valid execution patterns. – spencergibb Mar 04 '16 at 22:07
  • My myfeed project hasn't been updated in a while, so there could be issues with later versions. – spencergibb Mar 04 '16 at 22:08

1 Answers1

0

I ended up switching from using CompletableFuture to rx.Observable, which is supported by Hystrix/javanica.

gadams00
  • 771
  • 1
  • 10
  • 24