For code, see my tiny 4 class github project
I am using Spring FeignClients to connect to a rest service. This is what the Feign client looks like in its basic (non-async) form:
@FeignClient(value="localhost:8080/products", decode404 = true)
public interface ProductClient {
@RequestMapping(value="/{id}")
Product getById(@PathVariable("id") String id);
}
Now I wanted to do that asynchronously, using an Observable. Information on this is severely lacking in the Spring docs, there is only a small paragraph that tells you to use a HystrixCommand. That's all, no explanation, no sampe code.
In another blog post, I was told to use a HystrixObservable instead. And so I tried that:
@FeignClient(value="localhost:8080/products", decode404 = true)
public interface ProductClient {
@RequestMapping(value="/{id}")
HystrixObservable<Product> getById(@PathVariable("id") String id);
}
Either way, with a HystrixCommand or HystrixObservable, it throws me the error: com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of com.netflix.hystrix.HystrixObservable
I understand why it is giving that error, since Spring Boot automatically attaches a Decoder to the FeignClient to deserialize the response using Jackson. And the type to deserialize the response into is derived from the return value.
I could try to configure a custome Decoder or manually build the Feign clients, but that kind-of defeats the whole purpose of Spring Boot: that it works automagically (albeit with a bit of configuration here and there).
And so my question is: how is this supposed to work?