dchar
dchar

Reputation: 1695

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.

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.

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);
}

Upvotes: 0

Views: 4866

Answers (1)

Bariampas Thomas
Bariampas Thomas

Reputation: 16

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

. See here.

Upvotes: 0

Related Questions