【发布时间】: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