国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當前位置: 首頁 > news >正文

全網(wǎng)搜索石家莊seo全網(wǎng)營銷

全網(wǎng)搜索,石家莊seo全網(wǎng)營銷,軟件實施工資一般多少,網(wǎng)站備案率是什么一 服務(wù)降級的說明 1.1 服務(wù)降級說明 "服務(wù)器忙,請稍后在試"不讓客戶達等待,立即返回一個友好的提示。 1.2 服務(wù)降級的觸發(fā)情況 1.程序運行異常; 2.超時; 3.服務(wù)熔斷觸發(fā)服務(wù)降級;4 .線程池/信號量打…

一 服務(wù)降級的說明

1.1 服務(wù)降級說明

"服務(wù)器忙,請稍后在試"不讓客戶達等待,立即返回一個友好的提示。

1.2 服務(wù)降級的觸發(fā)情況

1.程序運行異常;

2.超時;

3.服務(wù)熔斷觸發(fā)服務(wù)降級;4

.線程池/信號量打滿也會導致服務(wù)降級

1.3 通用注解

?

二 案例:對每一個方法實行降級處理

2.1 消費端

2.1.1 pom文件

   <!--hystrix--><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-hystrix</artifactId></dependency>

2.1.2 設(shè)置降級規(guī)則

代碼

 @GetMapping(value = "/consumer/payment/nacos/{id}")@HystrixCommand(fallbackMethod = "dealFallBackInfo",commandProperties = {@HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds",value="1500")})public String paymentInfo(@PathVariable("id") Long id){System.out.println("獲取服務(wù)器配置信息serverUrl:"+serverURL);System.out.println("9008的controller獲取id:"+id);String str=orderConsumerService.getPaymentByIdLjf22222(id);return "ok:"+serverURL+""+str;}@GetMapping(value = "/consumer/getinfo/{id}")public Object getUserInfo(@PathVariable("id") Long id){User u=new User(id.intValue(),"beijing"+id);return  orderConsumerService.postQueryParams(u);}public String dealFallBackInfo(@PathVariable("id") Long id){return "我是消費者9008,服務(wù)出錯了,進行服務(wù)降級"+id;}

?2.1.3 開啟hystrix熔斷

添加:@EnableHystrix 注解

?2.2?服務(wù)端

2.2.1 pom文件

   <!--hystrix--><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-hystrix</artifactId></dependency>

2.2.2?設(shè)置降級規(guī)則

1.代碼

    @GetMapping(value = "/ljf/getinfo/{id}")@HystrixCommand(fallbackMethod = "dealFallBackInfo",commandProperties = {@HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds",value="3000")})public String getPayment(@PathVariable("id") Integer id){try {Thread.sleep(5000);} catch (InterruptedException e) {e.printStackTrace();}int k=10/0;System.out.println("================服務(wù)9009 獲取到的參數(shù)id:"+id);return "服務(wù)9009 獲取到的參數(shù)id:"+id;}@PostMapping("/path")public  String postQueryParams(@RequestBody User user) throws JsonProcessingException {String str=  new JsonMapper().writeValueAsString(user);System.out.println("post提交....");return str;}public String dealFallBackInfo(@PathVariable("id") Long id){return "我是消費者9009,服務(wù)出錯了,進行服務(wù)降級"+id;}

2.截圖

?2.2.3 開啟hystrix熔斷

??2.3?啟動服務(wù)測試

1.啟動nacos,啟動sleuth

2.啟動consumer9008? ?provider9009

?3.測試

三 案例:設(shè)置全局降級處理辦法

3.1 消費端設(shè)置

1.代碼

package com.ljf.mscloud.controller;import com.ljf.mscloud.model.User;
import com.ljf.mscloud.service.OrderConsumerService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;/*** @ClassName: OrderConsumerController* @Description: TODO* @Author: admin* @Date: 2023/08/14?18:09:14?* @Version: V1.0**/
@RestController
@Slf4j
@RefreshScope //支持Nacos的動態(tài)刷新功能。
//@DefaultProperties(defaultFallback = "globalFallBackInfo")
public class OrderConsumerController {@Value("${service-url.nacos-user-service}")private String serverURL;@Autowiredprivate OrderConsumerService orderConsumerService;@GetMapping(value = "/consumer/payment/nacos/{id}")@HystrixCommand(fallbackMethod = "dealFallBackInfo",commandProperties = {@HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds",value="1500")})public String paymentInfo(@PathVariable("id") Long id){System.out.println("獲取服務(wù)器配置信息serverUrl:"+serverURL);System.out.println("9008的controller獲取id:"+id);String str=orderConsumerService.getPaymentByIdLjf22222(id);return "ok:"+serverURL+""+str;}@GetMapping(value = "/consumer/getinfo/{id}")public Object getUserInfo(@PathVariable("id") Long id){User u=new User(id.intValue(),"beijing"+id);return  orderConsumerService.postQueryParams(u);}public String dealFallBackInfo(@PathVariable("id") Long id){return "我是消費者9008,服務(wù)出錯了,進行服務(wù)降級"+id;}public String globalFallBackInfo(){return "Global異常處理信息,請稍后再試,客戶端9008";}
}

2.截圖

?原因在沒有在制定方法加:@HystrixCommand? 那么加上此注解后:

?再次訪問:http://localhost:9008/consumer/getinfo/666

?

四 案例:給Feginclient注解的接口上添加降級規(guī)則

4.1 controller

package com.ljf.mscloud.controller;import com.ljf.mscloud.model.User;
import com.ljf.mscloud.service.OrderConsumerService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;/*** @ClassName: OrderConsumerController* @Description: TODO* @Author: admin* @Date: 2023/08/14?18:09:14?* @Version: V1.0**/
@RestController
@Slf4j
@RefreshScope //支持Nacos的動態(tài)刷新功能。
//
//@DefaultProperties(defaultFallback = "globalFallBackInfo")
public class OrderConsumerController {@Value("${service-url.nacos-user-service}")private String serverURL;@Autowiredprivate OrderConsumerService orderConsumerService;@GetMapping(value = "/consumer/payment/nacos/{id}")//   @HystrixCommand(fallbackMethod = "dealFallBackInfo",commandProperties = {//        @HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds",value="1500")// })public String paymentInfo(@PathVariable("id") Long id){System.out.println("獲取服務(wù)器配置信息serverUrl:"+serverURL);System.out.println("9008的controller獲取id:"+id);String str=orderConsumerService.getPaymentByIdLjf22222(id);return "ok:"+serverURL+""+str;}@GetMapping(value = "/consumer/getinfo/{id}")// @HystrixCommandpublic Object getUserInfo(@PathVariable("id") Long id){User u=new User(id.intValue(),"beijing"+id);//  int age = 10/0;return  orderConsumerService.postQueryParams(u);}public String dealFallBackInfo(@PathVariable("id") Long id){return "我是消費者9008,服務(wù)出錯了,進行服務(wù)降級"+id;}public String globalFallBackInfo(){return "Global異常處理信息,請稍后再試,客戶端9008";}
}

4.2 service

package com.ljf.mscloud.service;import com.ljf.mscloud.model.User;
import feign.Headers;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;@Component
@FeignClient(value = "mscloud-fegin-nacos-hystrix-provider9009",fallback = PaymentFallbackService.class)
public interface OrderConsumerService {@GetMapping(value = "/ljf/getinfo/{yyid}") //相當于:public String getPaymentByIdLjf22222(@PathVariable("yyid") Long ssid);// @Headers({"Content-Type: application/json"})// @PostMapping("/path")@PostMapping(value = "/path",consumes ="application/json")String postQueryParams(@RequestBody User user);
}

4.3 fallback實現(xiàn)類

@Component
public class PaymentFallbackService  implements OrderConsumerService{@Overridepublic String getPaymentByIdLjf22222(Long ssid) {return "getPaymentByIdLjf22222方法出現(xiàn)問題開始降級";}@Overridepublic String postQueryParams(User user) {return "postQueryParams方法出現(xiàn)問題開始降級";}
}

?4.4 配置文件

?4.5 測試

1.故意只啟動 consuemr9008,不啟動provider9009 模擬宕機的情況

2.測試

?

?

http://m.aloenet.com.cn/news/28765.html

相關(guān)文章:

  • 東莞網(wǎng)絡(luò)展示平臺東莞seo外包
  • 網(wǎng)站建設(shè)與維護是做什么seo公司上海牛巨微
  • wordpress的app怎么用而的跟地seo排名點擊軟件
  • 設(shè)計高端網(wǎng)站怎么宣傳自己的產(chǎn)品
  • 成都網(wǎng)站排名優(yōu)化今日新聞頭條新聞今天
  • 常寧網(wǎng)頁設(shè)計西安百度關(guān)鍵詞優(yōu)化排名
  • 濟南市做網(wǎng)站大連網(wǎng)站開發(fā)公司
  • php 網(wǎng)站 下載百度網(wǎng)址大全網(wǎng)站大全
  • sqlite做網(wǎng)站下載優(yōu)化大師安裝桌面
  • 網(wǎng)站空間購買800seo運營工作內(nèi)容
  • 兩個wordpress文章同步seo教程百度網(wǎng)盤
  • 17. 整個網(wǎng)站建設(shè)中的關(guān)鍵是關(guān)鍵詞優(yōu)化和seo
  • 做異地送花網(wǎng)站愛站小工具圣經(jīng)
  • 蘇中建設(shè)南京區(qū)域公司上海網(wǎng)站營銷seo電話
  • 中文域名做的網(wǎng)站有哪些深圳優(yōu)化網(wǎng)站
  • 哪有專業(yè)做網(wǎng)站推廣優(yōu)化網(wǎng)站排名
  • 上海施工單位廣東企業(yè)網(wǎng)站seo報價
  • 東陵網(wǎng)站制作產(chǎn)品推廣策劃方案怎么做
  • 自己如何開自己的商城搜索引擎優(yōu)化是免費的嗎
  • 給網(wǎng)站做排名優(yōu)化學什么好處包就業(yè)的培訓學校
  • 基于java開發(fā)網(wǎng)站開發(fā)網(wǎng)站關(guān)鍵詞提升
  • 企業(yè)商務(wù)網(wǎng)站的技術(shù)上海關(guān)鍵詞排名提升
  • 學校網(wǎng)站建設(shè)先進個人榮譽長沙好的seo外包公司
  • 網(wǎng)站建設(shè)公司運營手機建站系統(tǒng)
  • jsp網(wǎng)站制作詳細教程站長工具流量統(tǒng)計
  • 廣州淘寶網(wǎng)站建設(shè)泰州百度關(guān)鍵詞優(yōu)化
  • 網(wǎng)站開發(fā)軟件系統(tǒng)教程seo推廣排名網(wǎng)站
  • 烽火臺網(wǎng)站游戲推廣一個月能拿多少錢
  • 可信網(wǎng)站身份驗證免費制作自己的網(wǎng)頁
  • 誰能幫我做網(wǎng)站網(wǎng)站引流推廣怎么做