当前位置: 首页 > 知识库问答 >
问题:

如何在Spring Boot2.0中启用“hystrix.stream”?

辛承志
2023-03-14

我似乎找不到如何在Spring Boot2.0中启用hystrix.stream。当我尝试通过http://localhost:8080/hystrix.stream访问该文件时,我得到一个404 file not found错误。

在控制器中调用的方法:

@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");
}

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();
    }
}

这些是build.gradle中的依赖项:

dependencies {
    compile 'org.springframework.boot:spring-boot-starter-webflux'
    compile 'org.synchronoss.cloud:nio-multipart-parser'
    compile 'org.springframework.boot:spring-boot-starter-data-mongodb-reactive'
    compile 'org.springframework.boot:spring-boot-starter-thymeleaf'
    compile 'org.springframework.boot:spring-boot-starter-actuator'
    compile 'org.springframework.boot:spring-boot-devtools'

    compile 'org.springframework.cloud:spring-cloud-starter-stream-rabbit'
    compile 'org.springframework.cloud:spring-cloud-stream-reactive'

    compile 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
    compile 'org.springframework.cloud:spring-cloud-starter-netflix-hystrix'

    testCompile 'org.springframework.boot:spring-boot-starter-test'
    testCompile 'io.projectreactor:reactor-test'

    compile 'junit:junit:4.12'
}

当我转到http://localhost:8080/application/features时,您可以看到Hystrix已启用,如下所示:

{
    "enabled": [
        {
            "type": "com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect",
            "name": "Hystrix",
            "version": "1.5.12",
            "vendor": null
        },
        {
            "type": "com.netflix.discovery.EurekaClient",
            "name": "Eureka Client",
            "version": "1.8.4",
            "vendor": null
        },
        {
            "type": "org.springframework.cloud.client.discovery.composite.CompositeDiscoveryClient",
            "name": "DiscoveryClient",
            "version": "2.0.0.M3",
            "vendor": "Pivotal Software, Inc."
        },
        {
            "type": "org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient",
            "name": "LoadBalancerClient",
            "version": "2.0.0.M3",
            "vendor": "Pivotal Software, Inc."
        },
        {
            "type": "com.netflix.ribbon.Ribbon",
            "name": "Ribbon",
            "version": "2.2.2",
            "vendor": null
        }
    ],
    "disabled": []
}

这里到底出了什么问题?如果有帮助的话,我会试着跟着这里找到的代码走

https://github.com/learning-spring-boot/learning-spring-boot-2nd-edition-code/tree/master/7/part2

因为我正在学习我的方式通过这本书学习Spring靴第二版。

共有1个答案

缪风史
2023-03-14
  • 使用@enablehystrixdashboard添加@enablehystrix批注。
  • 在Application.Properties中添加Management.Endpoints.Web.Exposure.Include=*
  • 可在http://localhost:8080/hystrix访问Hystrix仪表板。
  • 在Hystrix stream URL输入中输入http://localhost:8080/acture/Hystrix.stream。
 类似资料:
  • 我似乎找不到如何在Spring Boot2.0中启用hystrix.stream。当我尝试通过http://localhost:8080/hystrix.stream访问该文件时,我得到一个404 file not found错误。 在控制器中调用的方法: CommentHelper代码,请注意正在使用@hystrixcommand: 这些是build.gradle中的依赖项: 当我转到http:

  • 问题内容: 尝试执行以下行时,仅显示最后两个语句(“ Here is some ERROR”和“ Here is some FATAL”),并且不显示前三个语句。我刚刚开始学习此主题,任何人都可以告诉为什么会这样呢? log4j.property有 问题答案: 您可能在项目中的某个地方有一个log4j.properties文件。在该文件中,您可以配置所需的调试输出级别。请参阅以下示例: 第一行将根

  • 问题内容: 我使用Flickr照片搜索API的JavaScript创建了一个演示。现在,我将其转换为AngularJs。我在互联网上搜索,发现下面的配置。 组态: 服务: 控制器: 问题答案: 你不知道 您请求的服务器必须实现CORS才能从您的网站访问权限中授予JavaScript。您的JavaScript无法授予自己访问其他网站的权限。

  • 问题内容: 标题说说我的问题。我需要将DTO包装到javascript方法回调中。目前,我应要求返回JSON。但是在Ajax中使用此问题,因为我将GET发送到其他域。当然还有治安警察。 我有创建附加提供的想法。有任何示例,链接或建议如何执行。 问题答案: RESTEasy中没有明确支持JSONP,但是在应用程序中启用JSONP的一种简单方法是编写Servlet过滤器。 这里有一些链接可以帮助您编写

  • 问题内容: 我正在尝试使用jquery提出跨源请求,但它一直被消息拒绝 XMLHttpRequest无法加载http:// …请求的资源上不存在“ Access-Control-Allow-Origin”标头。因此,不能访问Origin…。 我正在使用flask,heroku和jquery 客户端代码如下所示: 在heroku方面,我正在使用flask,就像这样 问题答案: 当我部署到Heroku

  • 问题内容: 当我在MySQL中执行查询时,它返回一条错误消息,说明未启用InnoDB。当我单击存储引擎时,InnoDB被禁用。 如何启用InnoDB? 问题答案: 您需要在文件中启用它,然后重新启动服务器: http://dev.mysql.com/doc/refman/5.1/zh-CN/innodb- parameters.html#option_mysqld_innodb 或者,您可以在运行