springCloud微服务---消费者查询方法报504(使用了网关)

配置了euruka、hystrix、feign、zuul,两个相同的提供者,一个消费者

eureka配置文件如下:

server:
  port: 6061

spring:
  application:
    name: eureka6061
  security:
    user:
      name: admin
      password: 123

eureka:
  server:
    enable-self-preservation: false        #禁用保护,默认true
    eviction-interval-timer-in-ms: 10000    #清理间隔(默认是60*1000)
  client:
    fetch-registry: false #是否向eureka server获取列表信息
    register-with-eureka: false #是否向自己注册
    service-url:
      defaultZone: http://admin:123@localhost:6061/eureka/

 

zuul配置文件如下:

server:
  port: 7070
spring:
  application:
    name: gateway-zuul

eureka:
  client:
    service-url:
      defaultZone: http://admin:123@localhost:6061/eureka/

zuul:
  routes:
    provider9091: /provider/*   #注意使用服务名
    consumer8090: /consumer/*
  prefix: /gateway                       #前缀
  ignored-services: '*'                  #禁用服务名访问(内网不受该限制)
  ignored-patterns: /**/hit/**    #禁用某些路径
  sensitive-headers: '*'                 #解决走网关session变化
  host:
    connect-timeout-millis: 60000
    socket-timeout-millis: 60000
  ribbon:
    eager-load:
      enabled: true
hystrix:
  command:
    default:
      execution:
        isolation:
          thread:
            timeoutInMilliseconds: 480000
ribbon:
  ReadTimeout: 5000     #ribbon连接超时
  ConnectTimeout: 8000  #ribbon读取超时

 

consumer配置文件如下:

server:
  port: 8090

spring:
  application:
    name: consumer8090
    mvc:
      format:
        date-time: yyyy-MM-dd HH:mm:ss
      jackson:
        time-zone: GMT+8
        date-format: yyyy-MM-dd HH:mm:ss

#redis:
#  host: 127.0.0.1
#  port: 6379
#  #password: root
#  database: 0
#  timeout: 10s  # 数据库连接超时时间,2.0 中该参数的类型为Duration,这里在配置的时候需要指明单位
#  # 连接池配置,2.0中直接使用jedis或者lettuce配置连接池
#  jedis:
#    pool:
#      max-idle: 50        # 最大空闲连接数
#      min-idle: 10        # 最小空闲连接数
#      max-wait:  -1s        # 等待可用连接的最大时间,负数为不限制
#      max-active: -1        # 最大活跃连接数,负数为不限制

eureka:
  client:
    service-url:
      defaultZone: http://admin:123@localhost:6061/eureka/   #注意用户名和密码 @
    register-with-eureka: true #向eurek server 注册
    fetch-registry: false #获取信息列表
#  server:
#    enable-self-preservation: false        #禁用保护,默认true
#    eviction-interval-timer-in-ms: 10000    #清理间隔(默认是60*1000)

provider9091: #服务名
  ribbon:
    #NFloadBalancerRuleClassName: com.netflix.loadbalancer.RandomRule  #随机策略
    NFloadBalancerRuleClassName: com.netflix.loadbalancer.RoundRobinRule #轮询

feign:
  hystrix:
    enabled: true   #默认false

management:
  endpoints:
    web:
      exposure:
        include: "*"
        #include: hystrix.stream
  endpoint:
    health:
      show-details: ALWAYS

hystrix:
  command:
    default:
      circuitBreaker:
        sleepWindowInMilliseconds: 5000   	#过多长时间,熔断器再次检测是否开启,默认为5000,即5s钟
        errorThresholdPercentage: 50	#错误率,默认50%
        forceOpen: false			#强制打开断路器,默认false(true打开后会强制断开服务)

 

测试了返回Integer的login方法与addComment方法,没有问题,返回List的showBlogs方法一直降级处理,第一次报504超时,后面返回空

    <select id="login" resultType="Integer">
        select count(1) from user where `userName`=#{arg0} and `password`=#{arg1}
    </select>

    <select id="showBlogs" resultType="com.aisling.pojo.BlogDetail">
        SELECT * FROM blog_detail ORDER BY createDate desc
    </select>

    <insert id="addComment" parameterType="com.aisling.pojo.BlogComment">
        INSERT INTO blog_comment(blogId,content,createUser,createDate)
        VALUES(#{blogId},#{content},#{createUser},#{createDate});
    </insert>

 

provider端没有问题

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 以帮助更多的人 ^-^