spring cloud:hystrix-dashboard-turbine

hystrix-dashboard-turbine-server

1. File-->new spring starter project

2.add dependency

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
<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>

3.Edit application.yml

server:
  port: 9000

spring:
  application:
    name: hystrix-dashboard-turbine-server

turbine:
  app-config: hystrix-dashboard-client-node1,hystrix-dashboard-client-node2
  aggregator:
    cluster-config: default
  cluster-name-expression: new String("default")
eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka/

4.program

package com.smile;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.netflix.turbine.EnableTurbine;

@SpringBootApplication
@EnableHystrixDashboard
@EnableTurbine
@EnableEurekaClient
public class HystrixDashboardTurbineServerApplication {

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

}

5.Run

http://localhost:9000/hystrix

http://localhost:9000/turbine.stream  

由于是默认cluster,所以输入 http://localhost:9000/turbine.stream,click Monitor Stream

按照 hystrix-dashboard-client 分别创建 hystrix-dashboard-client-node1和 hystrix-dashboard-client-node2 修改如下

server:
  port: 9002
spring: application: name: hystrix
-dashboard-client-node1
server:
  port: 9003
spring: application: name: hystrix-dashboard-client-node2
package com.smile.remote;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @FeignClient(name = "producer",fallback = HelloServiceHystrix.class) public interface HelloService { @RequestMapping("/getHello") public String getHello1(@RequestParam String name); }
package com.smile.remote;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@FeignClient(name = "producer",fallback = HelloServiceHystrix.class)
public interface HelloService {
    
    @RequestMapping("/getHello")
    public String getHello2(@RequestParam String name);
}

将其它class中调用到getHello()的地方对应修改一下就可以了, 有时会出现监控不到的情况,需要请求以下该服务的actuator接口就可以了 such as: http://localhost:9003/actuator

此处只有一个 Thread Pools ,because just one producer

猜你喜欢

转载自www.cnblogs.com/alittlesmile/p/10896203.html