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 就到这里了

  • 相关阅读:
    Linux pytorch安装 cuda,torch,torchvision版本选择
    R 语言 缺失值处理并使用SMOTE处理不平衡数据集
    Unable to fit model using “lrm.fit” in R
    Linux系统安装软件(搜狗拼音,teamviewer等)
    win10+anaconda3+pytorch安装
    支持向量机理论+R语言实现
    算法学习:给定一个序列求最大子序列的和
    13 HTTP传输大文件的方法
    12 HTTP的实体数据
    11 HTTP的特点,优点和缺点
  • 原文地址:https://www.cnblogs.com/alittlesmile/p/10895597.html
Copyright © 2011-2022 走看看