001/** 002 * Copyright (c) 2015-2022, Michael Yang 杨福海 (fuhai999@gmail.com). 003 * <p> 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * <p> 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * <p> 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package io.jboot.support.sentinel; 017 018import io.jboot.Jboot; 019import io.jboot.app.config.annotation.ConfigModel; 020 021import java.util.Map; 022 023@ConfigModel(prefix = "jboot.sentinel") 024public class SentinelConfig { 025 026 public static final String DATASOURCE_REDIS = "redis"; 027 public static final String DATASOURCE_ZOOKEEPER = "zookeeper"; 028 public static final String DATASOURCE_NACOS = "nacos"; 029 public static final String DATASOURCE_APOLLO = "apollo"; 030 031 // 是否启用 032 private boolean enable = false; 033 034 private String datasource; 035 036 // 是否对 http 请求启用限流,启用后还需要去 sentinel 后台配置 037 private boolean reqeustEnable = true; 038 039 private String reqeustTargetPrefix; 040 041 // 如果 http 被限流后跳转的页面 042 private String requestBlockPage; 043 044 // 如果 http 被限流后渲染的 json 数据,requestBlockPage 配置优先于此项 045 private Map requestBlockJsonMap; 046 047 private String ruleFile = "sentinel-rule.json"; 048 049 public boolean isEnable() { 050 return enable; 051 } 052 053 public void setEnable(boolean enable) { 054 this.enable = enable; 055 } 056 057 058 public String getDatasource() { 059 return datasource; 060 } 061 062 public void setDatasource(String datasource) { 063 this.datasource = datasource; 064 } 065 066 public boolean isReqeustEnable() { 067 return reqeustEnable; 068 } 069 070 public void setReqeustEnable(boolean reqeustEnable) { 071 this.reqeustEnable = reqeustEnable; 072 } 073 074 public String getReqeustTargetPrefix() { 075 return reqeustTargetPrefix; 076 } 077 078 public void setReqeustTargetPrefix(String reqeustTargetPrefix) { 079 this.reqeustTargetPrefix = reqeustTargetPrefix; 080 } 081 082 public String getRequestBlockPage() { 083 return requestBlockPage; 084 } 085 086 public void setRequestBlockPage(String requestBlockPage) { 087 this.requestBlockPage = requestBlockPage; 088 } 089 090 public Map getRequestBlockJsonMap() { 091 return requestBlockJsonMap; 092 } 093 094 public void setRequestBlockJsonMap(Map requestBlockJsonMap) { 095 this.requestBlockJsonMap = requestBlockJsonMap; 096 } 097 098 public String getRuleFile() { 099 return ruleFile; 100 } 101 102 public void setRuleFile(String ruleFile) { 103 this.ruleFile = ruleFile; 104 } 105 106 public static void set(SentinelConfig sentinelConfig) { 107 SentinelConfig.sentinelConfig = sentinelConfig; 108 } 109 110 private static SentinelConfig sentinelConfig; 111 112 public static SentinelConfig get() { 113 if (sentinelConfig == null){ 114 sentinelConfig = Jboot.config(SentinelConfig.class); 115 } 116 return sentinelConfig; 117 } 118}