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

微服務(wù)集成spring cloud sentinel

這篇具有很好參考價(jià)值的文章主要介紹了微服務(wù)集成spring cloud sentinel。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

目錄

1. sentinel使用場(chǎng)景

2.? sentinel組成

3. sentinel dashboard搭建

?4. sentinel客戶端詳細(xì)使用

4.1 引入依賴

4.2 application.properties增加dashboard注冊(cè)地址

4.3 手動(dòng)增加限流配置類

4.4 rest接口及service類

4.5 通過dashboard動(dòng)態(tài)配置限流規(guī)則


1. sentinel使用場(chǎng)景

限流、熔斷、監(jiān)控、動(dòng)態(tài)規(guī)則配置

2.? sentinel組成

由兩部分組成,

第一個(gè)是dashboard監(jiān)控儀表盤,單獨(dú)的jar,官網(wǎng)下載后啟動(dòng),可監(jiān)控所有服務(wù)、動(dòng)態(tài)發(fā)現(xiàn)服務(wù)、配置限流策略、熔斷等;

第二個(gè)是sentinel的客戶端核心包,供微服務(wù)引用,注冊(cè)到dashboard儀表盤,引入相關(guān)pom及設(shè)置相關(guān)配置即可;

3. sentinel dashboard搭建

啟動(dòng)命令

java -Dserver.port=8400 -Dcsp.sentinel.dashboard.server=localhost:8400 -Dproject.name=hj-sentinel -Dsentinel.dashboard.auth.username=sentinel -Dsentinel.dashboard.auth.password=sentinel -jar sentinel-dashboard-1.8.6.jar

啟動(dòng)成功,地址欄輸入localhost:8400, 如圖:

?微服務(wù)集成spring cloud sentinel,spring cloud,微服務(wù),spring cloud,sentinel

?4. sentinel客戶端詳細(xì)使用

4.1 引入依賴

<dependency>
   <groupId>com.alibaba.cloud</groupId>
   <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
   <version>2.2.5.RELEASE</version>
</dependency>

4.2 application.properties增加dashboard注冊(cè)地址

spring.cloud.sentinel.transport.dashboard=localhost:8400

4.3 手動(dòng)增加限流配置類

package hj.example.sampleprovider.sample.config;

import com.alibaba.csp.sentinel.slots.block.RuleConstant;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: sentinel 限流規(guī)則配置類
 **/
@Configuration
public class SentinelRulesConfig {
    @Bean
    public void initFlowQpsRules() {
        List<FlowRule> rules = new ArrayList<>();
        FlowRule flowRule = new FlowRule();
        flowRule.setResource("sentinelTest");
        flowRule.setGrade(RuleConstant.FLOW_GRADE_QPS);
        flowRule.setCount(1);
        flowRule.setLimitApp("default");
        flowRule.setClusterMode(false);
        flowRule.setControlBehavior(RuleConstant.CONTROL_BEHAVIOR_DEFAULT);
        rules.add(flowRule);

        FlowRule flowRule1 = new FlowRule();
        flowRule1.setResource("sayHello");
        flowRule1.setGrade(RuleConstant.FLOW_GRADE_QPS);
        flowRule1.setCount(1);
        flowRule1.setLimitApp("default");
        flowRule1.setClusterMode(false);
        flowRule1.setControlBehavior(RuleConstant.CONTROL_BEHAVIOR_DEFAULT);
        rules.add(flowRule1);
        FlowRuleManager.loadRules(rules);
    }
}

4.4 rest接口及service類

其中sentinelTest為rest接口限流,sayHello為方法限流

package hj.example.sampleprovider.sample.controller;

import com.alibaba.csp.sentinel.Entry;
import com.alibaba.csp.sentinel.SphU;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.alibaba.csp.sentinel.slots.block.RuleConstant;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
import com.alibaba.fastjson.JSONObject;
import hj.example.sampleprovider.sample.HelloServiceImpl;
import hj.example.sampleprovider.sample.config.SentinelRulesConfig;
import org.apache.commons.lang.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Description: TODO
 **/
@RestController
public class SentinelTestController {

    @Autowired
    private HelloServiceImpl helloService;

