Springboot 1.x 接入 springboot 2.x turbine service 问题汇总

1. turbine service 采用最新版,业务接口用1.5  接入不成功,在日志里头有404 获取不到信息,或者提示:No message available","path":"/actuator/hystrix.stream:

问题原因是:请求springboot 1.5 版本请求地址有变更与高版本信息不一致,两个版本需要统一一个URL。

处理方式:需要同一个URL,建议统一使用高版本。

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class HystrixConfiguration {
    @Bean
    public ServletRegistrationBean getServlet() {
        HystrixMetricsStreamServlet hystrixMetricsStreamServlet = new HystrixMetricsStreamServlet();
        ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean();
        servletRegistrationBean.setServlet(hystrixMetricsStreamServlet);
        servletRegistrationBean.addUrlMappings("/actuator/hystrix.stream");
        servletRegistrationBean.setName("HystrixMetricsStreamServlet");
        return servletRegistrationBean;
    }
}

application.yml

配置为:

management:
  endpoints:
    web:
      exposure:
        include: "*"
      cors:
        allowed-origins: "*"
        allowed-methods: "*"

turbine service application配置为:

turbine:
  app-config: *-service,**-service
  aggregator:
    clusterConfig: default
  clusterNameExpression: new String("default")
  combine-host: true
  instanceUrlSuffix:
    default: /actuator/hystrix.stream    ## 注意这里跟上边统一的/actuator/hystrix.stream。
  endpoints:
    web:
      base-path: actuator

1.5版本才用的是/hystrix.stream

2.x 版本才用的是/actuator/hystrix.stream  

所以在请求的时候获取数据出现404 拿不到数据。

建议在bean 处,配置文件处保持统一,统一采用高版本的/actuator/hystrix.stream 。低版本重新初始化bean 重新指定为/actuator/hystrix.stream即可。

2. 新接手别人的项目,然后springboot 版本为1.5 需要接入turbine service 。在引用pom.xml 依赖,配置文件修改配置之后还是没有实现效果。

输入:http://localhost:9705/hystrix.stream

效果是:hystrix.stream一直是ping   没有实际的数据。

问题原因是在crontoller 中没有@HystrixCommand注解。所以导致请求收集不到数据信息。

一般出现改问题,原因有 三个

1. 依赖文件不对,必须依赖一下文件jar  ,启动文件配置的注解不对。启动类注解为:

     ## 启动类注解:
     @EnableHystrix
     @EnableHystrixDashboard
     @EnableCircuitBreaker
     @EnableDiscoveryClient        

        ## 最新版本的依赖  
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
            <version>2.1.8.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.jolokia</groupId>
            <artifactId>jolokia-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
            <version>2.1.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
            <version>2.1.0.RELEASE</version>
        </dependency>

2. applicaiton.yml 没有配置权限

management:
  endpoints:
    web:
      exposure:
        include: "*"      ## 配置权限的地方
      cors:
        allowed-origins: "*"
        allowed-methods: "*"
  endpoint:
    health:
      show-details: ALWAYS

3. RequestMapping 方法上没有使用熔断器,即没有@HystrixCommand注解

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Dream_bin

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值