国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

SpringCloud之Gateway整合Sentinel服務(wù)降級和限流

這篇具有很好參考價值的文章主要介紹了SpringCloud之Gateway整合Sentinel服務(wù)降級和限流。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報違法"按鈕提交疑問。

1.下載Sentinel.jar可以圖形界面配置限流和降級規(guī)則
地址:可能需要翻墻
下載jar文件
2.引入maven依賴

   <!--    spring cloud gateway整合sentinel的依賴-->
   <dependency>
       <groupId>com.alibaba.cloud</groupId>
       <artifactId>spring-cloud-alibaba-sentinel-gateway</artifactId>
       <version>2.2.2.RELEASE</version>
   </dependency>

   <!--    sentinel的依賴-->
   <dependency>
       <groupId>com.alibaba.cloud</groupId>
       <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
       <version>2.2.2.RELEASE</version>
   </dependency>
   <dependency>
       <groupId>com.alibaba.csp</groupId>
       <artifactId>sentinel-spring-cloud-gateway-adapter</artifactId>
       <version>1.8.0</version>
   </dependency>

3.寫個自動注入Resource的過濾器類(可以不寫注解直接使用)

@Configuration
public class GatewayConfiguration {
 
    private final List<ViewResolver> viewResolvers;
    private final ServerCodecConfigurer serverCodecConfigurer;
 
    public GatewayConfiguration(ObjectProvider<List<ViewResolver>> viewResolversProvider,
                                ServerCodecConfigurer serverCodecConfigurer) {
        this.viewResolvers = viewResolversProvider.getIfAvailable(Collections::emptyList);
        this.serverCodecConfigurer = serverCodecConfigurer;
    }
 
    @Bean
    @Order(Ordered.HIGHEST_PRECEDENCE)
    public SentinelGatewayBlockExceptionHandler sentinelGatewayBlockExceptionHandler() {
        // Register the block exception handler for Spring Cloud Gateway.
        return new SentinelGatewayBlockExceptionHandler(viewResolvers, serverCodecConfigurer);
    }
 
    @Bean
    @Order(Ordered.HIGHEST_PRECEDENCE)
    public GlobalFilter sentinelGatewayFilter() {
        return new SentinelGatewayFilter();
    }
}

4.寫配置文件 application.properties

# 服務(wù)端口
server.port=80
# 服務(wù)名
spring.application.name=service-gateway
#服務(wù)熔斷
spring.cloud.sentinel.transport.dashboard=localhost:18080
# nacos服務(wù)地址
spring.cloud.nacos.discovery.server-addr=192.168.56.1:8848
spring.main.allow-bean-definition-overriding=true
spring.profiles.active=dev

#使用服務(wù)發(fā)現(xiàn)路由
spring.cloud.gateway.discovery.locator.enabled=true

