<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12
      云間錄  

      Dashboard演示的僅僅是單機(jī)服務(wù)監(jiān)控,實(shí)際項(xiàng)目基本都是集群,所以這里集群監(jiān)控用的是turbine

      turbine是基于Dashboard的。

       

      先搞個(gè)集群;

      microservice-student-provider-hystrix-1004項(xiàng)目的基礎(chǔ)上再搞一個(gè)microservice-student-provider-hystrix-1005

       

      代碼和配置都復(fù)制一份,然后修改幾個(gè)地方;

      yml配置:

       

      ---
      server:
        port: 1004
        context-path: /
      spring:
        datasource:
          type: com.alibaba.druid.pool.DruidDataSource
          driver-class-name: com.mysql.jdbc.Driver
          url: jdbc:mysql://localhost:3306/mybatis_ssm?useUnicode=true&characterEncoding=utf8
          username: root
          password: 123
        jpa:
          hibernate:
            ddl-auto: update
          show-sql: true
        application:
          name: microservice-student
        profiles: provider-hystrix-1004
      
      eureka:
        instance:
          hostname: localhost
          appname: microservice-student
          instance-id: microservice-student:1004
          prefer-ip-address: true
        client:
          service-url:
            defaultZone: http://eureka2001.lingerqi.com:2001/eureka/,http://eureka2002.lingerqi.com:2002/eureka/,http://eureka2003.lingerqi.com:2003/eureka/
      
      info:
        groupId: com.lingerqi.testSpringcloud
        artifactId: microservice-student-provider-hystrix-1004
        version: 1.0-SNAPSHOT
        userName: http://lingerqi.com
        phone: 123456
      
      hystrix:
        command:
          default:
            execution:
              isolation:
                thread:
                  timeoutInMilliseconds: 1500
      
      ---
      server:
        port: 1005
        context-path: /
      spring:
        datasource:
          type: com.alibaba.druid.pool.DruidDataSource
          driver-class-name: com.mysql.jdbc.Driver
          url: jdbc:mysql://localhost:3306/mybatis_ssm?useUnicode=true&characterEncoding=utf8
          username: root
          password: 123
        jpa:
          hibernate:
            ddl-auto: update
          show-sql: true
        application:
          name: microservice-student
        profiles: provider-hystrix-1005
      
      eureka:
        instance:
          hostname: localhost
          appname: microservice-student
          instance-id: microservice-student:1005
          prefer-ip-address: true
        client:
          service-url:
            defaultZone: http://eureka2001.lingerqi.com:2001/eureka/,http://eureka2002.lingerqi.com:2002/eureka/,http://eureka2003.lingerqi.com:2003/eureka/
      
      info:
        groupId: com.lingerqi.testSpringcloud
        artifactId: microservice-student-provider-hystrix-1005
        version: 1.0-SNAPSHOT
        userName: http://lingerqi.com
        phone: 123456
      
      hystrix:
        command:
          default:
            execution:
              isolation:
                thread:
                  timeoutInMilliseconds: 1500
      
      ---
      server:
        port: 1006
        context-path: /
      spring:
        datasource:
          type: com.alibaba.druid.pool.DruidDataSource
          driver-class-name: com.mysql.jdbc.Driver
          url: jdbc:mysql://localhost:3306/mybatis_ssm?useUnicode=true&characterEncoding=utf8
          username: root
          password: 123
        jpa:
          hibernate:
            ddl-auto: update
          show-sql: true
        application:
          name: microservice-student
        profiles: provider-hystrix-1006
      
      eureka:
        instance:
          hostname: localhost
          appname: microservice-student
          instance-id: microservice-student:1006
          prefer-ip-address: true
        client:
          service-url:
            defaultZone: http://eureka2001.lingerqi.com:2001/eureka/,http://eureka2002.lingerqi.com:2002/eureka/,http://eureka2003.lingerqi.com:2003/eureka/
      
      info:
        groupId: com.lingerqi.testSpringcloud
        artifactId: microservice-student-provider-hystrix-1006
        version: 1.0-SNAPSHOT
        userName: http://lingerqi.com
        phone: 123456
      
      hystrix:
        command:
          default:
            execution:
              isolation:
                thread:
                  timeoutInMilliseconds: 1500
      

       

        啟動(dòng)類(lèi)配置:

      package com.lingerqi.microservicestudentproviderhystrix;
      
      import org.springframework.boot.SpringApplication;
      import org.springframework.boot.autoconfigure.SpringBootApplication;
      import org.springframework.boot.autoconfigure.domain.EntityScan;
      import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
      import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
      
      @EnableCircuitBreaker
      @EntityScan("com.lingerqi.*.*")
      @EnableEurekaClient
      @SpringBootApplication
      public class MicroserviceStudentProviderHystrixApplication {
      
          public static void main(String[] args) {
              SpringApplication.run(MicroserviceStudentProviderHystrixApplication.class, args);
          }
      
      }

      這樣的話 就有了 hystrix集群服務(wù);

      我們新建項(xiàng)目microservice-student-consumer-hystrix-turbine-91

      新增pom.xml依賴(lài)

      <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-actuator</artifactId>
      </dependency>
      <dependency>
          <groupId>org.springframework.cloud</groupId>
          <artifactId>spring-cloud-starter-turbine</artifactId>
      </dependency>
      

        application.yml:

      server:
        port: 91
        context-path: /
      eureka:
        client:
          service-url:
            defaultZone: http://eureka2001.lingerqi.com:2001/eureka/,http://eureka2002.lingerqi.com:2002/eureka/,http://eureka2003.lingerqi.com:2003/eureka/
      turbine:
        app-config: microservice-student   # 指定要監(jiān)控的應(yīng)用名稱(chēng)
        clusterNameExpression: "'default'" #表示集群的名字為default
      spring:
        application:
          name: turbine

      新建啟動(dòng)類(lèi)MicroserviceStudentConsumerHystrixTurbine91Application 加注解:@EnableTurbine

      package com.lingerqi.microservicestudentconsumerhystrixturbine91;
      
      import org.springframework.boot.SpringApplication;
      import org.springframework.boot.autoconfigure.SpringBootApplication;
      import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
      import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
      import org.springframework.cloud.netflix.turbine.EnableTurbine;
      
      @SpringBootApplication(exclude={DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
      @EnableTurbine
      public class MicroserviceStudentConsumerHystrixTurbine91Application {
      
          public static void main(String[] args) {
              SpringApplication.run(MicroserviceStudentConsumerHystrixTurbine91Application.class, args);
          }
      
      }

      測(cè)試:

      啟動(dòng)三個(gè)eureka,然后把1004  1005 hystrix的服務(wù)都啟動(dòng);

       

      microservice-student-consumer-80這個(gè)也啟動(dòng),方便測(cè)試;

       

      dashboardturbine啟動(dòng);

      輸入http://localhost:90/hystrix進(jìn)入儀表盤(pán),輸入地址

       

       

       

      FeignHystrix整合

      前面的代碼,用@HystrixCommand fallbackMethod是很不好的,因?yàn)楹蜆I(yè)務(wù)代碼耦合度太高,不利于維護(hù),所以需要解耦,這我們講下Feign Hystrix整合。

      1、microservice-student-provider-hystrix項(xiàng)目修改

      我們不用原先那套。按照正常的邏輯來(lái)寫(xiě);

      StudentService加新的接口方法:

      /**
       * 測(cè)試Hystrix服務(wù)降級(jí)
       * @return
       */
      public Map<String,Object> hystrix();

      實(shí)現(xiàn)類(lèi):

      @Override
      public Map<String, Object> hystrix() {
          Map<String,Object> map=new HashMap<String,Object>();
          map.put("code", 200);
          map.put("info","工號(hào)【"+port+"】正在為您服務(wù)");
          return map;
      }

      StudentProviderController正常調(diào)用service方法:

      /**
           * 測(cè)試Hystrix服務(wù)降級(jí)
           * @return
           * @throws InterruptedException
           */
          @ResponseBody
          @GetMapping(value="/hystrix")
      //    @HystrixCommand(fallbackMethod="hystrixFallback")
          public Map<String,Object> hystrix() throws InterruptedException{
              Thread.sleep(100);
      //        Map<String,Object> map=new HashMap<String,Object>();
      //        map.put("code", 200);
      //        map.put("info","工號(hào)【"+port+"】正在為您服務(wù)");
              return this.studentService.hystrix();
          }
      
      //    public Map<String,Object> hystrixFallback() throws InterruptedException{
      //        Map<String,Object> map=new HashMap<String,Object>();
      //        map.put("code", 500);
      //        map.put("info", "系統(tǒng)【"+port+"】繁忙,稍后重試");
      //        return map;
      //    }
      

        

      microservice-common項(xiàng)目新建FallbackFactory類(lèi),解耦服務(wù)熔斷服務(wù)降級(jí)

      StudentClientService接口,新增getInfo方法;

       

      /**
       * 服務(wù)熔斷降級(jí)
       * @return
       */
      @GetMapping(value="/student/hystrix")
      public Map<String,Object> hystrix();

      新建 StudentClientFallbackFactory 類(lèi),實(shí)現(xiàn)FallbackFactory<StudentClientService>接口;

       

      package com.lingerqi.microservicecommon.service;
      
      import com.lingerqi.microservicecommon.entity.Student;
      import feign.hystrix.FallbackFactory;
      import org.springframework.stereotype.Component;
      
      import java.util.HashMap;
      import java.util.List;
      import java.util.Map;
      
      @Component
      public class StudentClientFallbackFactory implements FallbackFactory<StudentClientService> {
      
          @Override
          public StudentClientService create(Throwable cause) {
              return new StudentClientService() {
      
                  @Override
                  public boolean save(Student student) {
                      return false;
                  }
      
                  @Override
                  public List<Student> list() {
                      return null;
                  }
      
                  @Override
                  public Map<String, Object> hystrix() {
                      Map<String,Object> map=new HashMap<String,Object>();
                      map.put("code", 500);
                      map.put("info", "系統(tǒng)繁忙,稍后重試");
                      return map;
                  }
      
                  @Override
                  public Student get(Integer id) {
                      return null;
                  }
      
                  @Override
                  public boolean delete(Integer id) {
                      return false;
                  }
      
                  @Override
                  public String ribbon() {
                      return null;
                  }
              };
          }
      
      }

      StudentClientService接口的@FeignClient注解加下 fallbackFactory屬性

       

      @FeignClient(value="MICROSERVICE-STUDENT",fallbackFactory=StudentClientFallbackFactory.class)

      microservice-student-consumer-feign-80修改 支持Hystrix

      StudentConsumerFeignController新增方法調(diào)用

       

      /**
       * Feign整合Hystrix服務(wù)熔斷降級(jí)
       * @return
       * @throws InterruptedException
       */
      @GetMapping(value="/hystrix")
      public Map<String,Object> hystrix() throws InterruptedException{
          return studentClientService.hystrix();
      }

      microservice-student-consumer-feign-80application.yml加上hystrix支持

       

      feign:
        hystrix:
          enabled: true
      

       

        

      1、microservice-student-consumer-feign-80啟動(dòng)類(lèi)上添加公共模塊

      @ComponentScan(basePackages = {"com.lingerqi.microservicecommon","com.lingerqi.microservicestudentconsumerfeign80"})

      注意:

      1、公共子項(xiàng)目與當(dāng)前子項(xiàng)目的基包都要掃描到;

      2、只指定公共子模塊為基包會(huì)導(dǎo)致本子項(xiàng)目的springmvc功能失效;

      3、只指定本子項(xiàng)目為基包會(huì)導(dǎo)致feignHystrix集成失敗,從而導(dǎo)致服務(wù)熔斷功能失效

       

      package com.lingerqi.microservicestudentconsumerfeign80;
      
      import org.springframework.boot.SpringApplication;
      import org.springframework.boot.autoconfigure.SpringBootApplication;
      import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
      import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
      import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
      import org.springframework.cloud.netflix.feign.EnableFeignClients;
      import org.springframework.context.annotation.ComponentScan;
      
      @ComponentScan(basePackages = {"com.lingerqi.microservicecommon","com.lingerqi.microservicestudentconsumerfeign80"})//掃描公共模塊
      @EnableFeignClients(value = "com.lingerqi.*.*")
      @EnableEurekaClient
      @SpringBootApplication(exclude={DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
      public class MicroserviceStudentConsumerFeign80Application {
      
          public static void main(String[] args) {
              SpringApplication.run(MicroserviceStudentConsumerFeign80Application.class, args);
          }
      
      }
      

       

        

      測(cè)試開(kāi)啟三個(gè)eureka,以及帶hystrixprovider,和帶feign,hystrixconsummer

       

       

      集群后超時(shí)設(shè)置

      這里因?yàn)檫€有一個(gè) feign 也有一個(gè)超時(shí)時(shí)間的設(shè)置,當(dāng)然feign底層是 ribbon的封裝,所以 直接配置ribbon,ribbon默認(rèn)超時(shí)也是1秒。

      所以這里都是強(qiáng)制要求,ribbon的超時(shí)時(shí)間要大于hystrix的超時(shí)時(shí)間,否則 hystrix自定義的超時(shí)時(shí)間毫無(wú)意義。

      所以還得microservice-student-consumer-feign-80上加個(gè) ribbon超時(shí)時(shí)間設(shè)置

      ribbon:
        ReadTimeout: 10000
        ConnectTimeout: 9000

      這樣就完工了

       

       

       

       

       

       

       

       

       

      posted on 2019-12-10 23:34  云間錄  閱讀(270)  評(píng)論(0)    收藏  舉報(bào)
       
      主站蜘蛛池模板: 亚洲欧洲美洲在线观看| 成人片在线看无码不卡| 国产精品午夜福利合集| 色综合天天色综合久久网| 东京热一精品无码av| 国产麻豆md传媒视频| 国产亚洲精品日韩av在| 亚洲无人区一区二区三区| 99久久免费精品色老| 猫咪AV成人永久网站在线观看 | 国产午夜精品福利视频| 国产精品线在线精品| 5555国产在线观看| 国产精品成人中文字幕| 亚洲欧美日韩综合久久| 国产精品 自在自线| 久久久久国产精品熟女影院| 欧美国产亚洲日韩在线二区| 日本高清在线观看WWW色| 国产大学生粉嫩无套流白浆 | 久久夜色撩人国产综合av| 国产精品理论片在线观看| 亚洲理论在线A中文字幕| 久久伊99综合婷婷久久伊| 亚洲国产精品嫩草影院久久| 瑞昌市| 蜜臀午夜一区二区在线播放| 99久久国产成人免费网站| 国产精品视频一区二区三区不卡| 国产精品呻吟一区二区三区| 国产精品中文字幕久久| 亚洲欧洲日产国码无码久久99| 一区二区三区日本久久九| 亚洲综合在线日韩av| 情欲少妇人妻100篇| 国产一区二区不卡视频在线| 免费午夜无码片在线观看影院| 工布江达县| 亚洲中文字幕在线无码一区二区| 亚洲一区中文字幕人妻| 邵东县|