Ich bin neu in Hystrix Dashboard. Ich habe eine Beispielanwendung mit Hystrix geschrieben. Ich möchte das Hystrix-Diagramm (Befehlsmetrikstream) sehen. Aber ich bekomme den folgenden Fehler:Hystrix Dashboard Ausgabe im Frühjahr Boot
Circuit: Unable to connect to Command Metric Stream
Thread Pools: Loading...
Ich verwende STS mit Maven.
Unten finden Sie den Code verwendet:
Einfache Server Micro Anwendung
package hello;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
@RestController
@SpringBootApplication
public class BookstoreApplication {
@RequestMapping(value = "/recommended")
public String readingList(){
return "Spring in Action (Manning), Cloud Native Java (O'Reilly), Learning Spring Boot (Packt)";
}
public static void main(String[] args) {
SpringApplication.run(BookstoreApplication.class, args);
}
}
Einfache Client Micro Anwendung (Frühjahr Boot-Bahnlauf in Port 8095) Ich habe (Frühjahr Boot-Bahn in Port 8085 ausgeführt wird) enthalten die Abhängigkeit von Hystrix und Hystrix-Dashboard zusammen mit Web, so dass die alle Hystrix Abhängigkeiten sind in classpath
package hello;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import java.net.URI;
@Service
public class BookService {
private final RestTemplate restTemplate;
public BookService(RestTemplate rest) {
this.restTemplate = rest;
}
@HystrixCommand(fallbackMethod = "reliable")
public String readingList() {
URI uri = URI.create("http://localhost:8090/recommended");
return this.restTemplate.getForObject(uri, String.class);
}
public String reliable() {
return "Cloud Native Java (O'Reilly)";
}
}
package hello;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.web.client.RestTemplate;
@EnableHystrixDashboard
@EnableHystrix
@EnableCircuitBreaker
@RestController
@SpringBootApplication
public class ReadingApplication {
@Autowired
private BookService bookService;
@Bean
public RestTemplate rest(RestTemplateBuilder builder) {
return builder.build();
}
@RequestMapping("/to-read")
public String toRead() {
return bookService.readingList();
}
public static void main(String[] args) {
SpringApplication.run(ReadingApplication.class, args);
}
}
Durch den obigen Code ausgeführt wird, Die Hystrix funktioniert gut, wenn die BooKStoreApplication heruntergefahren ist, wird es eine Fallback-Methode geben.
Beide URLs funktionieren einwandfrei. Normalfall:
http://localhost:8085/recommended
Output: Spring in Action (Manning), Cloud Native Java (O'Reilly), Learning Spring Boot (Packt)
http://localhost:8095/to-read
Output: Spring in Action (Manning), Cloud Native Java (O'Reilly), Learning Spring Boot (Packt)
When BookStoreApplication is down (http://localhost:8085/recommended) accessing http://localhost:8095/to-read returns "Cloud Native Java (O'Reilly)" as expected.
Aber wenn ich diese URL http://localhost:8095/hystrix aufzurufen versucht, erhalte ich die Hystrix Dashboardseite und für den Stream Wert zu fragen.
Ich habe versucht, http://localhost:8095/ oder http://localhost:8095/to-read gegeben, und angeklickt „Monitor-Stream“ und es wird zur nächsten Seite mit Fehler gehen:
Circuit: Unable to connect to Command Metric Stream
Thread Pools: Loading...