#設(shè)置路由id
spring.cloud.gateway.routes[0].id=service-cmn
#設(shè)置路由的uri
spring.cloud.gateway.routes[0].uri=lb://service-cmn
#設(shè)置路由斷言,代理servicerId為auth-service的/auth/路徑
spring.cloud.gateway.routes[0].predicates= Path=/*/cmn/**

5.cmd命令行啟動jar文件訪問localhost:18080頁面,自己設(shè)置QPS
java -jar -server.port=18080 sentinel-dashboard.jar
SpringCloud之Gateway整合Sentinel服務(wù)降級和限流,springCloud,spring cloud,gateway,sentinel
SpringCloud之Gateway整合Sentinel服務(wù)降級和限流,springCloud,spring cloud,gateway,sentinel
--------不在微服務(wù)中使用,在普通springboot也可以使用--------
1.maven依賴

  <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

2.service中寫

@Service

public class UserService { 
	//不可以用在類上
    @SentinelResource(value = "sayHello",fallback = "sayHellofail")
    public String sayHello(){
        return "Hello,World";
    }

    public  String sayHellofail(){ //限流的方法
        return "I'am sorry";
    }

}

3.controller

@RestController
public class UserController {

    @Autowired
    UserService userService;

    @RequestMapping("/hello")
    public String hello(){
      return userService.sayHello();
    }
}

3.sentinel控制臺查看
SpringCloud之Gateway整合Sentinel服務(wù)降級和限流,springCloud,spring cloud,gateway,sentinel

SpringCloud之Gateway整合Sentinel服務(wù)降級和限流,springCloud,spring cloud,gateway,sentinel
//快速訪問
SpringCloud之Gateway整合Sentinel服務(wù)降級和限流,springCloud,spring cloud,gateway,sentinel文章來源地址http://www.zghlxwxcb.cn/news/detail-723346.html

到了這里,關(guān)于SpringCloud之Gateway整合Sentinel服務(wù)降級和限流的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • Java之SpringCloud Alibaba【五】【微服務(wù) Sentinel整合openfeign進(jìn)行降級】

    Java之SpringCloud Alibaba【五】【微服務(wù) Sentinel整合openfeign進(jìn)行降級】

    Java之SpringCloud Alibaba【一】【Nacos一篇文章精通系列】 跳轉(zhuǎn) Java之SpringCloud Alibaba【二】【微服務(wù)調(diào)用組件Feign】 跳轉(zhuǎn) Java之SpringCloud Alibaba【三】【微服務(wù)Nacos-config配置中心】 跳轉(zhuǎn) Java之SpringCloud Alibaba【四】【微服務(wù) Sentinel服務(wù)熔斷】 跳轉(zhuǎn) Java之SpringCloud Alibaba【五】【微服務(wù)

    2024年02月11日
    瀏覽(39)
  • SpringCloud Alibaba Sentinel 與 SpringCloud Gateway 的限流有什么差別?(三種限流算法原理分析)

    SpringCloud Alibaba Sentinel 與 SpringCloud Gateway 的限流有什么差別?(三種限流算法原理分析)

    目錄 一、Sentinel 與 Gateway 的限流有什么差別? 1.1、前置知識 - 四種常見的限流算法 1.1.1、Tips 1.1.2、計(jì)數(shù)器算法 1)固定窗口計(jì)數(shù)器算法 2)滑動窗口計(jì)數(shù)器算法 1.1.3、令牌桶算法 1.1.4、漏桶算法 1.2、解決問題 1.1.1、Tips 限流, 就是指對服務(wù)器請求量做限制,避免因?yàn)橥话l(fā)的

    2024年01月25日
    瀏覽(17)
  • 微服務(wù)韌性工程:利用Sentinel實(shí)施有效服務(wù)容錯與限流降級

    微服務(wù)韌性工程:利用Sentinel實(shí)施有效服務(wù)容錯與限流降級

    ? ? ? ? 目錄 一、雪崩效應(yīng) 二、Sentinel 服務(wù)容錯 ? ? ? ? 2.1?Sentinel容錯思路 ? ? ? ? 2.2 內(nèi)部異常兼容 ? ? ? ? 2.3 外部流量控制 三、Sentinel 項(xiàng)目搭建 四、Sentinel 工作原理 ????????服務(wù)容錯是微服務(wù)設(shè)計(jì)中一項(xiàng)重要原則和技術(shù)手段,主要目標(biāo)是在服務(wù)出現(xiàn)故障、網(wǎng)絡(luò)波

    2024年03月15日
    瀏覽(23)
  • SpringCloud Alibaba Sentinel整合GateWay

    SpringCloud Alibaba Sentinel整合GateWay

    在微服務(wù)系統(tǒng)中,網(wǎng)關(guān)提供了微服務(wù)系統(tǒng)的統(tǒng)一入口,所以我們在做限流的時候,肯定是要在網(wǎng)關(guān)層面做一個流量的控制,Sentinel 支持對 Spring Cloud Gateway、Zuul 等主流的 API Gateway 進(jìn)行限流。 網(wǎng)關(guān): Sentinel 1.6.0 引入了 Sentinel API Gateway Adapter Common 模塊,此模塊中包含網(wǎng)關(guān)限流的

    2024年02月16日
    瀏覽(21)
  • 聊一聊服務(wù)治理三板斧:限流、熔斷、降級和go-sentinel的實(shí)現(xiàn)

    聊一聊服務(wù)治理三板斧:限流、熔斷、降級和go-sentinel的實(shí)現(xiàn)

    我們知道,對于一個項(xiàng)目之初,我們不可能上來就按幾千的并發(fā)去配置,為什么?兩個方面,第一個是成本高。第二個是維護(hù)難度大。即便是天貓?zhí)詫氝@種,也是采用的動態(tài)擴(kuò)容的方式來應(yīng)對雙十一。那么一個項(xiàng)目如何應(yīng)對突然的高并發(fā),我們有哪些常用的措施和處理呢?我

    2024年01月19日
    瀏覽(28)
  • 熔斷降級與限流在開源SpringBoot/SpringCloud微服務(wù)框架的最佳實(shí)踐

    熔斷降級與限流在開源SpringBoot/SpringCloud微服務(wù)框架的最佳實(shí)踐

    前期內(nèi)容導(dǎo)讀: Java開源RSA/AES/SHA1/PGP/SM2/SM3/SM4加密算法介紹 Java開源AES/SM4/3DES對稱加密算法介紹及其實(shí)現(xiàn) Java開源AES/SM4/3DES對稱加密算法的驗(yàn)證說明 Java開源RSA/SM2非對稱加密算法對比介紹 Java開源RSA非對稱加密算法實(shí)現(xiàn) Java開源SM2非對稱加密算法實(shí)現(xiàn) Java開源接口微服務(wù)代碼框架

    2024年02月12日
    瀏覽(25)
  • 【SpringCloud Alibaba】(六)使用 Sentinel 實(shí)現(xiàn)服務(wù)限流與容錯

    【SpringCloud Alibaba】(六)使用 Sentinel 實(shí)現(xiàn)服務(wù)限流與容錯

    今天,我們就使用 Sentinel 實(shí)現(xiàn)接口的限流,并使用 Feign 整合 Sentinel 實(shí)現(xiàn)服務(wù)容錯的功能,讓我們體驗(yàn)下微服務(wù)使用了服務(wù)容錯功能的效果。 因?yàn)閮?nèi)容僅僅圍繞著 SpringCloud Alibaba技術(shù)棧展開,所以,這里我們使用的服務(wù)容錯組件是阿里開源的 Sentinel。 當(dāng)然,能夠?qū)崿F(xiàn)服務(wù)容錯

    2024年02月14日
    瀏覽(23)
  • Sentinel 降級、限流、熔斷

    Sentinel 降級、限流、熔斷

    在現(xiàn)代分布式系統(tǒng)中,如何有效地保護(hù)系統(tǒng)免受突發(fā)流量和故障的影響,是每個開發(fā)人員和架構(gòu)師都需要思考的重要問題。在這樣的背景下,Sentinel作為一個強(qiáng)大的系統(tǒng)保護(hù)和控制組件,為我們提供了降級、限流、熔斷等多種策略,幫助我們更好地保障系統(tǒng)的穩(wěn)定性和可用性

    2024年01月24日
    瀏覽(24)
  • 09-微服務(wù)Sentinel整合GateWay

    09-微服務(wù)Sentinel整合GateWay

    在微服務(wù)系統(tǒng)中,網(wǎng)關(guān)提供了微服務(wù)系統(tǒng)的統(tǒng)一入口,所以我們在做限流的時候,肯定是要在網(wǎng)關(guān)層面做一個流量的控制,Sentinel 支持對 Spring Cloud Gateway、Zuul 等主流的 API Gateway 進(jìn)行限流。 Sentinel 1.6.0 引入了 Sentinel API Gateway Adapter Common 模塊,此模塊中包含網(wǎng)關(guān)限流的規(guī)則和

    2024年01月24日
    瀏覽(14)
  • 【微服務(wù)】Feign 整合 Sentinel,深入探索 Sentinel 的隔離和熔斷降級規(guī)則,以及授權(quán)規(guī)則和自定義異常返回結(jié)果

    【微服務(wù)】Feign 整合 Sentinel,深入探索 Sentinel 的隔離和熔斷降級規(guī)則,以及授權(quán)規(guī)則和自定義異常返回結(jié)果

    在前文中,介紹了 Sentinel 的流控模式和流控效果,然而限流只是一種預(yù)防措施,雖然可以盡量避免因?yàn)椴l(fā)問題而引起的服務(wù)故障,但服務(wù)仍然可能因其他因素而發(fā)生故障。為了將這些故障控制在一定范圍內(nèi),以避免雪崩效應(yīng)的發(fā)生,我們需要依賴線程隔離(艙壁模式)和熔

    2024年02月08日
    瀏覽(27)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包