    @RequestMapping("/testClean/{id}")
    public ResponseEntity<Object> testClean(@PathVariable("id") String id) {
        String resultStr = String.format("test clean id: %s [%s]", id, DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss ssss"));
        return new ResponseEntity<>(resultStr , HttpStatus.OK);
    }

    @RequestMapping("/testSentinelDynamicDashboard")
    public ResponseEntity<Object> testSentinelDynamicDashboard() {
        String resultStr = String.format("testSentinelDynamicDashboard [%s]", DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss sss"));
        return new ResponseEntity<>(resultStr, HttpStatus.OK);
    }

    @RequestMapping("/sayHello")
    public ResponseEntity<Object> sayHelloTest() {
        String helloStr = helloService.sayHello("sayHelloTest");
        return new ResponseEntity<>(helloStr, HttpStatus.OK);
    }

    @SentinelResource(value = "sentinelTest", blockHandler = "sentinelTestHandler")
    @RequestMapping("/sentinelTest")
    public ResponseEntity<Object> sentinelTest() {
        System.out.println(" sentinelTest :" + DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss sss"));
        return new ResponseEntity<>("sentinelTest ", HttpStatus.OK);
    }
    public ResponseEntity<Object>  sentinelTestHandler(BlockException e) {
        System.out.println("被限流了");
        return new ResponseEntity<>("========sentinelTestHandler 被限流了:" + JSONObject.toJSONString(e), HttpStatus.OK);
    }
}
package hj.example.sampleprovider.sample;

import com.alibaba.csp.sentinel.Entry;
import com.alibaba.csp.sentinel.SphU;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.alibaba.fastjson.JSON;
import hj.example.sample.IHelloService;
import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Value;
import test.SentinelTest;

import javax.xml.bind.ValidationException;
import java.util.Date;

@DubboService
public class HelloServiceImpl implements IHelloService {

    @Value("${dubbo.application.name}")
    private String serviceName;

    @SentinelResource(value = "sayHello", blockHandler = "sayHelloBlockHandler")
    public String sayHello(String name) {
        System.out.printf("[%s]: Hello, %s%n", serviceName, name);
        return String.format("[%s]: Hello, %s", serviceName, name);
    }

    public String sayHelloBlockHandler(String name, BlockException e) throws ValidationException {
        System.out.println("sayHello 被限流了。name:" + name + ",被限流了:" + JSON.toJSONString(e));
        return "sayHello 被限流了。name:" + name + ",被限流了:" + JSON.toJSONString(e);
    }

    public void sentinelTestMethod() {
        try(Entry entry = SphU.entry("sentinelTestMethod")) {
            System.out.println("hello sentinel : " + DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss sss"));
        }catch (BlockException e) {
            e.printStackTrace();
        }
    }

    public void sentinelTestHandler(BlockException e) throws ValidationException {
        e.printStackTrace();
        throw new ValidationException(e.getMessage());
    }
}

4.5 通過dashboard動(dòng)態(tài)配置限流規(guī)則

微服務(wù)集成spring cloud sentinel,spring cloud,微服務(wù),spring cloud,sentinel文章來源地址http://www.zghlxwxcb.cn/news/detail-665542.html

到了這里,關(guān)于微服務(wù)集成spring cloud sentinel的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

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

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

相關(guān)文章

  • 【Spring Cloud Alibaba】Sentinel 服務(wù)熔斷與流量控制

    【Spring Cloud Alibaba】Sentinel 服務(wù)熔斷與流量控制

    目錄 前言 一、Sentinel 入門 1.1 什么是 Sentinel ? 1.2 微服務(wù)集成 Sentinel ?1.3 安裝Sentinel控制臺(tái) 二、Jmeter 壓力測(cè)試工具 2.1 Jmeter 介紹? 2.2 Jmeter 安裝 2.3 接口測(cè)試 三、Sentinel 使用 3.1 限流規(guī)則 3.1.1 warm up(預(yù)熱模式) 3.1.2?排隊(duì)等待 3.1.3 關(guān)聯(lián) 3.1.4 鏈路 3.2 熔斷規(guī)則 3.3 服務(wù)降級(jí) ????

    2024年02月01日
    瀏覽(28)
  • 【springcloud 微服務(wù)】Spring Cloud Alibaba整合Sentinel詳解

    目錄 一、前言 二、環(huán)境準(zhǔn)備 2.1 部署sentinel管控臺(tái) 2.1.1 官網(wǎng)下載sentinel的jar包 2.1.2 啟動(dòng)控制臺(tái)

    2023年04月09日
    瀏覽(96)
  • 【springcloud 微服務(wù)】Spring Cloud Alibaba Sentinel使用詳解

    目錄 一、前言 二、分布式系統(tǒng)遇到的問題 2.1 服務(wù)可用性問題 2.1.1? 單點(diǎn)故障

    2024年01月16日
    瀏覽(22)
  • 【Spring Cloud】服務(wù)容錯(cuò)中間件Sentinel進(jìn)階——五大規(guī)則

    【Spring Cloud】服務(wù)容錯(cuò)中間件Sentinel進(jìn)階——五大規(guī)則

    我們?cè)谏弦黄恼轮袑?duì) Sentinel 已經(jīng)有了基本的了解,接下來,我們一起對(duì)它的進(jìn)階進(jìn)行學(xué)習(xí)吧! 資源 所謂資源就是 Sentinel 要保護(hù)的東西,資源是 Sentinel 的關(guān)鍵概念。它可以是Java應(yīng)用程序中的任何內(nèi)容,可以是一個(gè)服務(wù),也可以是一個(gè)方法,甚至可以是一段代碼。 我們?nèi)腴T

