我似乎找不到如何在Spring Boot 2.0中启用hystrix.stream。当我尝试通过访问http:// localhost:8080 / hystrix.stream访问文件时,出现404文件未找到错误。
在控制器中调用的方法:
@GetMapping("/")
public Mono<String> index(Model model) {
model.addAttribute("images",
imageService
.findAllImages()
.map(image -> new HashMap<String, Object>() {{
put("id", image.getId());
put("name", image.getName());
put("imageComments", commentHelper.getComments(image));
}})
);
return Mono.just("index");
}
Run Code Online (Sandbox Code Playgroud)
CommentHelper代码,请注意正在使用@HystrixCommand:
@Component
public class CommentHelper {
private final RestTemplate restTemplate;
CommentHelper(RestTemplate restTemplate) {
this.restTemplate = restTemplate;
}
@HystrixCommand(fallbackMethod = "defaultComments")
public List<Comment> getComments(Image image) {
return restTemplate.exchange(
"http://COMMENTS/comments/{imageId}",
HttpMethod.GET,
null,
new ParameterizedTypeReference<List<Comment>>() {},
image.getId()).getBody();
}
public List<Comment> defaultComments(Image image) {
return Collections.emptyList();
}
}
Run Code Online (Sandbox Code Playgroud)
这些是来自build.gradle的依赖项: …
我有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)
我有下一个仪表板:
来自控制台的完整堆栈跟踪在这里。以下是一些代码段: …