Feign异常com.netflix.hystrix.exception.HystrixRuntimeException

异常提示

2020-08-06 21:42:57.779 ERROR 20088 --- [io-18085-exec-9] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : 
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception
 [Request processing failed; nested exception is com.netflix.hystrix.exception.HystrixRuntimeException: 
 SkuFeign#findList(Sku) timed-out and no fallback available.] with root cause

原因:

Hystrix缺省超时判断为1秒钟,由于网络问题,有些请求超过1秒钟之后才接收到。

解决:

配置修改请求超时时长(application.yml):

hystrix:  
  command:  
    default:  
      execution:  
        isolation:  
          thread:  
            timeoutInMilliseconds: 30000 #缺省为1000  

application.properties 文件

hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=30000

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
com.netflix.feign是一个声明式的Web Service客户端,它简化了编写Web服务客户端的操作。使用Feign,可以通过注释接口来定义客户端,而无需编写实现代码。以下是使用Feign的步骤: 1.添加依赖 在Maven项目中,将以下依赖添加到pom.xml文件中: ``` <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> <version>2.2.5.RELEASE</version> </dependency> ``` 2.创建接口 创建一个用于调用Web服务的接口,并使用注释定义它。例如,以下是一个使用GET请求获取用户信息的接口: ``` @FeignClient(name = "user-service") public interface UserClient { @GetMapping("/users/{id}") User getUser(@PathVariable("id") Long id); } ``` 在此示例中,@FeignClient注释指定要调用的服务的名称,并且getUser方法使用@GetMapping注释定义了一个GET请求。 3.注入客户端 在应用程序中注入客户端,并将其用于调用Web服务。例如,以下是如何在Spring Boot应用程序中注入客户端: ``` @RestController public class UserController { @Autowired private UserClient userClient; @GetMapping("/users/{id}") public User getUser(@PathVariable Long id) { return userClient.getUser(id); } } ``` 在此示例中,UserController使用@Autowired注释注入了UserClient,并将其用于调用getUser方法。 4.配置客户端 通过配置文件或使用Java代码,可以对客户端进行各种配置。例如,以下是如何配置Feign客户端的超时时间: ``` feign.client.config.default.connectTimeout=5000 feign.client.config.default.readTimeout=5000 ``` 在此示例中,配置文件设置默认Feign客户端的连接超时和读取超时时间为5秒。 以上就是使用com.netflix.feign的基本步骤。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值