Sentinelとspringbootは、プロバイダーのリクエストをダウングレードします

Sentinel
、リクエストのプロバイダーの現在の制限ダウングレード処理にMavenの依存関係追加します

<!--引入sentinel 熔断 降级 -->
<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>

次の構成情報をプロジェクトのapplication.ymlに追加します。

    #配置sentinel
    spring:
	    sentinel:
	      transport:
	        dashboard: localhost:8883
	        #控制台的port
	        port: 8719

sentinelをダウンロードしてローカルにインストールします
https://github.com/alibaba/spring-cloud-alibaba/wiki/Sentinel
ここにインストールしたバージョンはsentinel.dashboard-1.6.3.jar
ここに画像の説明を挿入
で、sentinel.dashboard-1.6.3.jarです。
次のディレクトリの下にあるcmdを開いてコマンドを実行します。

java -jar  sentinel.dashboard-1.6.3.jar --server.port=8883

ブラウザがページを開きます。
ログインユーザー名を入力します。センチネル
パスワード:センチネル
はプロジェクトのパスをランダムに要求します。ダッシュボードパネルに次の情報が表示されます。
各マイクロサービスは統計監査情報を導入しますspring-boot-starter-actuatorここに画像の説明を挿入
マイクロサービスは統計監査情報を導入しますspring-boot-starter -actuatorエンドポイントは、エンドポイント機能を使用する前に、Spring-boot-starter-をMavenに追加する必要性を
サポート
します。構成内のエンドポイントアクセスを許可します。

Spring Boot1.xに構成management.security.enabled = falseを追加します。公開されたエンドポイントパスは/ sentinelです

Spring Boot2.xに構成management.endpoints.web.exposure.include = *を追加します。公開されたエンドポイントパスは/ actuator / sentinelです

SentinelEndpointで公開されている情報は非常に役立ちます。現在のアプリケーションのすべてのルール情報、ログディレクトリ、現在のインスタンスのIP、Sentinelダッシュボードアドレス、ブロックページ、アプリケーションのハートビート頻度、Sentinelダッシュボードなどが含まれます。

プロバイダーはダウングレード処理を行い
、Mavenの依存関係追加します

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

構成ファイルに構成情報を追加します

management.endpoints.web.exposure.include=*

カスタムフロー制御応答構成クラスを追加します

**
 * @date 2021-02-22 2:19 下午
 * @description sentinel自定义返回方法
 */
@Configuration
public class MySeckillSentinelConfig {
    
    

    public MySeckillSentinelConfig() {
    
    
        WebCallbackManager.setUrlBlockHandler(new UrlBlockHandler() {
    
    
            @Override
            public void blocked(HttpServletRequest request, HttpServletResponse response, BlockException e) throws IOException {
    
    
                //请求流量过大就返回
                R r = R.error(BizCodeEnume.TO_MANY_REQUEST.getCode(), BizCodeEnume.TO_MANY_REQUEST.getMsg());
                //解决response乱码
                response.setCharacterEncoding("utf-8");
                response.setContentType("application/json");
                response.getWriter().write(JSON.toJSONString(r));
            }
        });
    }
}

リクエストトラフィックが大きすぎる場合にトリガーされます
ここに画像の説明を挿入

おすすめ

転載: blog.csdn.net/u014496893/article/details/114368832