-
Notifications
You must be signed in to change notification settings - Fork 244
OAuth2FeignRequestInterceptor fails with hystrix thread isolation #89
Comments
Hi, I have found out that the problem is that Hystrix forces code execution in another thread and so you have no access to request / session scoped beans. However, it would be desirable to be able to keep Hystrix enabled. However, I don't see how to properly do the setup using feign-hystrix and I was not able to find an example. Please, could you help with this or provide an example using feign-hystrix? Thanks so much! |
@miguelfgar If you are using |
Hi @spencergibb, @dsyer, Thanks so much for your help. @dsyer, now that I understand what the problem is I completely agree with the change of the subject. Thanks for changing it. @spencergibb yes, I use @FeignClient and I have hystrix on the classpath and so I'm using feign-hystrix module as you say (I have checked that the jar appears on my classpath). All this is OK. My code works with the following setups:
Summary, what I don't know is how to make OAuth2FeignRequestInterceptor to work with feign-hystrix enabled and 'thread' isolation, which is exactly what Dave has reworded in the title of the issue very well :-) Thanks again for your help :-) |
how do you set the isolation strategy to SEMAPHORE? the property 'hystrix.command.default.execution.isolation.strategy' doesn't seem to exist in the lastest release of spring-cloud-starter-hystrix (1.1.4.RELEASE) and i'm not seeing how to configure the circuit breaker used by spring feign. Or to be more clean, it may be coded to, but i cannot find where it would be coded to and it doesn't seem to be exposed in a spring-configuration-metadata.json for the project EDIT: so it looks like its coded in but just not in any configuration metadata file |
It's not spring configuration, it's Hystrix (via archaius), so the metadata won't reflect it. I believe It is well documented both in the spring cloud user guide and the Hystrix wiki. |
This is done as it runs on separate thread when hystrix is enabled which in turn does not work with OAuth2 Gives below error: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request. Refer to spring-attic/spring-cloud-security#89 for more details
Hi guys,
I'm implenting OAuth2 Token relay with Spring Boot 1.3.1 and Spring Cloud Brixton.M4
Microservice A needs to call Microservice B propagating the same OAuth2 token that comes from ZuulProxy (which is OAuth2 enabled).
I'm using FeignClient (in Microservice A) with OAuth2FeignRequestInterceptor so FeingClient can add the oauth2 token to the call to the Microservice B.
However, I get the following exception:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.oauth2ClientContext': Scope 'request' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
I've seen that OAuth2ClientContext is by default scoped "session" as is necessary to persist the context between HTTP Request.
How should I config the OAuth2FeignRequestInterceptor so this works? Currently:
I've been not able to find an example of using OAuth2FeignRequestInterceptor in this scenario (token relay). If you have one, could you send me the link? or could you point me in the right direction with this?
Thanks so much!
The text was updated successfully, but these errors were encountered: