zoukankan      html  css  js  c++  java
  • spring cloud:HystrixDashboard

     hystrix-dashboard-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>

    3.Edit application.yml

    server:
      port: 9000
      
    spring:
      application:
        name: hystrix-dashboard-server
    
    #    
    #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.boot.web.servlet.ServletRegistrationBean;
    import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
    import org.springframework.context.annotation.Bean;
    
    import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
    
    @SpringBootApplication
    @EnableHystrixDashboard
    public class HystrixDashboardServerApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(HystrixDashboardServerApplication.class, args);
        }
    
    }

    5.Run

    visit :  http://localhost:9000/hystrix 

    输入要监控的地址 http://localhost:9001/actuator/hystrix.stream 点击 monitor

     

    hystrix-dashboard-client

    
    

    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-eureka-client</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
            <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
                </artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-openfeign</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-devtools</artifactId>
            </dependency>
    
    

    3.Edit application.yml

    server:
      port: 9001
    spring:
      application:
        name: hystrix-dashboard-client
    
    eureka:
      client:
        service-url:
          defaulZone: http://localhost:8761/eureka/
          
    management:
      endpoints:
        web:
          exposure:
            include: '*'
    
    feign:
      hystrix:
        enabled: true

    4.program

    package com.smile;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
    import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
    import org.springframework.cloud.openfeign.EnableFeignClients;
    
    @SpringBootApplication
    @EnableEurekaClient
    @EnableFeignClients
    @EnableCircuitBreaker    //开启断路器,否则监控不到
    public class HystrixDashboardClientApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(HystrixDashboardClientApplication.class, args);
        }
    
    }
    package com.smile.controller;
    
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.web.bind.annotation.PathVariable;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    import com.smile.remote.HelloService;
    
    
    @RestController
    public class ConsumerController {
    
        @Autowired
        HelloService helloService;
    
        @RequestMapping("/hello/{name}")
        public String helloConsumer(@PathVariable("name") String name) {
            return helloService.getHello(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 getHello(@RequestParam String name);
    }
    package com.smile.remote;
    
    import org.springframework.stereotype.Component;
    
    @Component
    public class HelloServiceHystrix implements HelloService{
    
        @Override
        public String getHello(String name) {
            return "hello "+name+",this is hystrix!";
        }
    
    }

    5.Run

    visit: http://localhost:9001/hello/smile

       hello smile

       停止producer 再次访问 http://localhost:9001/hello/smile

     hello smile,this is hystrix!

    监控也会监控到hystrix

    hystrix-dashboard 就到这里了

  • 相关阅读:
    (四)rsync未授权访问
    (前言一)HTTP报文
    (一)会话固定攻击
    使用Burp、PhantomJS进行XSS检测
    win10配置环境变量
    java学习网站http://how2j.cn/
    镜像下载
    jQuery
    jQuery
    jQuery
  • 原文地址:https://www.cnblogs.com/alittlesmile/p/10895597.html
Copyright © 2011-2022 走看看