Feign client concurrency issue
Feign client concurrency issue
I have setup Spring Cloud (Camden.SR7)
with Eureka (1.3.5.RELEASE)
, Config server
and several Spring Boot (1.5.7.RELEASE)
microservices. Communication between microservices is performed with Feign
client (Hystrix
is disabled). Although this works correctly during development, I noticed that under high traffic when multiple simultaneous calls are made between the same microservices, then the threads become deadlocked and no responses are received. This seems as if Feign client does not behave correctly in multi-thread.
Spring Cloud (Camden.SR7)
Eureka (1.3.5.RELEASE)
Config server
Spring Boot (1.5.7.RELEASE)
Feign
Hystrix
I currently use the SEMAPHORE
isolation strategy. I also tried changing the isolation strategy to THREAD
and specifying a thread pool, but in this case I got 403 error for all my calls. I also experimented with feign-httpclient
as an alternative and although this seemed to improve the situation, it required hardcoded URLs instead of retrieving them from Eureka
, so I did not proceed with this solution.
SEMAPHORE
THREAD
feign-httpclient
Eureka
Any ideas how to fix this? My code is as follows
bootstrap.yml:
hystrix:
command:
default:
execution:
isolation:
strategy: SEMAPHORE
semaphore:
maxConcurrentRequests: 100000 # basically 'unlimited'
timeout:
enabled: false
circuitBreaker:
enabled: false
fallback:
enabled: false
ribbon:
ConnectTimeout: 180000
ReadTimeout: 180000
FeignClientConfiguration:
@Configuration
public class FeignClientConfiguration {
@Bean
public Retryer retryer() {
return new Retryer() {
@Override
public void continueOrPropagate(RetryableException e) {
throw e;
}
@Override
public Retryer clone() {
return this;
}
};
}
@Bean
public RequestInterceptor requestTokenBearerInterceptor() {
return requestTemplate -> {
requestTemplate.header("Authorization",JWTUtil.getAuthorizationToken());
};
}
FeignClient:
@FeignClient(name = "audit-log-service", configuration = FeignClientConfiguration.class)
public interface AuditLogFeignClient {
@RequestMapping("/audit-log-ms/audit/save")
void saveEntityToDatabase(@RequestBody Object object);
}
1 Answer
1
You can add in yml configuration file the property sharedSecurityContext: true.
This will share the Security context of main thread to the one used by the Hystrix command when you use isolation strategy THREAD
THREAD
.
See here.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Thank you, this seems to work. By adding this property I no longer get the 403 errors with THREAD strategy and this seems to solve the concurrency issue.
– dchar
Jul 4 at 14:01