naz*_*art 5 spring runtimeexception spring-boot hystrix spring-cloud
我有Spring Cloud的微服务项目,这是父母的摘录:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.7.RELEASE</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.SR3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
所有服务都在Eureka服务器下运行:
所有服务运行正常。我可以打给Postman适当的电话,一切正常。
我有单独的服务来处理Hystrix仪表板,摘录自pom:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
配置主类:
@SpringBootApplication
@EnableHystrixDashboard
public class DashboardApp {
public static void main(String[] args) {
SpringApplication.run(DashboardApp.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
和配置yaml文件:
spring:
application:
name: Dashboard
server:
port: 8000
eureka:
client:
fetchRegistry: true
registerWithEureka: false
serviceUrl:
defaultZone: http://localhost:8761/eureka
Run Code Online (Sandbox Code Playgroud)
我有下一个仪表板:
来自控制台的完整堆栈跟踪在这里。以下是一些代码段:
2018-04-12 11:28:25.089 ERROR 15762 --- [qtp295055909-16] ashboardConfiguration$ProxyStreamServlet : Error proxying request: http://localhost:8082/hystrix.stream
java.lang.RuntimeException: org.eclipse.jetty.io.EofException
at org.springframework.cloud.netflix.hystrix.dashboard.HystrixDashboardConfiguration$ProxyStreamServlet.doGet(HystrixDashboardConfiguration.java:208)
....
Caused by: org.eclipse.jetty.io.EofException: null
...
Caused by: java.io.IOException: Broken pipe
...
Run Code Online (Sandbox Code Playgroud)
弹簧执行器可访问服务本身:
摘录pom如下:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
Config类的外观:
@EnableHystrix
@EnableEurekaClient
@SpringBootApplication
public class TableApp {
public static void main(String[] args) {
SpringApplication.run(TableApp.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
如何解决这个问题?
Sha*_*pta 10
对于使用Spring Boot 2的用户,hystrix.stream端点已移至/actuator/hystrix.stream。
对我来说,这个网址有效:
http://localhost:8082/actuator/hystrix.stream
Run Code Online (Sandbox Code Playgroud)
是的,通过以下属性启用该执行器端点:
management.endpoints.web.exposure.include=hystrix.stream
Run Code Online (Sandbox Code Playgroud)
当然,您的项目中必须包含执行器依赖项。
Hystrix 仪表板本身不能用于同时监控多个实例。你需要的是涡轮+仪表板。简而言之,turbine 是多个 hystrix 指标流的聚合器。
实例配置:
management:
endpoints:
web:
exposure:
include: hystrix.stream, info, health
spring:
application:
name: WRITING
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka
Run Code Online (Sandbox Code Playgroud)
这里重要的是公开 hystix.stream 执行器。涡轮机将使用该端点来读取指标。另外,不要忘记添加执行器启动器。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
如果一切正确,http://localhost:8080/actuator/hystrix.stream端点应该可用。
涡轮机配置如下所示:
server:
port: 8888
spring:
application:
name: TURBINE
eureka:
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://localhost:8761/eureka/
turbine:
appConfig: WRITING,READING
clusterNameExpression: new String('default')
Run Code Online (Sandbox Code Playgroud)
在 中appConfig,您应该指定用于监控的服务名称。
启动涡轮机后localhost:8888/turbine.stream即可使用。
您可以将此 URL 传递到仪表板并监控已发现实例的 hystrix 命令聚合的所有数据。
Github项目示例。
ps 您使用的依赖项已被弃用。请检查Maven 仓库
我能解决这个问题的spring-boot-starter-parent版本2.0.7.RELEASE和spring-cloud-dependencies版本Finchley.SR2中加入下面的两个属性application.properties。
management.endpoints.web.exposure.include=*
management.endpoints.web.base-path=/
Run Code Online (Sandbox Code Playgroud)
最后,我找到了解决方案。
问题是控制器 API 必须通过HystrixCommand注释来上市。
文档片段:
Turbine AMQP by Spring Cloud offers a different model where each
application instance pushes the metrics from Hystrix commands to
Turbine through a central AMQP broker.
Run Code Online (Sandbox Code Playgroud)
我将它添加到所有控制器的方法中,没有任何参数,如下所示:
@RestController
@AllArgsConstructor
public class GuestController {
private DinnerService dinnerService;
@HystrixCommand
@PostMapping("/dinner")
public Integer startDinner(@RequestBody List<Integer> menuItems) {
return dinnerService.startDinner(menuItems);
}
@HystrixCommand
@DeleteMapping("/dinner/{tableId}")
public void finishDinner(@PathVariable Integer tableId) {
dinnerService.finishDinner(tableId);
}
}
Run Code Online (Sandbox Code Playgroud)
现在一切都很迷人:
现在我明白了,我离它是如此之近。
| 归档时间: |
|
| 查看次数: |
6153 次 |
| 最近记录: |