Context
My micro-services application is based on spring-cloud
: a zuul
gateway is configured in front of two micro-services: service-a and service-b.
One of my API requires that service-a requests service-b; I use feign
for that.
Zuul send X-FORWARDED-*
headers to the services, for them to rewrite the HATEOAS links correctly (when the services are configured with ForwardedHeaderFilter
).
My problem is that the services communicate with each other using Feign
, which relies on Hystrix
.
Hystrix
creates a new thread for each request (we don't use the SEMAPHORE config), so the request in Spring's RequestContextHolder
is lost in the Feign request from service-a to service-b, I can't enrich the feign
request with an feign
interceptor anymore since the original request is lost.
Some potential solutions
Forwarding authorization token is now supported directly by Spring with the parameter hystrix.shareSecurityContext: true
There isn't any "out of the box" configuration to have Hystrix shares the request between threads.
A solution could be to implement my own HystrixConcurrencyStrategy
, which is a class from netflix.hystrix.
My latest find is this Pull Request that has been sent to spring-cloud-netflix, but unfortunately not integrated.
I can try to copy the code of the Pull request, and create a bean, just as what "eacdy" wrote:
@Bean
public RequestAttributeHystrixConcurrencyStrategy hystrixRequestAutoConfiguration() {
return new RequestAttributeHystrixConcurrencyStrategy();
}
Is there an easier solution to forward the headers from Zuul
with Hystrix
?
I suppose that what I am trying to do is very standard when using Zuul
, Hystrix
, and HATEOAS
micro-services that communicate with each other, so maybe there is something that exists already (and that I couldn't find)?
Thanks !