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注解