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

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

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

      小雞炸

      導航

      SpringCloud學習筆記2

      一、Ribbon實現客戶端的負載均衡【只支持2.3版本即以下、過渡性知識點】

      Ribbon:一個服務集群多個、Ribbon來決定選擇調用哪一個(負載均衡)、使用了Feign就不用使用Ribbon了

      1、創建項目選擇以下組件:SpringBoot DevTools、Eureka Discovery Client、Ribbon、Spring Web

      2、添加配置信息

      # 設置服務端口
      server.port=8881
      #  設置服務名 可以相同、相同則為后面的負載均衡準備
      spring.application.name=hello-service
      #  設置注冊中心地址
      eureka.client.service-url.defaultZone=http://localhost:7777/eureka
      

      3、在啟動類配置RestTemplate

      //@EnableDiscoveryClient向服務中心注冊,并且注冊了一個叫restTemplate的bean。
      @SpringBootApplication
      @EnableDiscoveryClient
      public class ServiceRibbonApplication {
          public static void main(String[] args) {
              SpringApplication.run(ServiceRibbonApplication.class, args);
          }
          
          //@LoadBalanced注冊表明,這個restRemplate是需要做負載均衡的。
          @Bean
          @LoadBalanced
          RestTemplate restTemplate() {
              return new RestTemplate();
          }
      }
      

      4、Controller使用RestTemplate調用其他服務實現負載均衡

      @RestController
      @RequestMapping("/classes")
      public class ClassesController {
      	//restTemplate對象自帶負載均衡的調用客戶端對象
          @Autowired RestTemplate restTemplate;
      	
      	@RequestMapping("/index001")
      	public String index001() {
      		return "client002-classes-index001"+restTemplate.getForObject("http://service001/student/index001",String.class);
      	}
      }
      

      二、Hystrix斷路器(熔斷)

      1、Hystrix介紹:有3個服務、當Feign在三個中選一個時、假如選得2號、但2號這時候恰好宕機了、此時就屬于斷路

      是什么?hystrix對應的中文名字是“豪豬”,豪豬周身長滿了刺,能保護自己不受天敵的傷害,代表了一種防御機制,這與hystrix本身的功能不謀而合,因此Netflix團隊將該框架命名為Hystrix,并使用了對應的卡通形象做作為logo。
      
      為什么要使用?在一個分布式系統里,許多依賴不可避免的會調用失敗,比如超時、異常等,如何能夠保證在一個依賴出問題的情況下,不會導致整體服務失敗,這個就是Hystrix需要做的事情。Hystrix提供了熔斷、隔離、Fallback、cache、監控等功能,能夠在一個、或多個依賴同時出現問題時保證系統依然可用。
      

      2、添加依賴jar包

      <dependency>
      	<groupId>org.springframework.cloud</groupId>
      	<artifactId>spring-cloud-starter-hystrix</artifactId>
      	<version>1.4.0.RELEASE</version>
      </dependency>
      

      3、Controller配置斷熔

      @RestController
      @RequestMapping("/hystrix")
      public class HystrixController {
      	//restTemplate對象自帶負載均衡的調用客戶端對象、或者直接使用Feign
          @Autowired RestTemplate restTemplate;
      
          @RequestMapping("/test")
          //當請求的地址出現錯誤、執行error方法、如果test執行超過2秒或拋出異常皆會被斷路
          @HystrixCommand(fallbackMethod = "error")
          public String test(String name) throws Exception{
          	if (1==1)
          		throw new Exception("error");
          	 return restTemplate.postForObject("http://server001/student/method002",null,String.class);
          }
          //異常也會被斷路
          public String error(String name,Throwable e) {
          	return e.getMessage()+name;
          }
      }
      

      4、啟動類添加斷熔注解

      @SpringBootApplication
      @EnableDiscoveryClient
      //允許斷路器
      @EnableCircuitBreaker
      public class RibbonApplication {
          public static void main(String[] args) {
              SpringApplication.run(RibbonApplication.class, args);
          }
      }
      

      三、Zuul網關配置、新版本請使用gateway

      1、作用:反向代理+負載均衡+限流

      限流需要單獨添加jar包

      
      

      2、添加依賴jar包

      	<dependency>
      			<groupId>org.springframework.boot</groupId>
      			<artifactId>spring-boot-starter-web</artifactId>
      		</dependency>
      		<dependency>
      			<groupId>org.springframework.cloud</groupId>
      			<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
      		</dependency>
      		<dependency>
      			<groupId>org.springframework.cloud</groupId>
      			<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
      		</dependency>
      <!--限流的jar包、需要手動導入-->
      	<dependency>
      		<groupId>com.marcosbarbero.cloud</groupId>
      		<artifactId>spring-cloud-zuul-ratelimit</artifactId>
      		<version>2.0.0.RELEASE</version>
      	</dependency>
      		<dependency>
      			<groupId>org.springframework.boot</groupId>
      			<artifactId>spring-boot-devtools</artifactId>
      			<scope>runtime</scope>
      			<optional>true</optional>
      		</dependency>
      

      3、配置網關

      #注冊中心地址
      eureka.client.serviceUrl.defaultZone=http://localhost:7777/eureka/
      #服務端口
      server.port=8888
      #我在注冊中心的網關名稱
      spring.application.name=zuul001
      
      
      # 如:server001有個服務:http://localhost:8001/student/method001
      # 配置下面網關后用戶訪問 http://localhost:8888/zuul/student/method001、和上面的路徑一摸一樣
      # 網關配置 zuul.routes.任意名[亦可位服務名].path:、如果service-id相同則帶負載均衡1
      zuul.routes.abc.path= /abc/**
      zuul.routes.abc.service-id= CLIENT002
      # 上面可簡寫zuul.routes.servere001.path=/aaa/**	第一個字不能是zuul
      # 如果是zuul.routes.servere001= 等同于 zuul.routes.clie.path=/servere001/**
      
      ## 開啟限流、針對單個服務
      zuul.ratelimit.enabled=true
      # 60秒內請求超過3次、服務端就拋出異常、60s后可以恢復正常請求
      zuul.ratelimit.policies.abc.limit=3
      zuul.ratelimit.policies.abc.refresh-interval=60
      ## 針對某個IP進行限流、不影響其他IP
      ## zuul.ratelimit.policies.abc.type=ip地址
      
      
      # 開啟全局限流
      # zuul.ratelimit.enabled=true
      # zuul.ratelimit.default-policy.limit=3
      # zuul.ratelimit.default-policy.refresh-interval=60
      # zuul.ratelimit.default-policy.type=origin
      

      4、啟動類添加注解

      @EnableZuulProxy
      @EnableEurekaClient
      @SpringBootApplication
      public class SpringcloudzuulApplication {
      	public static void main(String[] args) {
      		SpringApplication.run(SpringcloudzuulApplication.class, args);
      	}
      }
      

      posted on 2022-01-19 11:25  小雞炸  閱讀(35)  評論(0)    收藏  舉報

      主站蜘蛛池模板: 东京一本一道一二三区| 亚洲高潮喷水无码AV电影| 天天色综网| 男女性高爱潮免费网站| 免费久久人人爽人人爽AV| 亚洲国产欧美一区二区好看电影 | 国产老熟女一区二区三区| 与子乱对白在线播放单亲国产| 亚洲最大日韩精品一区| 久久av色欲av久久蜜桃网| 国产精品剧情亚洲二区| 动漫精品专区一区二区三区| 风流老熟女一区二区三区| 国产国产午夜福利视频| 亚洲精品成人区在线观看 | 精品久久久中文字幕人妻| 国产a在视频线精品视频下载| 成全影视大全在线观看| 国产午夜亚洲精品一区| 深田えいみ禁欲后被隔壁人妻| 国产一区二区三区无遮挡| 中国CHINA体内裑精亚洲日本| 康定县| 狠狠色噜噜狠狠狠888米奇视频| 欧美一本大道香蕉综合视频 | 人妻内射一区二区在线视频| 天天做天天爱夜夜爽导航| 双乳奶水饱满少妇呻吟免费看| 亚洲欧美综合精品成人网站| 国产人妻无码一区二区三区18| 久久这里有精品国产电影网| 又爽又黄又无遮挡的激情视频| 国产亚洲国产精品二区| 亚洲一区二区三区啪啪| 午夜福利国产盗摄久久性| 永久免费av无码网站直播| 色老99久久精品偷偷鲁| 精品国偷自产在线视频99| 国产亚洲制服免视频| 久久夜色撩人精品国产av| 瑞安市|