开发者社区> 问答> 正文

[@徐雷frank][¥20]SpringCloud 隔一段时间去调用服务就返回 read time out

已解决

最近使用springcloud搭建微服务;api-server作为接口提供服务 zxmseed-server作为消费,当zxmseed-server调用api-server一段时间过后 再去访问就返回read time out。

在网上找到三种解决方案:

1:设置关闭熔断器

feign:
httpclient:

enabled:true

#熔断器关闭
hystrix:

  enabled: false

2:关闭超时时间:

关闭超时时间

hystrix:
command:
default:

  execution:
    timeout:
      enabled: false

3:设置ribbon超时时间:

ribbon.ReadTimeout: 1000
ribbon.ConnectTimeout: 250
结果都是一样,间隔时间久了 访问就read time out;

注册中心配置:

server:
port: 8888
eureka:
instance:

hostname: localhost

client:

registerWithEureka: false
fetchRegistry: false
serviceUrl:
  defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

api-server 配置:

server:
port: 8762

eureka:
client:

serviceUrl:
  defaultZone: http://localhost:8888/eureka/

spring:
application:

name: api-server

datasource:

url: jdbc:mysql://127.0.0.1:3306/test?characterEncoding=UTF-8&&useSSL=false
username: root
password: 123456
driver-class-name: com.mysql.jdbc.Driver

熔断器关闭

feign:
hystrix:

enabled: false

zxmseed-server 消费者配置:

feign:

httpclient:

enabled:true

熔断器关闭

hystrix:

enabled: false

eureka:
client:

serviceUrl:
  defaultZone: http://localhost:8888/eureka/

spring:
application:

name: zxmseed-server

server:
port: 8800

关闭超时时间

hystrix:

command:

default:

execution:

timeout:

enabled: false

hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 70000

ribbon.ReadTimeout: 1000
ribbon.ConnectTimeout: 250
有什么方式可以让他不超时,如果我的服务访问量少间隔时间就会很长 怎么样设置不超时!?

展开
收起
晓生寒 2018-12-14 20:42:44 6193 0
1 条回答
写回答
取消 提交回答
  • 1.阿里云大学讲师,主讲《微服务Spring Cloud设计与开发实战》《MongoDB高级实战》等课程 2.MongoDB中文社区专家 3.《MongoDB实战》第2版译者 5.吉林大学计算机科学学士、上海交通大学硕士
    采纳回答

    1、Spring Cloud超时问题,涉及到多个配置,比如Ribbon超时和限流超时控制,如果时间太短容易导致请求超时。
    2、当向服务调用添加低“延迟”参数时,网关的行为没有任何与超时相关的问题,但是如果延迟参数被更改为很短时间低至1到1.5秒,则网关将超时。原因是网关设置使用Eureka服务器,则网关就会使用Netflix组件进行实际调用。
    4、此外,Hystrix确保调用是容错。 我们遇到的第一个超时是因为Hystrix具有非常低的延迟容限阈值,调整hystrix设置应该让我们超过第一个超时。
    5、配置2个部分
    hystrix:
    command:

    default:
      execution:
        isolation:
          thread:
            timeoutInMilliseconds: 15000

    6、Ribbon服务svc:
    ribbon:

    ReadTimeout: 15000
    2019-07-17 23:21:32
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
云栖社区特邀专家徐雷Java Spring Boot开发实战系列课程(第20讲):经典面试题与阿里等名企内部招聘求职面试技巧 立即下载
微服务架构模式与原理Spring Cloud开发实战 立即下载
阿里特邀专家徐雷Java Spring Boot开发实战系列课程(第18讲):制作Java Docker镜像与推送到DockerHub和阿里云Docker仓库 立即下载

相关实验场景

更多