【问题标题】:Feign client concurrency issueFeign客户端并发问题
【发布时间】:2018-12-10 18:47:42
【问题描述】:

我已经设置了 Spring Cloud (Camden.SR7)Eureka (1.3.5.RELEASE)Config server 和几个 Spring Boot (1.5.7.RELEASE) 微服务。微服务之间的通信使用Feign 客户端执行(Hystrix 已禁用)。虽然这在开发过程中可以正常工作,但我注意到在高流量下,当在同一个微服务之间进行多个同时调用时,线程会陷入死锁并且没有收到任何响应。这似乎 Feign 客户端在多线程中的行为不正确。

我目前使用SEMAPHORE 隔离策略。我还尝试将隔离策略更改为THREAD 并指定一个线程池,但在这种情况下,我的所有调用都收到 403 错误。我还尝试了 feign-httpclient 作为替代方案,虽然这似乎改善了这种情况,但它需要硬编码 URL,而不是从 Eureka 检索它们,所以我没有继续使用这个解决方案。

任何想法如何解决这个问题?我的代码如下

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

FeignClient配置:

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

【问题讨论】:

    标签: spring-cloud netflix-eureka hystrix spring-cloud-feign feign


    【解决方案1】:

    您可以在 yml 配置文件中添加属性 sharedSecurityContext: true。 当你使用隔离策略THREAD

    。 见here

    【讨论】:

    • 谢谢,这似乎有效。通过添加此属性,我不再收到 THREAD 策略的 403 错误,这似乎解决了并发问题。
    猜你喜欢
    • 2018-08-22
    • 2019-11-04
    • 1970-01-01
    • 2020-12-20
    • 2020-09-10
    • 2020-04-29
    • 1970-01-01
    • 2018-03-21
    • 2018-04-19
    相关资源
    最近更新 更多