1

我可以看到 hystrix 仪表板:http://localhost:8081/hystrix 我还看到我的电路中断和回退方法也可以正常工作但是我无法在http://localhost:8081/actuator/hystrix看到我的应用程序数据.stream 在此处输入图像描述 当我查看 /actuator/conditions 时,我看到 Hystrix 出现以下错误

"HystrixAutoConfiguration.HystrixServletAutoConfiguration": {
                    "notMatched": [
                        {
                            "condition": "OnClassCondition",
                            "message": "@ConditionalOnClass did not find required class 'com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet'"
                        }
                    ],
                    "matched": []
                }

代码 pom.xml

Spring Boot parent version : 2.2.6.RELEASE
Spring Cloud version : Hoxton.SR3
<dependencies>
   <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
   </dependency>
   <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
   </dependency>
</dependencies>

应用程序属性

management.endpoints.web.exposure.include = hystrix.stream, conditions

主应用

@SpringBootApplication
@EnableEurekaClient
@EnableCircuitBreaker
@EnableHystrixDashboard
@EnableHystrix
public class MovieCatalogServiceApplication {}

目录休息控制器

@RestController
@RequestMapping("/catalog")
public class CatalogRestController {

    @Autowired
    MovieInfoService movieInfo;

    @Autowired
    UserRatingsService userRatingInfo;


    @RequestMapping("/{userId}")
    public List<Catalog> getCatalogsByUserId(@PathVariable("userId") int userId){

        UserRatings ratings = userRatingInfo.getUserRating(userId);


        return ratings.getUserRatings().stream().map(oneOfRatings -> {
            return movieInfo.getCatalog(oneOfRatings);
            }).collect(Collectors.toList());

    }
}

用户评分服务

@Service
public class UserRatingsService {

    @Autowired
    private WebClient webClient;

    @HystrixCommand(fallbackMethod="getFallbackUserRating")
    public UserRatings getUserRating(int userId) {
        return webClient
                .get()
                .uri("http://user-rated-movies-service/ratingsdata/users/"+ userId)
                .retrieve()
                .bodyToMono(UserRatings.class)
                .block();
    }
    public UserRatings getFallbackUserRating(int userId) {
        UserRatings userRatings = new UserRatings();
        userRatings.setUserRatings(Arrays.asList(
                new Rating("0", "fallback method of user rating", 0)
                ));

        return userRatings;
    }
}
4

1 回答 1

0

您的 Hixtrix 端口是 8081,因此您需要在该 8081 端口上使用端点来进行指标工作。

例如

API-GATEWAY where Hystrix is used on port: 8081
USER-SERVICE port: 9001

问题:

API-GATEWAY - http://localhost:8081/acturator/hystrix.stream
USER-SERVICE save user - http://localhost:9001/user/ 

解决方案:

API-GATEWAY - http://localhost:8081/acturator/hystrix.stream
USER-SERVICE save user - http://localhost:8081/user/ 

指标现在运行良好,Hystrix Dashboard 可以正常运行。

于 2021-04-04T02:15:56.610 回答