Невозможно подключиться к командному метрическому потоку в Spring Cloud + Hystrix + Turbine - MIME-тип («text / plain»), который не является «text / event-stream» - PullRequest
0 голосов
/ 02 сентября 2018

Я уже прошел по ссылке: Невозможно подключиться к Command Metric Stream для Hystrix Dashboard с Spring Cloud и перепробовал несколько вариантов, но пока ничего не получалось. Я занимаюсь разработкой Spring Cloud Code + Hystrix + Turbine .

Не могли бы вы сообщить мне, в чем проблема? Я использую Spring Boot v2.0.4.RELEASE.

enter image description here

enter image description here

HystrixDashboardApplication.java

@EnableTurbine
@EnableHystrixDashboard
@SpringBootApplication
public class HystrixDashboardApplication {

    public static void main(String[] args) {
        SpringApplication.run(HystrixDashboardApplication.class, args);
    }
}

pom.xml

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <spring-cloud.version>Finchley.SR1</spring-cloud.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-turbine</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

tollrate-billboard приложение имеет следующий код TollrateBillboardApplication.java

@EnableCircuitBreaker
@SpringBootApplication
@EnableEurekaClient
public class TollrateBillboardApplication {

    public static void main(String[] args) {
        SpringApplication.run(TollrateBillboardApplication.class, args);
    }
}

DashboardController.java

@Controller
public class DashboardController {

    @LoadBalanced
    @Bean
    public RestTemplate restTemplate(RestTemplateBuilder builder) {
        return builder.build();
    }

    @Autowired
    private RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "getTollRateBackup")
    @RequestMapping("/dashboard")
    public String GetTollRate(@RequestParam int stationId, Model m) {

        TollRate tr = restTemplate.getForObject("http://pluralsight-toll-service/tollrate/" + stationId, TollRate.class);
        System.out.println("stationId: " + stationId);
        m.addAttribute("rate", tr.getCurrentRate());
        return "dashboard";
    }

    public String getTollRateBackup(@RequestParam int stationId, Model m) { 
        System.out.println("Fallback operation called");
        m.addAttribute("rate", "1.00");
        return "dashboard";
    }
}

bootstrap.properties

spring.application.name=pluralsight-tollrate-billboard

application.properties

server.port=8082
# eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true

#http://cloud.spring.io/spring-cloud-static/Finchley.RELEASE/single/spring-cloud.html#_environment_changes
management.endpoints.web.exposure.include=hystrix.stream

Результат команды CURL:

curl "http://localhost:8085/clusters"

выход

[
    {
        "name": "PLURALSIGHT-FASTPASS-CONSOLE",
        "link": "http://localhost:8085/turbine.stream?cluster=PLURALSIGHT-FASTPASS-CONSOLE"
    },
    {
        "name": "PLURALSIGHT-TOLLRATE-BILLBOARD",
        "link": "http://localhost:8085/turbine.stream?cluster=PLURALSIGHT-TOLLRATE-BILLBOARD"
    }
]

РЕДАКТИРОВАТЬ-1 :: , я использую "Hystrix-турбина"

@EnableTurbineStream
@SpringBootApplication
public class HystrixTurbineApplication {

    public static void main(String[] args) {
        SpringApplication.run(HystrixTurbineApplication.class, args);
    }
}

Теперь я получаю ошибку ниже:

2018-09-03 22:23:45.808  WARN 2820 --- [nio-8085-exec-5] ashboardConfiguration$ProxyStreamServlet : Failed opening connection to http://localhost:8085/turbine.stream?cluster=PLURALSIGHT-FASTPASS-CONSOLE : 404 : HTTP/1.1 404 
2018-09-03 22:23:45.808  WARN 2820 --- [nio-8085-exec-2] ashboardConfiguration$ProxyStreamServlet : Failed opening connection to http://localhost:8085/turbine.stream?cluster=PLURALSIGHT-FASTPASS-CONSOLE : 404 : HTTP/1.1 404 

1 Ответ

0 голосов
/ 05 сентября 2018

@ Sayali Я попытался воссоздать ошибку в моей собственной системе, и мне удалось заставить ее работать, вот несколько проверок, которые вы можете сделать:

1) URL на вашем первом скриншоте неверен. URL вашего потока в панели инструментов Hystrix должен быть:

http://localhost:8085/turbine.stream?cluster=PLURALSIGHT-TOLLRATE-BILLBOARD

URL должен указывать на порт приложения панели мониторинга, в котором есть аннотация @EnableTurbine в вашем основном классе.

2) Проверьте, получаете ли вы ответ для:

http://localhost:8082/actuator/hystrix.stream

(используйте ваш браузер для этого) (это должно происходить из приложения, которое вы включили в Hystrix при использовании @EnableCircuitBreaker)

Если вы получаете эхо-запросы, то по крайней мере ваш поток Hystrix доступен. Если не, Проверьте, есть ли у вас: org.springframework.boot:spring-boot-starter-actuator в зависимостях и
убедитесь, что у вас установлено свойство ниже в файле application.properties приложения, которое имеет @EnableCircuitBreaker в основном классе:

management.endpoints.web.exposure.include= hystrix.stream, info, health

Проверьте URL еще раз.

3) Перед тем, как перейти к потокам турбины, приведите в действие турбинную секцию, поэтому на данный момент вы можете внести следующие изменения:

@EnableTurbine // instead of @EnableTurbineStream
@SpringBootApplication
public class HystrixTurbineApplication {

    public static void main(String[] args) {
        SpringApplication.run(HystrixTurbineApplication.class, args);
    }
}

Также для использования TurbineStream:

Возможно, вы захотите, чтобы ваши команды Hystrix передавали метрики в Turbine. Spring Cloud позволяет это с помощью обмена сообщениями. Чтобы сделать это на клиенте, добавьте зависимость от Spring-Cloud-Netflix-Hystrix-Stream и тому Spring-Cloud-Starter-Stream- * на ваш выбор.

см .: http://cloud.spring.io/spring-cloud-static/Finchley.SR1/single/spring-cloud.html#_turbine_stream

Надеюсь, это поможет. Пожалуйста, прокомментируйте, чтобы помочь мне узнать, сработало ли это для вас.

...