如何在独立的Turbine应用程序中激活/turbine.stream端点

时间:2018-08-28 14:47:54

标签: spring spring-boot spring-cloud spring-cloud-netflix

我正在尝试创建一个独立的应用程序以从其他应用程序收集Hystrix流。但是默认情况下它不会公开 /turbine.stream 端点。我确定我的项目中缺少什么。

Spring Boot:2.0.4.RELEASE,Spring Cloud:Finchley.SR1

应用程序类:

import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class Main extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {

        // Build a simple UI
        VBox root = new VBox(5);
        root.setPadding(new Insets(10));
        root.setAlignment(Pos.CENTER);

        // Create a list of Chess pieces
        ObservableList<ChessPiece> chessPieces = FXCollections.observableArrayList();

        // Add a sample Chess piece, a queen in this case
        chessPieces.add(new ChessPiece(
                "Queen",
                new ImageView("sample/listViewImages/queen.png"),
                0
        ));

        // Create the ListView
        ListView<ChessPiece> lvChessPieces = new ListView<>();

        // Setup the CellFactory
        lvChessPieces.setCellFactory(listView -> new ListCell<ChessPiece>() {
            @Override
            protected void updateItem(ChessPiece piece, boolean empty) {
                super.updateItem(piece, empty);

                if (empty) {
                    setGraphic(null);
                } else {

                    // Create a HBox to hold our displayed value
                    HBox hBox = new HBox(5);
                    hBox.setAlignment(Pos.CENTER);

                    // Add the values from our piece to the HBox
                    hBox.getChildren().addAll(
                            piece.getImage(),
                            new Label(piece.getName()),
                            new Label("x " + piece.getCount())
                    );

                    // Set the HBox as the display
                    setGraphic(hBox);
                }
            }
        });

        // Bind our list of pieces to the ListView
        lvChessPieces.setItems(chessPieces);

        // Create a button to add change the Queen count
        Button button = new Button("Add a Queen");
        button.setOnAction(e -> {
            // Get the queen from the list of Chess Pieces. For this sample we only have one piece in our List,
            // but in a real application, you'll need to build a method for retrieving the correct piece.
            ChessPiece queen = chessPieces.get(0);
            queen.setCount(queen.getCount() + 1);

            // Refresh the ListView to show the updated counts
            lvChessPieces.refresh();
        });

        root.getChildren().addAll(lvChessPieces, button);
        primaryStage.setScene(new Scene(root));

        primaryStage.show();
    }
}

/**
 * Defines a Chess piece, including it's name, image, and current count
 */
class ChessPiece {

    private final String name;
    private final ImageView image;
    private int count;

    public ChessPiece(String name, ImageView image, int count) {
        this.name = name;
        this.image = image;
        this.count = count;

        // Resize the image, if necessary
        this.image.setFitHeight(25);
        this.image.setFitWidth(20);

    }

    public String getName() {
        return name;
    }

    public ImageView getImage() {
        return image;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }
}

applicaiton.yml的内容:

@SpringBootApplication
@EnableDiscoveryClient
@EnableTurbine
public class DemoApplication {

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

}

与Maven的依赖关系:

server:
  port: 8383
spring:
  application:
    name: hystrix-turbine

management:
  endpoints:
    web.exposure.include: '*'
applications: hystrix
turbine:
  aggregator:
    clusterConfig: ${applications}
  appConfig: ${applications}
#  instanceUrlSuffix.default: actuator/hystrix.stream

我为此创建了一个sample project

1 个答案:

答案 0 :(得分:2)

建议您检查以下配置步骤:

1)您在Hystrix信息中心中的流URL应为:

http://localhost:{turbine app port}/turbine.stream?cluster={configured cluster in properties file}

该网址应指向主类中带有@EnableTurbine批注的应用程序端口。

2)检查您是否收到以下答复:

http://localhost:{client app port}/actuator/hystrix.stream

(为此使用浏览器)(这应该来自您在使用@EnableCircuitBreaker时启用了hystrix的应用程序)

如果您收到ping命令,则至少可以访问hystrix流。如果不是,请检查客户端依赖项中是否有org.springframework.boot:spring-boot-starter-actuator,并且 确保在主类中具有@EnableCircuitBreaker的应用程序的application.properties文件中设置了以下属性:

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

再次检查URL。

3)一旦收到hystrix.stream的回复,您现在就可以在涡轮机应用程序属性文件中配置集群了:

turbine:

      appConfig: {serviceId in lower case}
      aggregator:
        clusterConfig: {above serviceId in upper case} 

运行该应用程序后,检查是否已正确配置集群:

http://localhost:{turbine app port}/clusters

如果一切正常,您不应在浏览器上看到“ []”。

在集群端点上看到响应后,现在您可以在将仪表板指向涡轮应用程序时在仪表板上查看详细信息