9

I cannot seem to find how to enable hystrix.stream in Spring Boot 2.0. When I try to access the file by going to http://localhost:8080/hystrix.stream I get a 404 file not found error.

Method called in the controller:

@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 code, note that @HystrixCommand is being used:

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

These are the dependencies from 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'
}

When I go to http://localhost:8080/application/features you can see that Hystrix is enabled as shown in the following:

{
    "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": []
}

What exactly is wrong here? If it helps, I'm trying to follow along with the code found here

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

As I'm going working my way through the book Learning Spring Boot 2nd Edition.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • Regarding the edit: questions that ask "please help me" tend to be looking for highly localized guidance, or in some cases, ongoing or private assistance, which is not suited to our Q&A format. It is also rather vague, and is better replaced with a more specific question. Please read [Why is “Can someone help me?” not an actual question?](//meta.stackoverflow.com/questions/284236/why-is-can-someone-help-me-not-an-actual-question). – halfer Jan 29 '18 at 11:13

3 Answers3

13
Ashutosh
  • 2,827
  • 2
  • 12
  • 11
  • Could you please guide me here: https://stackoverflow.com/questions/59738969/unable-to-connect-to-command-metric-stream-in-hystrix-dashboard-issue? – PAA Jan 15 '20 at 12:11
4

You need to include management.endpoints.web.exposure.include=* in application.properties according to this issue

samsong8610
  • 137
  • 1
  • 7
2

You need to add management.endpoints.web.base-path=/ in your application.properties. For example, check this out.

The path needs to be empty, so it registers correct as /actuator/hystrix.stream.

P3trur0
  • 3,155
  • 1
  • 13
  • 27
  • Could you please guide me here: https://stackoverflow.com/questions/59738969/unable-to-connect-to-command-metric-stream-in-hystrix-dashboard-issue ? – PAA Jan 15 '20 at 12:11