    2024年04月26日
    瀏覽(24)
  • 微服務(wù)之Spring Cloud Alibaba Sentinel介紹與下載(詳細(xì)方法)

    微服務(wù)之Spring Cloud Alibaba Sentinel介紹與下載(詳細(xì)方法)

    隨著微服務(wù)的流行,服務(wù)和服務(wù)之間的穩(wěn)定性變得越來越重要。Sentinel 以流量為切入點(diǎn),從流量控制、流量路由、熔斷降級(jí)、系統(tǒng)自適應(yīng)過載保護(hù)、熱點(diǎn)流量防護(hù)等多個(gè)維度保護(hù)服務(wù)的穩(wěn)定性。 2012 年,Sentinel 誕生,主要功能為入口流量控制。 2013-2017 年,Sentinel 在阿里巴巴

    2024年02月11日
    瀏覽(95)
  • 【SpringCloud】11、Spring Cloud Gateway使用Sentinel實(shí)現(xiàn)服務(wù)限流

    1、關(guān)于 Sentinel Sentinel 是阿里巴巴開源的一個(gè)流量防衛(wèi)防護(hù)組件,可以為微服務(wù)架構(gòu)提供強(qiáng)大的流量防衛(wèi)能力,包括流量控制、熔斷降級(jí)等功能。Spring Cloud Gateway 與 Sentinel 結(jié)合,可以實(shí)現(xiàn)強(qiáng)大的限流功能。 Sentinel 具有以下特性: 豐富的應(yīng)用場(chǎng)景:Sentinel 承接了阿里巴巴近

    2024年02月01日
    瀏覽(23)
  • Spring Cloud Alibaba全家桶(六)——微服務(wù)組件Sentinel介紹與使用

    Spring Cloud Alibaba全家桶(六)——微服務(wù)組件Sentinel介紹與使用

    本文小新為大家?guī)?微服務(wù)組件Sentinel介紹與使用 相關(guān)知識(shí),具體內(nèi)容包括 分布式系統(tǒng)存在的問題 , 分布式系統(tǒng)問題的解決方案 , Sentinel介紹 , Sentinel快速開始 (包括: API實(shí)現(xiàn)Sentinel資源保護(hù) , @SentinelResource注解實(shí)現(xiàn)資源保護(hù) ), Sentinel控制臺(tái) , Spring Cloud Alibaba整合

    2024年01月17日
    瀏覽(96)
  • Sentinel nacos spring cloud 持久化配置---分布式/微服務(wù)流量控制

    Sentinel nacos spring cloud 持久化配置---分布式/微服務(wù)流量控制

    下載地址:https://github.com/alibaba/Sentinel/releases 本次版本:1.8.6 上一篇文章已介紹 我們先說目標(biāo),為各位看官節(jié)省不匹配的時(shí)間 0、使用sentinel流控中心 1、使用nacos做配置中心 5、使用spring-cloud-starter-alibaba-sentinel做持久化配置 https://github.com/OrderDong/microservice-boot 分支:microserv

    2024年02月16日
    瀏覽(19)
  • Spring Cloud集成Nacos實(shí)現(xiàn)服務(wù)配置中心 | Spring Cloud 7

    先我們來看一下,微服務(wù)架構(gòu)下關(guān)于配置文件的一些問題: 配置文件相對(duì)分散。在一個(gè)微服務(wù)架構(gòu)下,配置文件會(huì)隨著微服務(wù)的增多變的越來越多,而且分散在各個(gè)微服務(wù)中,不好統(tǒng)一配置和管理。 配置文件無法區(qū)分環(huán)境,開發(fā)環(huán)境、測(cè)試環(huán)境、線上環(huán)境。微服務(wù)項(xiàng)目可能會(huì)

    2024年02月14日
    瀏覽(88)
  • Spring Cloud Gateway集成SpringDoc,集中管理微服務(wù)API

    Spring Cloud Gateway集成SpringDoc,集中管理微服務(wù)API

    Spring Cloud微服務(wù)集成SpringDoc,在Spring Cloud Gateway中統(tǒng)一管理微服務(wù)的API,微服務(wù)上下線時(shí)自動(dòng)刷新SwaggerUi中的group組。 框架 版本 Spring Boot 3.1.5 Spring Cloud 2022.0.4 Spring Cloud Alibaba 2022.0.0.0 Spring Doc 2.2.0 Nacos Server 2.2.3 公共模塊里的配置是之前文章中提到的內(nèi)容,加了一個(gè)webmvc和we

    2024年04月28日
    瀏覽(18)

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

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

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

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包