Spring Cloud监控页面打不开

之前没有使用rabbit来收集熔断器的信息时,没有问题,后来整合以后,发现了一个问题就是zipkinhystrix页面一直打不开,看了一下控制台发现资源文件一直处于加载中。
仔细一看请求返回的类型居然是:text/event-stream
然后访问了一下映射端点/actuator/mappings,发现映射的controllerTurbineController

下面是源码:

@RestController
public class TurbineController {
    private static final Log log = LogFactory.getLog(TurbineController.class);

    private final Flux<String> flux;

    public TurbineController(PublishSubject<Map<String, Object>> hystrixSubject) {
        Observable<Map<String, Object>> stream = StreamAggregator.aggregateGroupedStreams(hystrixSubject.groupBy(
                data -> InstanceKey.create((String) data.get("instanceId"))))
                .doOnUnsubscribe(() -> log.info("Unsubscribing aggregation."))
                .doOnSubscribe(() -> log.info("Starting aggregation")).flatMap(o -> o);
        Flux<Map<String, Object>> ping = Flux.interval(Duration.ofSeconds(5), Duration.ofSeconds(10))
                .map(l -> Collections.singletonMap("type", (Object) "ping"))
                .share();
        flux = Flux.merge(RxReactiveStreams.toPublisher(stream), ping)
                .share().map(map -> JsonUtility.mapToJson(map));
    }

    @GetMapping(produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<String> stream() {
        return this.flux;
    }
}

我们需要修改上面的映射:

// 继承
public class TurbineController extends org.springframework.cloud.netflix.turbine.stream.TurbineController {

	public TurbineController(PublishSubject<Map<String, Object>> hystrixSubject) {
		super(hystrixSubject);
	}

	@GetMapping(value = "/turbine.stream", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
	public Flux<String> stream() {
		return super.stream();
	}

}
// 在main方法启动类里面添加初始化
@Bean
public org.springframework.cloud.netflix.turbine.stream.TurbineController turbineController(PublishSubject<Map<String, Object>> hystrixSubject) {
	return new TurbineController(hystrixSubject);
}

完成上面的就可以看到映射改为了/turbine.stream了。