I tried to follow "https://github.com/spring-cloud/spring-cloud-sleuth/issues/124" (https://github.com/spring-cloud-samples/brewery/blob/master/brewing/src/main/java/io/spring/cloud/samples/brewery/bottling/BottlingConfiguration.java#L30) but it didn't help. The loadBalancerInterceptor is not added to the AsyncRestTemplate. When I debugged, I found that the interceptors are added/registered "after" all the beans are created - so AsyncRestTemplate gets created immediately after RestTemplate and before @Loadbalanced interceptor gets added.
Asked
Active
Viewed 875 times
0
-
Can you post your sample somewhere? – Marcin Grzejszczak Apr 18 '17 at 20:37
-
One additional info is: I have 2 "@Loadbalanced" RestTemplates and I want to pass only one of them to AsyncRestTemplate (for this I tried to use "@Qualifier" and also tried to specify the name corresponding to one of them - failed in both approaches - the interceptor was not added). I will now try to give you a sample project. – Jothi Apr 18 '17 at 20:48
-
Have you tried to autowire a list of interceptors and add them manually? A sample would be really helpful – Marcin Grzejszczak Apr 18 '17 at 20:49
-
Hi @MarcinGrzejszczak - here is a link to the Eureka client project - https://github.com/jot-hub/eureka-async-rest. The Eureka server needs to be setup and the eureka url should be updated in Eureka client project. – Jothi Apr 19 '17 at 03:07
-
1You're not wrapping your AsyncRestTemplate in a trace representation. Check this section of the docs - http://cloud.spring.io/spring-cloud-sleuth/1.1.x/#_multiple_asynchronous_rest_templates (I added it yesterday). – Marcin Grzejszczak Apr 19 '17 at 07:54
-
Hi @MarcinGrzejszczak - need a little bit more detail: My understanding of your suggestions is as follows: TraceAsyncRestTemplate solves 2 problems in 1 go - (1) make sure tracing is enabled for requests with AsyncRestTemplate by delegating calls via RestTemplate? (2) As a side-effect, the interceptors set for RestTemplate (including the LoadBalancerInterceptor) also comes into play and solves the original issue raised in the question - is this correct? – Jothi Apr 19 '17 at 13:14
-
TraceAsyncRestTemplate registers a traced callback that takes care of passing tracing information. Also, the result of request execution is a traced representation of a ListenableFuture. And what you mentioned looks correct :) – Marcin Grzejszczak Apr 19 '17 at 13:24
-
Also, what exactly should go in CustomClientHttpRequestFactory? Looks like am missing something obvious here - is it not enough to use simpleclienthttprequestfactory? – Jothi Apr 19 '17 at 13:30
-
You can build whatever ClientHttpRequestFactory you want. It can be the one that you've mentioned. – Marcin Grzejszczak Apr 19 '17 at 13:31
-
I don't have permission to upvote this yet - probably @MarcinGrzejszczak's comments could be moved to answers section. – Jothi Apr 19 '17 at 13:32
-
Moved a comment as an answer – Marcin Grzejszczak Apr 19 '17 at 13:33
1 Answers
0
You're not wrapping your AsyncRestTemplate in a trace representation. Check this section of the docs - cloud.spring.io/spring-cloud-sleuth/1.1.x/#_multiple_asynchronous_rest_templates (I added it yesterday).
UPDATE:
This PR https://github.com/spring-cloud/spring-cloud-commons/pull/149 fixes the problem with AsyncRestTemplate
entirely in the Dalston release.

Marcin Grzejszczak
- 10,624
- 1
- 16
- 32
-
TraceAsyncRestTemplate still did not make sure LoadBalancerInterceptor is called - i.e. I continue to get "UnknownHostException" from Eureka - I updated the project - https://github.com/jot-hub/eureka-async-rest – Jothi Apr 19 '17 at 14:30
-
am also looking at https://github.com/spring-cloud/spring-cloud-commons/pull/149 - is that a more straight forward way to achieve the same? – Jothi Apr 19 '17 at 17:21
-
The latest Dalston release of Spring cloud fixes this by adding @LoadBalanced support also to AsyncRestTemplate - project is updated with such changes (important changes are in the pom)- github.com/jot-hub/eureka-async-rest – Jothi Apr 19 '17 at 17:34
-