This is an automated email from the ASF dual-hosted git repository. midnight2104 pushed a commit to branch midnight2104 in repository https://gitbox.apache.org/repos/asf/incubator-shenyu-website.git
commit 0f9597e15748e7985898b53980d883d55beb5410 Author: midnight2104 <[email protected]> AuthorDate: Fri Sep 3 13:34:35 2021 +0800 add custom spi doc --- docs/design/spi-design.md | 49 +++++++++++++ docs/developer/spi/custom-condition-match.md | 74 ------------------- docs/developer/spi/custom-match-mode.md | 75 +++++++++++++++++++ docs/developer/spi/custom-parameter-data.md | 75 +++++++++++++++++++ docs/developer/spi/custom-predicate-judge.md | 81 +++++++++++++++++++++ .../current/design/_category_.json | 2 +- .../current/design/spi-design.md | 42 +++++++++++ .../current/developer/spi/_category_.json | 2 +- .../developer/spi/custom-condition-match.md | 73 ------------------- .../current/developer/spi/custom-match-mode.md | 72 ++++++++++++++++++ .../current/developer/spi/custom-parameter-data.md | 71 ++++++++++++++++++ .../developer/spi/custom-predicate-judge.md | 75 +++++++++++++++++++ .../version-2.4.0/design/_category_.json | 2 +- .../version-2.4.0/design/spi-design.md | 42 +++++++++++ .../version-2.4.0/developer/spi/_category_.json | 2 +- .../developer/spi/custom-condition-match.md | 73 ------------------- .../developer/spi/custom-match-mode.md | 72 ++++++++++++++++++ .../developer/spi/custom-parameter-data.md | 71 ++++++++++++++++++ .../developer/spi/custom-predicate-judge.md | 75 +++++++++++++++++++ .../img/shenyu/custom/custom_parameter_data_en.png | Bin 0 -> 81855 bytes .../img/shenyu/custom/custom_parameter_data_zh.png | Bin 0 -> 83147 bytes .../shenyu/custom/custom_predicate_judge_en.png | Bin 0 -> 95180 bytes .../shenyu/custom/custom_predicate_judge_zh.png | Bin 0 -> 97230 bytes .../shenyu/custom/use_custom_parameter_data_en.png | Bin 0 -> 83207 bytes .../shenyu/custom/use_custom_parameter_data_zh.png | Bin 0 -> 88231 bytes .../custom/use_custom_predicate_judge_en.png | Bin 0 -> 93031 bytes .../custom/use_custom_predicate_judge_zh.png | Bin 0 -> 86660 bytes versioned_docs/version-2.4.0/design/spi-design.md | 49 +++++++++++++ .../developer/spi/custom-condition-match.md | 74 ------------------- .../developer/spi/custom-match-mode.md | 75 +++++++++++++++++++ .../developer/spi/custom-parameter-data.md | 75 +++++++++++++++++++ .../developer/spi/custom-predicate-judge.md | 81 +++++++++++++++++++++ 32 files changed, 1084 insertions(+), 298 deletions(-) diff --git a/docs/design/spi-design.md b/docs/design/spi-design.md new file mode 100644 index 0000000..260ee65 --- /dev/null +++ b/docs/design/spi-design.md @@ -0,0 +1,49 @@ +--- +title: SPI Design +keywords: ["spi design"] +description: spi-design +--- + + +SPI, called Service Provider Interface, is a built-in JDK Service that provides discovery function and a dynamic replacement discovery mechanism. + + +[shenyu-spi](https://github.com/apache/incubator-shenyu/tree/master/shenyu-spi) is a custom SPI extension implementation for Apache Shenyu gateway. The design and implementation principles refer to [SPI Extension Implementations](https://dubbo.apache.org/en/docs/v2.7/dev/impls/) . + + +### Registry Center + +`Consul`, `Etcd`, `Http`, `Nacos` and `Zookeeper` are supported. The expansion of the registry including client and server, interface respectively `ShenyuServerRegisterRepository` and `ShenyuClientRegisterRepository`. + +### Metrics Center + +Responsible for service monitoring, loading concrete implementation through `SPI`, currently support `Prometheus`, service interface is `MetricsBootService`. + + + +### Load Balance + +Select one of the service providers to call. Currently, the supported algorithms are `Has`, `Random`, and `RoundRobin`, and the extended interface is `LoadBalance`. + +### RateLimiter + + +In the `RateLimiter` plugin, which stream limiting algorithm to use, currently supporting `Concurren`, `LeakyBucke`, `SlidingWindow` and `TokenBucket`, the extension interface is `RateLimiterAlgorithm`. + + +### Match Strategy + +Which matching method to use when adding selectors And rules, currently supports `And`, `Or`, And the extension interface is `MatchStrategy`. + + +### Parameter Data + + +Currently, `URI`,`RequestMethod`, `Query`, `Post`, `IP`, `Host`, `Cookie`, and `Header` are supported. The extended interface is `ParameterData`. + + +### Predicate Judge + +Which conditional policy to use when adding selectors and rules currently supports `Match`, `Contains`,`Equals`, `Groovy`, `Regex`, `SpEL`, `TimerAfter` and `TimerBefore`. The extension interface is `PredicateJudge`. + + diff --git a/docs/developer/spi/custom-condition-match.md b/docs/developer/spi/custom-condition-match.md deleted file mode 100644 index a95c087..0000000 --- a/docs/developer/spi/custom-condition-match.md +++ /dev/null @@ -1,74 +0,0 @@ ---- -title: Custom Condition Match -keywords: ["Condition"] -description: custom condition match ---- - - -## Explanation - -* Before custom development, please customize and build the gateway environment first, please refer to: [custom deployment](../../deployment/deployment-custom) - -* This article describes how to customize the extension of `org.apache.shenyu.plugin.base.condition.strategy.MatchStrategy`. - -## Extension - -* Create a new class `${you class}`,implements `org.apache.shenyu.plugin.base.condition.strategy.MatchStrategy` - -``` -public class ${you class} implements MatchStrategy { - - @Override - public Boolean match(final List<ConditionData> conditionDataList, final ServerWebExchange exchange) { - //coding and return - return true; - } -} -``` - -* In the project `resources` directory,Create a new `META-INF/shenyu` directory, and the new file name is : `org.apache.shenyu.plugin.base.condition.strategy.MatchStrategy`. - add `${you spi name}` = `${you class path}`: - -``` -${you spi name} = ${you class path} -``` - -* In the `Admin` service ---> BasicConfig ---> Dictionary , Find the dictionary code as `MATCH_MODE`, add a new piece of data, pay attention to the dictionary name: `${you spi name}`. - -<img src="/img/shenyu/custom/custom-condition-match-en.png" width="40%" height="30%" /> - -* Or execute the following custom `SQL` statement: - -```sql -INSERT IGNORE INTO `shenyu_dict` ( - `id`, - `type`, - `dict_code`, - `dict_name`, - `dict_value`, - `desc`, - `sort`, - `enabled`, - `date_created`, - `date_updated` - ) -VALUES ( - 'you id', - 'matchMode', - 'MATCH_MODE', - 'you spi name', - 'you value', - 'you spi name', - 0, - 1, - '2021-05-30 19:29:10', - '2021-05-30 20:15:23' - ); -``` - - - - - - - diff --git a/docs/developer/spi/custom-match-mode.md b/docs/developer/spi/custom-match-mode.md new file mode 100644 index 0000000..bb517d6 --- /dev/null +++ b/docs/developer/spi/custom-match-mode.md @@ -0,0 +1,75 @@ +--- +title: Custom Match Mode +keywords: ["MatchStrategy"] +description: custom match mode +--- + + +* This paper describes how to customize the extension of `org.apache.shenyu.plugin.base.condition.strategy.MatchStrategy`. + + +* Create a new class `CustomMatchStrategy`, extends `org.apache.shenyu.plugin.base.condition.strategy.AbstractMatchStrategy`, implements `org.apache.shenyu.plugin.base.condition.strategy.MatchStrategy`, add annotation `org.apache.shenyu.spi.Join`. + +```java +/** + * This is custom match strategy. + */ +@Join +public class CustomMatchStrategy extends AbstractMatchStrategy implements MatchStrategy { + + @Override + public Boolean match(final List<ConditionData> conditionDataList, final ServerWebExchange exchange) { + // custom match strategy + } +} +``` + +* Add key-value as following in `org.apache.shenyu.plugin.base.condition.strategy.MatchStrategy` file. + +```shell script +${spi name} = ${custom class path} +``` + +`${spi name}` represents the name of `spi` and `${custom class path}` represents the fully qualified name of the class. Such as: + + +```shell script +custom = org.apache.shenyu.examples.http.strategy.CustomMatchStrategy +``` + + +* Add enum in `org.apache.shenyu.common.enums.MatchModeEnum` class: + +```java + + /** + * And custom mode enum. + */ + CUSTOM(2, "custom"), +``` + + + +* In the `Apache ShenYu` gateway management system --> BasicConfig --> Dictionary, find the dictionary code as `MATCH_MODE`, add a new piece of data, pay attention to the dictionary name: `${spi name}`. + +<img src="/img/shenyu/custom/custom_match_strategy_en.png" width="70%" height="60%" /> + +> DictionaryType: `matchMode`; +> +> DictionaryCode: `MATCH_MODE`; +> +> DictionaryName: `${spi name}`, input your custom spi name; +> +> DictionaryValue: When used, the value of the drop-down box, do not repeat with the existing; +> +> DictionaryDescribe: desc your custom match strategy; +> +> Sort: to sort; +> +> Status: open or close. + + +* When adding selectors or rules, you can use custom MatchType: + + +<img src="/img/shenyu/custom/use_custom_match_strategy_en.png" width="80%" height="70%" /> diff --git a/docs/developer/spi/custom-parameter-data.md b/docs/developer/spi/custom-parameter-data.md new file mode 100644 index 0000000..51560b8 --- /dev/null +++ b/docs/developer/spi/custom-parameter-data.md @@ -0,0 +1,75 @@ +--- +title: Custom Parameter Data +keywords: ["ParameterData"] +description: Custom Parameter Data +--- + +This paper describes how to customize the extension of `org.apache.shenyu.plugin.base.condition.data.ParameterData`. + +* Create a new class `CustomParameterData`, implements `org.apache.shenyu.plugin.base.condition.data.ParameterData`, add annotation `org.apache.shenyu.spi.Join`. + +```java +/** + * This is custom parameter data. + */ +@Join +public class CustomParameterData implements ParameterData { + + @Override + public String builder(final String paramName, final ServerWebExchange exchange) { + // custom parameter data + } +} +``` + + +* In `org.apache.shenyu.plugin.base.condition.data.ParameterData` file, add key-value as following: + +```shell script +${spi name} = ${custom class path} +``` + +`${spi name}` represents the name of `spi` and `${custom class path}` represents the fully qualified name of the class. Such as: + + +```shell script +custom=org.apache.shenyu.examples.http.condition.data.CustomParameterData +``` + +* Add enum in `org.apache.shenyu.common.enums.ParamTypeEnum` class: + +```java + + /** + * custom param type enum. + */ + CUSTOM("custom", true), +``` + + +* In the `Apache ShenYu` gateway management system --> BasicConfig --> Dictionary, find the dictionary code as `PARAM_TYPE`, add a new piece of data, pay attention to the dictionary name: `${spi name}`. + +<img src="/img/shenyu/custom/custom_parameter_data_en.png" width="70%" height="60%" /> + +> DictionaryType: `paramType`; +> +> DictionaryCode: `PARAM_TYPE`; +> +> DictionaryName: `${spi name}`, input your custom spi name; +> +> DictionaryValue: When used, the value of the drop-down box, do not repeat with the existing; +> +> DictionaryDescribe: desc your custom match strategy; +> +> Sort: to sort; +> +> Status: open or close. + + +* When adding selectors or rules, you can use custom parameter data: + + +<img src="/img/shenyu/custom/use_custom_parameter_data_en.png" width="80%" height="70%" /> + + + diff --git a/docs/developer/spi/custom-predicate-judge.md b/docs/developer/spi/custom-predicate-judge.md new file mode 100644 index 0000000..9131ea3 --- /dev/null +++ b/docs/developer/spi/custom-predicate-judge.md @@ -0,0 +1,81 @@ +--- +title: Custom Predicate Judge +keywords: ["PredicateJudge"] +description: Custom Predicate Judge +--- + + +* This paper describes how to customize the extension of `org.apache.shenyu.plugin.base.condition.judge.PredicateJudge`. + + +* Create a new class `CustomPredicateJudge`, implements `org.apache.shenyu.plugin.base.condition.judge.PredicateJudge`, add annotation `org.apache.shenyu.spi.Join`. + +```java +/** + * custom predicate judge. + */ +@Join +public class CustomPredicateJudge implements PredicateJudge { + + @Override + public Boolean judge(final ConditionData conditionData, final String realData) { + // Custom Predicate Judge + } +} + +``` + + + +* In `org.apache.shenyu.plugin.base.condition.judge.PredicateJudge` file, add key-value as following: + +```shell script +${spi name} = ${custom class path} +``` + +`${spi name}` represents the name of `spi` and `${custom class path}` represents the fully qualified name of the class. Such as: + + +```shell script +custom=org.apache.shenyu.examples.http.judge.CustomPredicateJudge +``` + + + +* Add enum in `org.apache.shenyu.common.enums.OperatorEnum` class: + +```java + + /** + * custom operator enum. + */ + CUSTOM("custom", true), +``` + + +* In the `Apache ShenYu` gateway management system --> BasicConfig --> Dictionary, find the dictionary code as `OPERATOR`, add a new piece of data, pay attention to the dictionary name: `${spi name}`. + +<img src="/img/shenyu/custom/custom_predicate_judge_en.png" width="70%" height="60%" /> + +> DictionaryType: `operator`; +> +> DictionaryCode: `OPERATOR`; +> +> DictionaryName: `${spi name}`, input your custom spi name; +> +> DictionaryValue: When used, the value of the drop-down box, do not repeat with the existing; +> +> DictionaryDescribe: desc your custom match strategy; +> +> Sort: to sort; +> +> Status: open or close. + + +* When adding selectors or rules, you can use custom predicate judge: + + +<img src="/img/shenyu/custom/use_custom_predicate_judge_en.png" width="80%" height="70%" /> + + + diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/design/_category_.json b/i18n/zh/docusaurus-plugin-content-docs/current/design/_category_.json index 738bab8..681e473 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/design/_category_.json +++ b/i18n/zh/docusaurus-plugin-content-docs/current/design/_category_.json @@ -1,4 +1,4 @@ { - "label": "设计", + "label": "设计文档", "position": 2 } diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/design/spi-design.md b/i18n/zh/docusaurus-plugin-content-docs/current/design/spi-design.md new file mode 100644 index 0000000..b464e10 --- /dev/null +++ b/i18n/zh/docusaurus-plugin-content-docs/current/design/spi-design.md @@ -0,0 +1,42 @@ +--- +title: SPI扩展 +keywords: ["spi design"] +description: 对ShenYu网关中SPI的使用进行介绍 +--- + +`SPI` 全称为 `Service Provider Interface`, 是 `JDK` 内置的一种服务提供发现功能, 一种动态替换发现的机制。 + +[shenyu-spi](https://github.com/apache/incubator-shenyu/tree/master/shenyu-spi) 是`Apache ShenYu`网关自定义的`SPI`扩展实现,设计和实现原理参考了`Dubbo`的 [SPI扩展实现](https://dubbo.apache.org/zh/docs/v2.7/dev/impls/) 。 + + +### 注册中心扩展 + +通过哪种方式实现服务的注册,当前支持`Consul`、`Etcd`、`Http`、`Nacos`和`Zookeeper`。注册中心的扩展包括客户端和服务端,接口分别为 `ShenyuServerRegisterRepository` 和 `ShenyuClientRegisterRepository` 。 + +### 监控中心扩展 + +负责服务的监控,通过`SPI`加载具体实现,当前支持`Prometheus` ,服务接口是 `MetricsBootService` 。 + +### 负载均衡扩展 + +从多个服务提供方中选择一个进行调用,当前支持的算法有`Hash`、`Random` 和 `RoundRobin`,扩展接口是 `LoadBalance` 。 + + +### RateLimiter扩展 + +在`RateLimiter`插件中,使用何种限流算法,当前支持`Concurrent`、`LeakyBucket`、`SlidingWindow` 和 `TokenBucket`,扩展接口是 `RateLimiterAlgorithm` 。 + + +### 匹配方式扩展 + +在添加选择器和规则时,使用哪种匹配方式,当前支持`And`、`Or`,扩展接口是 `MatchStrategy` 。 + + +### 条件参数扩展 + +在添加选择器和规则时,使用哪种条件参数,当前支持`URI`、`RequestMethod`、`Query`、`Post`、`IP`、`Host`、`Cookie` 和 `Header`,扩展接口是 `ParameterData` 。 + + +### 条件策略扩展 + +在添加选择器和规则时,使用哪种条件策略,当前支持`Match`、`Contains`、`Equals`、`Groovy`、`Regex`、`SpEL`、`TimerAfter` 和 `TimerBefore`,扩展接口是 `PredicateJudge` 。 diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/developer/spi/_category_.json b/i18n/zh/docusaurus-plugin-content-docs/current/developer/spi/_category_.json index 149cee9..9976e06 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/developer/spi/_category_.json +++ b/i18n/zh/docusaurus-plugin-content-docs/current/developer/spi/_category_.json @@ -1,4 +1,4 @@ { - "label": "SPI", + "label": "自定义SPI", "position": 1 } diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/developer/spi/custom-condition-match.md b/i18n/zh/docusaurus-plugin-content-docs/current/developer/spi/custom-condition-match.md deleted file mode 100644 index 864dac4..0000000 --- a/i18n/zh/docusaurus-plugin-content-docs/current/developer/spi/custom-condition-match.md +++ /dev/null @@ -1,73 +0,0 @@ ---- -title: 自定义匹配条件策略 -description: 自定义匹配条件策略 ---- - - -## 说明 - -* 在自定义开发前,请先自定义搭建好网关环境,请参考: [自定义部署](../../deployment/deployment-custom) - -* 本文介绍如何对 `org.apache.shenyu.plugin.base.condition.strategy.MatchStrategy` 进行自定义扩展。 - -## 扩展实现 - -* 新增一个类 `${you class}`,实现 `org.apache.shenyu.plugin.base.condition.strategy.MatchStrategy` - -``` -public class ${you class} implements MatchStrategy { - - @Override - public Boolean match(final List<ConditionData> conditionDataList, final ServerWebExchange exchange) { - //开发你的匹配逻辑,返回结果 - return true; - } -} -``` - -* 在项目 `resources` 目录下,新建 `META-INF/shenyu` 目录, 并且新增文件名为 : `org.apache.shenyu.plugin.base.condition.strategy.MatchStrategy`. - 内容新增 `${you spi name}` = `${you class path}`: - -``` -${you spi name} = ${you class path} -``` - -* 在 `Admin` 后台 ---> 基础管理 ---> 字典管理 , 找到字典编码为 `MATCH_MODE`,新增一条数据,注意字典名称要为: `${you spi name}`。 - -<img src="/img/shenyu/custom/custom-condition-match-zh.png" width="40%" height="30%" /> - -* 或者执行以下自定义`SQL`语句: - -```sql -INSERT IGNORE INTO `shenyu_dict` ( - `id`, - `type`, - `dict_code`, - `dict_name`, - `dict_value`, - `desc`, - `sort`, - `enabled`, - `date_created`, - `date_updated` - ) -VALUES ( - 'you id', - 'matchMode', - 'MATCH_MODE', - 'you spi name', - 'you value', - 'you spi name', - 0, - 1, - '2021-05-30 19:29:10', - '2021-05-30 20:15:23' - ); -``` - - - - - - - diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/developer/spi/custom-match-mode.md b/i18n/zh/docusaurus-plugin-content-docs/current/developer/spi/custom-match-mode.md new file mode 100644 index 0000000..44bceae --- /dev/null +++ b/i18n/zh/docusaurus-plugin-content-docs/current/developer/spi/custom-match-mode.md @@ -0,0 +1,72 @@ +--- +title: 自定义匹配方式 +keywords: ["MatchStrategy"] +description: 自定义匹配方式 +--- + +本文介绍如何对 `org.apache.shenyu.plugin.base.condition.strategy.MatchStrategy` 进行自定义扩展。 + + +* 新增一个类 `CustomMatchStrategy`,继承`org.apache.shenyu.plugin.base.condition.strategy.AbstractMatchStrategy`,实现 `org.apache.shenyu.plugin.base.condition.strategy.MatchStrategy` ,添加注解`org.apache.shenyu.spi.Join`。 + +```java +/** + * This is custom match strategy. + */ +@Join +public class CustomMatchStrategy extends AbstractMatchStrategy implements MatchStrategy { + + @Override + public Boolean match(final List<ConditionData> conditionDataList, final ServerWebExchange exchange) { + // 匹配逻辑实现 + } +} +``` + +* 在`org.apache.shenyu.plugin.base.condition.strategy.MatchStrategy`文件中添加如下内容: + +```shell script +${spi name}=${custom class path} +``` + +`${spi name}`表示`spi`的名称,`${custom class path}`表示该类的全限定名。比如: + +```shell script +custom=org.apache.shenyu.examples.http.strategy.CustomMatchStrategy +``` + +* 在 `org.apache.shenyu.common.enums.MatchModeEnum` 类中添加枚举类型: + +```java + + /** + * And custom mode enum. + */ + CUSTOM(2, "custom"), +``` + +* 在`Apache ShenYu`网关管理系统 --> 基础配置 --> 字典管理, 找到字典编码为 `MATCH_MODE`,新增一条数据,注意字典名称要为: `${spi name}`,图中的示例是`custom`。 + +<img src="/img/shenyu/custom/custom_match_strategy_zh.png" width="70%" height="60%" /> + +> 字典类型:`matchMode`; +> +> 字典编码:`MATCH_MODE`; +> +> 字典名称:`${spi name}`,填写自定义`spi`的名称; +> +> 字典值:使用时,下拉框的值,不要和现有的重复; +> +> 字典描述或备注信息:描述信息; +> +> 排序: 排序; +> +> 状态:打开或关闭。 + + + +* 在添加选择器或规则时,就可以使用自定义的匹配方式: + +<img src="/img/shenyu/custom/use_custom_match_strategy_zh.png" width="80%" height="70%" /> + + diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/developer/spi/custom-parameter-data.md b/i18n/zh/docusaurus-plugin-content-docs/current/developer/spi/custom-parameter-data.md new file mode 100644 index 0000000..b878801 --- /dev/null +++ b/i18n/zh/docusaurus-plugin-content-docs/current/developer/spi/custom-parameter-data.md @@ -0,0 +1,71 @@ +--- +title: 自定义条件参数 +keywords: ["ParameterData"] +description: 自定义条件参数 +--- + +本文介绍如何对 `org.apache.shenyu.plugin.base.condition.data.ParameterData` 进行自定义扩展。 + + +* 新增一个类 `CustomParameterData`,实现 `org.apache.shenyu.plugin.base.condition.data.ParameterData` 接口 ,添加注解`org.apache.shenyu.spi.Join`。 + +```java +/** + * This is custom parameter data. + */ +@Join +public class CustomParameterData implements ParameterData { + + @Override + public String builder(final String paramName, final ServerWebExchange exchange) { + // 自定义条件参数 + } +} +``` + +* 在 `org.apache.shenyu.plugin.base.condition.data.ParameterData` 文件中添加如下内容: + +```shell script +${spi name}=${custom class path} +``` + +`${spi name}`表示`spi`的名称,`${custom class path}`表示该类的全限定名。比如: + +```shell script +custom=org.apache.shenyu.examples.http.condition.data.CustomParameterData +``` + +* 在 `org.apache.shenyu.common.enums.ParamTypeEnum` 类中添加枚举类型: + +```java + /** + * custom param type enum. + */ + CUSTOM("custom", true), +``` + + +* 在`Apache ShenYu`网关管理系统 --> 基础配置 --> 字典管理, 找到字典编码为 `PARAM_TYPE`,新增一条数据,注意字典名称要为: `${spi name}`,图中的示例是`custom`。 + +<img src="/img/shenyu/custom/custom_parameter_data_zh.png" width="70%" height="60%" /> + +> 字典类型:`paramType`; +> +> 字典编码:`PARAM_TYPE`; +> +> 字典名称:`${spi name}`,填写自定义`spi`的名称; +> +> 字典值:使用时,下拉框的值,不要和现有的重复; +> +> 字典描述或备注信息:描述信息; +> +> 排序: 排序; +> +> 状态:打开或关闭。 + + +* 在添加选择器或规则时,就可以使用自定义的条件参数: + +<img src="/img/shenyu/custom/use_custom_parameter_data_zh.png" width="80%" height="70%" /> + + diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/developer/spi/custom-predicate-judge.md b/i18n/zh/docusaurus-plugin-content-docs/current/developer/spi/custom-predicate-judge.md new file mode 100644 index 0000000..418aef4 --- /dev/null +++ b/i18n/zh/docusaurus-plugin-content-docs/current/developer/spi/custom-predicate-judge.md @@ -0,0 +1,75 @@ +--- +title: 自定义条件策略 +keywords: ["PredicateJudge"] +description: 自定义条件策略 +--- + + +* 本文介绍如何对 `org.apache.shenyu.plugin.base.condition.judge.PredicateJudge` 进行自定义扩展。 + + +* 新增一个类 `CustomPredicateJudge`,实现 `org.apache.shenyu.plugin.base.condition.judge.PredicateJudge` 接口 ,添加注解`org.apache.shenyu.spi.Join`。 + +```java +/** + * custom predicate judge. + */ +@Join +public class CustomPredicateJudge implements PredicateJudge { + + @Override + public Boolean judge(final ConditionData conditionData, final String realData) { + // 自定义条件策略 + } +} + +``` + +* 在 `org.apache.shenyu.plugin.base.condition.judge.PredicateJudge` 文件中添加如下内容: + +```shell script +${spi name}=${custom class path} +``` + +`${spi name}`表示`spi`的名称,`${custom class path}`表示该类的全限定名。比如: + +```shell script +custom=org.apache.shenyu.examples.http.judge.CustomPredicateJudge +``` + + +* 在 `org.apache.shenyu.common.enums.OperatorEnum` 类中添加枚举类型: + +```java + /** + * custom operator enum. + */ + CUSTOM("custom", true), +``` + + +* 在`Apache ShenYu`网关管理系统 --> 基础配置 --> 字典管理, 找到字典编码为 `OPERATOR`,新增一条数据,注意字典名称要为: `${spi name}`,图中的示例是`custom`。 + +<img src="/img/shenyu/custom/custom_predicate_judge_zh.png" width="70%" height="60%" /> + +> 字典类型:`operator`; +> +> 字典编码:`OPERATOR`; +> +> 字典名称:`${spi name}`,填写自定义`spi`的名称; +> +> 字典值:使用时,下拉框的值,不要和现有的重复; +> +> 字典描述或备注信息:描述信息; +> +> 排序: 排序; +> +> 状态:打开或关闭。 + + + +* 在添加选择器或规则时,就可以使用自定义的条件策略: + +<img src="/img/shenyu/custom/use_custom_predicate_judge_zh.png" width="80%" height="70%" /> + + diff --git a/i18n/zh/docusaurus-plugin-content-docs/version-2.4.0/design/_category_.json b/i18n/zh/docusaurus-plugin-content-docs/version-2.4.0/design/_category_.json index 738bab8..681e473 100755 --- a/i18n/zh/docusaurus-plugin-content-docs/version-2.4.0/design/_category_.json +++ b/i18n/zh/docusaurus-plugin-content-docs/version-2.4.0/design/_category_.json @@ -1,4 +1,4 @@ { - "label": "设计", + "label": "设计文档", "position": 2 } diff --git a/i18n/zh/docusaurus-plugin-content-docs/version-2.4.0/design/spi-design.md b/i18n/zh/docusaurus-plugin-content-docs/version-2.4.0/design/spi-design.md new file mode 100644 index 0000000..b464e10 --- /dev/null +++ b/i18n/zh/docusaurus-plugin-content-docs/version-2.4.0/design/spi-design.md @@ -0,0 +1,42 @@ +--- +title: SPI扩展 +keywords: ["spi design"] +description: 对ShenYu网关中SPI的使用进行介绍 +--- + +`SPI` 全称为 `Service Provider Interface`, 是 `JDK` 内置的一种服务提供发现功能, 一种动态替换发现的机制。 + +[shenyu-spi](https://github.com/apache/incubator-shenyu/tree/master/shenyu-spi) 是`Apache ShenYu`网关自定义的`SPI`扩展实现,设计和实现原理参考了`Dubbo`的 [SPI扩展实现](https://dubbo.apache.org/zh/docs/v2.7/dev/impls/) 。 + + +### 注册中心扩展 + +通过哪种方式实现服务的注册,当前支持`Consul`、`Etcd`、`Http`、`Nacos`和`Zookeeper`。注册中心的扩展包括客户端和服务端,接口分别为 `ShenyuServerRegisterRepository` 和 `ShenyuClientRegisterRepository` 。 + +### 监控中心扩展 + +负责服务的监控,通过`SPI`加载具体实现,当前支持`Prometheus` ,服务接口是 `MetricsBootService` 。 + +### 负载均衡扩展 + +从多个服务提供方中选择一个进行调用,当前支持的算法有`Hash`、`Random` 和 `RoundRobin`,扩展接口是 `LoadBalance` 。 + + +### RateLimiter扩展 + +在`RateLimiter`插件中,使用何种限流算法,当前支持`Concurrent`、`LeakyBucket`、`SlidingWindow` 和 `TokenBucket`,扩展接口是 `RateLimiterAlgorithm` 。 + + +### 匹配方式扩展 + +在添加选择器和规则时,使用哪种匹配方式,当前支持`And`、`Or`,扩展接口是 `MatchStrategy` 。 + + +### 条件参数扩展 + +在添加选择器和规则时,使用哪种条件参数,当前支持`URI`、`RequestMethod`、`Query`、`Post`、`IP`、`Host`、`Cookie` 和 `Header`,扩展接口是 `ParameterData` 。 + + +### 条件策略扩展 + +在添加选择器和规则时,使用哪种条件策略,当前支持`Match`、`Contains`、`Equals`、`Groovy`、`Regex`、`SpEL`、`TimerAfter` 和 `TimerBefore`,扩展接口是 `PredicateJudge` 。 diff --git a/i18n/zh/docusaurus-plugin-content-docs/version-2.4.0/developer/spi/_category_.json b/i18n/zh/docusaurus-plugin-content-docs/version-2.4.0/developer/spi/_category_.json index 149cee9..9976e06 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/version-2.4.0/developer/spi/_category_.json +++ b/i18n/zh/docusaurus-plugin-content-docs/version-2.4.0/developer/spi/_category_.json @@ -1,4 +1,4 @@ { - "label": "SPI", + "label": "自定义SPI", "position": 1 } diff --git a/i18n/zh/docusaurus-plugin-content-docs/version-2.4.0/developer/spi/custom-condition-match.md b/i18n/zh/docusaurus-plugin-content-docs/version-2.4.0/developer/spi/custom-condition-match.md deleted file mode 100644 index 864dac4..0000000 --- a/i18n/zh/docusaurus-plugin-content-docs/version-2.4.0/developer/spi/custom-condition-match.md +++ /dev/null @@ -1,73 +0,0 @@ ---- -title: 自定义匹配条件策略 -description: 自定义匹配条件策略 ---- - - -## 说明 - -* 在自定义开发前,请先自定义搭建好网关环境,请参考: [自定义部署](../../deployment/deployment-custom) - -* 本文介绍如何对 `org.apache.shenyu.plugin.base.condition.strategy.MatchStrategy` 进行自定义扩展。 - -## 扩展实现 - -* 新增一个类 `${you class}`,实现 `org.apache.shenyu.plugin.base.condition.strategy.MatchStrategy` - -``` -public class ${you class} implements MatchStrategy { - - @Override - public Boolean match(final List<ConditionData> conditionDataList, final ServerWebExchange exchange) { - //开发你的匹配逻辑,返回结果 - return true; - } -} -``` - -* 在项目 `resources` 目录下,新建 `META-INF/shenyu` 目录, 并且新增文件名为 : `org.apache.shenyu.plugin.base.condition.strategy.MatchStrategy`. - 内容新增 `${you spi name}` = `${you class path}`: - -``` -${you spi name} = ${you class path} -``` - -* 在 `Admin` 后台 ---> 基础管理 ---> 字典管理 , 找到字典编码为 `MATCH_MODE`,新增一条数据,注意字典名称要为: `${you spi name}`。 - -<img src="/img/shenyu/custom/custom-condition-match-zh.png" width="40%" height="30%" /> - -* 或者执行以下自定义`SQL`语句: - -```sql -INSERT IGNORE INTO `shenyu_dict` ( - `id`, - `type`, - `dict_code`, - `dict_name`, - `dict_value`, - `desc`, - `sort`, - `enabled`, - `date_created`, - `date_updated` - ) -VALUES ( - 'you id', - 'matchMode', - 'MATCH_MODE', - 'you spi name', - 'you value', - 'you spi name', - 0, - 1, - '2021-05-30 19:29:10', - '2021-05-30 20:15:23' - ); -``` - - - - - - - diff --git a/i18n/zh/docusaurus-plugin-content-docs/version-2.4.0/developer/spi/custom-match-mode.md b/i18n/zh/docusaurus-plugin-content-docs/version-2.4.0/developer/spi/custom-match-mode.md new file mode 100644 index 0000000..44bceae --- /dev/null +++ b/i18n/zh/docusaurus-plugin-content-docs/version-2.4.0/developer/spi/custom-match-mode.md @@ -0,0 +1,72 @@ +--- +title: 自定义匹配方式 +keywords: ["MatchStrategy"] +description: 自定义匹配方式 +--- + +本文介绍如何对 `org.apache.shenyu.plugin.base.condition.strategy.MatchStrategy` 进行自定义扩展。 + + +* 新增一个类 `CustomMatchStrategy`,继承`org.apache.shenyu.plugin.base.condition.strategy.AbstractMatchStrategy`,实现 `org.apache.shenyu.plugin.base.condition.strategy.MatchStrategy` ,添加注解`org.apache.shenyu.spi.Join`。 + +```java +/** + * This is custom match strategy. + */ +@Join +public class CustomMatchStrategy extends AbstractMatchStrategy implements MatchStrategy { + + @Override + public Boolean match(final List<ConditionData> conditionDataList, final ServerWebExchange exchange) { + // 匹配逻辑实现 + } +} +``` + +* 在`org.apache.shenyu.plugin.base.condition.strategy.MatchStrategy`文件中添加如下内容: + +```shell script +${spi name}=${custom class path} +``` + +`${spi name}`表示`spi`的名称,`${custom class path}`表示该类的全限定名。比如: + +```shell script +custom=org.apache.shenyu.examples.http.strategy.CustomMatchStrategy +``` + +* 在 `org.apache.shenyu.common.enums.MatchModeEnum` 类中添加枚举类型: + +```java + + /** + * And custom mode enum. + */ + CUSTOM(2, "custom"), +``` + +* 在`Apache ShenYu`网关管理系统 --> 基础配置 --> 字典管理, 找到字典编码为 `MATCH_MODE`,新增一条数据,注意字典名称要为: `${spi name}`,图中的示例是`custom`。 + +<img src="/img/shenyu/custom/custom_match_strategy_zh.png" width="70%" height="60%" /> + +> 字典类型:`matchMode`; +> +> 字典编码:`MATCH_MODE`; +> +> 字典名称:`${spi name}`,填写自定义`spi`的名称; +> +> 字典值:使用时,下拉框的值,不要和现有的重复; +> +> 字典描述或备注信息:描述信息; +> +> 排序: 排序; +> +> 状态:打开或关闭。 + + + +* 在添加选择器或规则时,就可以使用自定义的匹配方式: + +<img src="/img/shenyu/custom/use_custom_match_strategy_zh.png" width="80%" height="70%" /> + + diff --git a/i18n/zh/docusaurus-plugin-content-docs/version-2.4.0/developer/spi/custom-parameter-data.md b/i18n/zh/docusaurus-plugin-content-docs/version-2.4.0/developer/spi/custom-parameter-data.md new file mode 100644 index 0000000..b878801 --- /dev/null +++ b/i18n/zh/docusaurus-plugin-content-docs/version-2.4.0/developer/spi/custom-parameter-data.md @@ -0,0 +1,71 @@ +--- +title: 自定义条件参数 +keywords: ["ParameterData"] +description: 自定义条件参数 +--- + +本文介绍如何对 `org.apache.shenyu.plugin.base.condition.data.ParameterData` 进行自定义扩展。 + + +* 新增一个类 `CustomParameterData`,实现 `org.apache.shenyu.plugin.base.condition.data.ParameterData` 接口 ,添加注解`org.apache.shenyu.spi.Join`。 + +```java +/** + * This is custom parameter data. + */ +@Join +public class CustomParameterData implements ParameterData { + + @Override + public String builder(final String paramName, final ServerWebExchange exchange) { + // 自定义条件参数 + } +} +``` + +* 在 `org.apache.shenyu.plugin.base.condition.data.ParameterData` 文件中添加如下内容: + +```shell script +${spi name}=${custom class path} +``` + +`${spi name}`表示`spi`的名称,`${custom class path}`表示该类的全限定名。比如: + +```shell script +custom=org.apache.shenyu.examples.http.condition.data.CustomParameterData +``` + +* 在 `org.apache.shenyu.common.enums.ParamTypeEnum` 类中添加枚举类型: + +```java + /** + * custom param type enum. + */ + CUSTOM("custom", true), +``` + + +* 在`Apache ShenYu`网关管理系统 --> 基础配置 --> 字典管理, 找到字典编码为 `PARAM_TYPE`,新增一条数据,注意字典名称要为: `${spi name}`,图中的示例是`custom`。 + +<img src="/img/shenyu/custom/custom_parameter_data_zh.png" width="70%" height="60%" /> + +> 字典类型:`paramType`; +> +> 字典编码:`PARAM_TYPE`; +> +> 字典名称:`${spi name}`,填写自定义`spi`的名称; +> +> 字典值:使用时,下拉框的值,不要和现有的重复; +> +> 字典描述或备注信息:描述信息; +> +> 排序: 排序; +> +> 状态:打开或关闭。 + + +* 在添加选择器或规则时,就可以使用自定义的条件参数: + +<img src="/img/shenyu/custom/use_custom_parameter_data_zh.png" width="80%" height="70%" /> + + diff --git a/i18n/zh/docusaurus-plugin-content-docs/version-2.4.0/developer/spi/custom-predicate-judge.md b/i18n/zh/docusaurus-plugin-content-docs/version-2.4.0/developer/spi/custom-predicate-judge.md new file mode 100644 index 0000000..418aef4 --- /dev/null +++ b/i18n/zh/docusaurus-plugin-content-docs/version-2.4.0/developer/spi/custom-predicate-judge.md @@ -0,0 +1,75 @@ +--- +title: 自定义条件策略 +keywords: ["PredicateJudge"] +description: 自定义条件策略 +--- + + +* 本文介绍如何对 `org.apache.shenyu.plugin.base.condition.judge.PredicateJudge` 进行自定义扩展。 + + +* 新增一个类 `CustomPredicateJudge`,实现 `org.apache.shenyu.plugin.base.condition.judge.PredicateJudge` 接口 ,添加注解`org.apache.shenyu.spi.Join`。 + +```java +/** + * custom predicate judge. + */ +@Join +public class CustomPredicateJudge implements PredicateJudge { + + @Override + public Boolean judge(final ConditionData conditionData, final String realData) { + // 自定义条件策略 + } +} + +``` + +* 在 `org.apache.shenyu.plugin.base.condition.judge.PredicateJudge` 文件中添加如下内容: + +```shell script +${spi name}=${custom class path} +``` + +`${spi name}`表示`spi`的名称,`${custom class path}`表示该类的全限定名。比如: + +```shell script +custom=org.apache.shenyu.examples.http.judge.CustomPredicateJudge +``` + + +* 在 `org.apache.shenyu.common.enums.OperatorEnum` 类中添加枚举类型: + +```java + /** + * custom operator enum. + */ + CUSTOM("custom", true), +``` + + +* 在`Apache ShenYu`网关管理系统 --> 基础配置 --> 字典管理, 找到字典编码为 `OPERATOR`,新增一条数据,注意字典名称要为: `${spi name}`,图中的示例是`custom`。 + +<img src="/img/shenyu/custom/custom_predicate_judge_zh.png" width="70%" height="60%" /> + +> 字典类型:`operator`; +> +> 字典编码:`OPERATOR`; +> +> 字典名称:`${spi name}`,填写自定义`spi`的名称; +> +> 字典值:使用时,下拉框的值,不要和现有的重复; +> +> 字典描述或备注信息:描述信息; +> +> 排序: 排序; +> +> 状态:打开或关闭。 + + + +* 在添加选择器或规则时,就可以使用自定义的条件策略: + +<img src="/img/shenyu/custom/use_custom_predicate_judge_zh.png" width="80%" height="70%" /> + + diff --git a/static/img/shenyu/custom/custom_parameter_data_en.png b/static/img/shenyu/custom/custom_parameter_data_en.png new file mode 100644 index 0000000..a256f7b Binary files /dev/null and b/static/img/shenyu/custom/custom_parameter_data_en.png differ diff --git a/static/img/shenyu/custom/custom_parameter_data_zh.png b/static/img/shenyu/custom/custom_parameter_data_zh.png new file mode 100644 index 0000000..80fb34e Binary files /dev/null and b/static/img/shenyu/custom/custom_parameter_data_zh.png differ diff --git a/static/img/shenyu/custom/custom_predicate_judge_en.png b/static/img/shenyu/custom/custom_predicate_judge_en.png new file mode 100644 index 0000000..4aae456 Binary files /dev/null and b/static/img/shenyu/custom/custom_predicate_judge_en.png differ diff --git a/static/img/shenyu/custom/custom_predicate_judge_zh.png b/static/img/shenyu/custom/custom_predicate_judge_zh.png new file mode 100644 index 0000000..82a7f57 Binary files /dev/null and b/static/img/shenyu/custom/custom_predicate_judge_zh.png differ diff --git a/static/img/shenyu/custom/use_custom_parameter_data_en.png b/static/img/shenyu/custom/use_custom_parameter_data_en.png new file mode 100644 index 0000000..268e639 Binary files /dev/null and b/static/img/shenyu/custom/use_custom_parameter_data_en.png differ diff --git a/static/img/shenyu/custom/use_custom_parameter_data_zh.png b/static/img/shenyu/custom/use_custom_parameter_data_zh.png new file mode 100644 index 0000000..71ff71a Binary files /dev/null and b/static/img/shenyu/custom/use_custom_parameter_data_zh.png differ diff --git a/static/img/shenyu/custom/use_custom_predicate_judge_en.png b/static/img/shenyu/custom/use_custom_predicate_judge_en.png new file mode 100644 index 0000000..ed2112e Binary files /dev/null and b/static/img/shenyu/custom/use_custom_predicate_judge_en.png differ diff --git a/static/img/shenyu/custom/use_custom_predicate_judge_zh.png b/static/img/shenyu/custom/use_custom_predicate_judge_zh.png new file mode 100644 index 0000000..fd348c3 Binary files /dev/null and b/static/img/shenyu/custom/use_custom_predicate_judge_zh.png differ diff --git a/versioned_docs/version-2.4.0/design/spi-design.md b/versioned_docs/version-2.4.0/design/spi-design.md new file mode 100644 index 0000000..260ee65 --- /dev/null +++ b/versioned_docs/version-2.4.0/design/spi-design.md @@ -0,0 +1,49 @@ +--- +title: SPI Design +keywords: ["spi design"] +description: spi-design +--- + + +SPI, called Service Provider Interface, is a built-in JDK Service that provides discovery function and a dynamic replacement discovery mechanism. + + +[shenyu-spi](https://github.com/apache/incubator-shenyu/tree/master/shenyu-spi) is a custom SPI extension implementation for Apache Shenyu gateway. The design and implementation principles refer to [SPI Extension Implementations](https://dubbo.apache.org/en/docs/v2.7/dev/impls/) . + + +### Registry Center + +`Consul`, `Etcd`, `Http`, `Nacos` and `Zookeeper` are supported. The expansion of the registry including client and server, interface respectively `ShenyuServerRegisterRepository` and `ShenyuClientRegisterRepository`. + +### Metrics Center + +Responsible for service monitoring, loading concrete implementation through `SPI`, currently support `Prometheus`, service interface is `MetricsBootService`. + + + +### Load Balance + +Select one of the service providers to call. Currently, the supported algorithms are `Has`, `Random`, and `RoundRobin`, and the extended interface is `LoadBalance`. + +### RateLimiter + + +In the `RateLimiter` plugin, which stream limiting algorithm to use, currently supporting `Concurren`, `LeakyBucke`, `SlidingWindow` and `TokenBucket`, the extension interface is `RateLimiterAlgorithm`. + + +### Match Strategy + +Which matching method to use when adding selectors And rules, currently supports `And`, `Or`, And the extension interface is `MatchStrategy`. + + +### Parameter Data + + +Currently, `URI`,`RequestMethod`, `Query`, `Post`, `IP`, `Host`, `Cookie`, and `Header` are supported. The extended interface is `ParameterData`. + + +### Predicate Judge + +Which conditional policy to use when adding selectors and rules currently supports `Match`, `Contains`,`Equals`, `Groovy`, `Regex`, `SpEL`, `TimerAfter` and `TimerBefore`. The extension interface is `PredicateJudge`. + + diff --git a/versioned_docs/version-2.4.0/developer/spi/custom-condition-match.md b/versioned_docs/version-2.4.0/developer/spi/custom-condition-match.md deleted file mode 100644 index a95c087..0000000 --- a/versioned_docs/version-2.4.0/developer/spi/custom-condition-match.md +++ /dev/null @@ -1,74 +0,0 @@ ---- -title: Custom Condition Match -keywords: ["Condition"] -description: custom condition match ---- - - -## Explanation - -* Before custom development, please customize and build the gateway environment first, please refer to: [custom deployment](../../deployment/deployment-custom) - -* This article describes how to customize the extension of `org.apache.shenyu.plugin.base.condition.strategy.MatchStrategy`. - -## Extension - -* Create a new class `${you class}`,implements `org.apache.shenyu.plugin.base.condition.strategy.MatchStrategy` - -``` -public class ${you class} implements MatchStrategy { - - @Override - public Boolean match(final List<ConditionData> conditionDataList, final ServerWebExchange exchange) { - //coding and return - return true; - } -} -``` - -* In the project `resources` directory,Create a new `META-INF/shenyu` directory, and the new file name is : `org.apache.shenyu.plugin.base.condition.strategy.MatchStrategy`. - add `${you spi name}` = `${you class path}`: - -``` -${you spi name} = ${you class path} -``` - -* In the `Admin` service ---> BasicConfig ---> Dictionary , Find the dictionary code as `MATCH_MODE`, add a new piece of data, pay attention to the dictionary name: `${you spi name}`. - -<img src="/img/shenyu/custom/custom-condition-match-en.png" width="40%" height="30%" /> - -* Or execute the following custom `SQL` statement: - -```sql -INSERT IGNORE INTO `shenyu_dict` ( - `id`, - `type`, - `dict_code`, - `dict_name`, - `dict_value`, - `desc`, - `sort`, - `enabled`, - `date_created`, - `date_updated` - ) -VALUES ( - 'you id', - 'matchMode', - 'MATCH_MODE', - 'you spi name', - 'you value', - 'you spi name', - 0, - 1, - '2021-05-30 19:29:10', - '2021-05-30 20:15:23' - ); -``` - - - - - - - diff --git a/versioned_docs/version-2.4.0/developer/spi/custom-match-mode.md b/versioned_docs/version-2.4.0/developer/spi/custom-match-mode.md new file mode 100644 index 0000000..bb517d6 --- /dev/null +++ b/versioned_docs/version-2.4.0/developer/spi/custom-match-mode.md @@ -0,0 +1,75 @@ +--- +title: Custom Match Mode +keywords: ["MatchStrategy"] +description: custom match mode +--- + + +* This paper describes how to customize the extension of `org.apache.shenyu.plugin.base.condition.strategy.MatchStrategy`. + + +* Create a new class `CustomMatchStrategy`, extends `org.apache.shenyu.plugin.base.condition.strategy.AbstractMatchStrategy`, implements `org.apache.shenyu.plugin.base.condition.strategy.MatchStrategy`, add annotation `org.apache.shenyu.spi.Join`. + +```java +/** + * This is custom match strategy. + */ +@Join +public class CustomMatchStrategy extends AbstractMatchStrategy implements MatchStrategy { + + @Override + public Boolean match(final List<ConditionData> conditionDataList, final ServerWebExchange exchange) { + // custom match strategy + } +} +``` + +* Add key-value as following in `org.apache.shenyu.plugin.base.condition.strategy.MatchStrategy` file. + +```shell script +${spi name} = ${custom class path} +``` + +`${spi name}` represents the name of `spi` and `${custom class path}` represents the fully qualified name of the class. Such as: + + +```shell script +custom = org.apache.shenyu.examples.http.strategy.CustomMatchStrategy +``` + + +* Add enum in `org.apache.shenyu.common.enums.MatchModeEnum` class: + +```java + + /** + * And custom mode enum. + */ + CUSTOM(2, "custom"), +``` + + + +* In the `Apache ShenYu` gateway management system --> BasicConfig --> Dictionary, find the dictionary code as `MATCH_MODE`, add a new piece of data, pay attention to the dictionary name: `${spi name}`. + +<img src="/img/shenyu/custom/custom_match_strategy_en.png" width="70%" height="60%" /> + +> DictionaryType: `matchMode`; +> +> DictionaryCode: `MATCH_MODE`; +> +> DictionaryName: `${spi name}`, input your custom spi name; +> +> DictionaryValue: When used, the value of the drop-down box, do not repeat with the existing; +> +> DictionaryDescribe: desc your custom match strategy; +> +> Sort: to sort; +> +> Status: open or close. + + +* When adding selectors or rules, you can use custom MatchType: + + +<img src="/img/shenyu/custom/use_custom_match_strategy_en.png" width="80%" height="70%" /> diff --git a/versioned_docs/version-2.4.0/developer/spi/custom-parameter-data.md b/versioned_docs/version-2.4.0/developer/spi/custom-parameter-data.md new file mode 100644 index 0000000..51560b8 --- /dev/null +++ b/versioned_docs/version-2.4.0/developer/spi/custom-parameter-data.md @@ -0,0 +1,75 @@ +--- +title: Custom Parameter Data +keywords: ["ParameterData"] +description: Custom Parameter Data +--- + +This paper describes how to customize the extension of `org.apache.shenyu.plugin.base.condition.data.ParameterData`. + +* Create a new class `CustomParameterData`, implements `org.apache.shenyu.plugin.base.condition.data.ParameterData`, add annotation `org.apache.shenyu.spi.Join`. + +```java +/** + * This is custom parameter data. + */ +@Join +public class CustomParameterData implements ParameterData { + + @Override + public String builder(final String paramName, final ServerWebExchange exchange) { + // custom parameter data + } +} +``` + + +* In `org.apache.shenyu.plugin.base.condition.data.ParameterData` file, add key-value as following: + +```shell script +${spi name} = ${custom class path} +``` + +`${spi name}` represents the name of `spi` and `${custom class path}` represents the fully qualified name of the class. Such as: + + +```shell script +custom=org.apache.shenyu.examples.http.condition.data.CustomParameterData +``` + +* Add enum in `org.apache.shenyu.common.enums.ParamTypeEnum` class: + +```java + + /** + * custom param type enum. + */ + CUSTOM("custom", true), +``` + + +* In the `Apache ShenYu` gateway management system --> BasicConfig --> Dictionary, find the dictionary code as `PARAM_TYPE`, add a new piece of data, pay attention to the dictionary name: `${spi name}`. + +<img src="/img/shenyu/custom/custom_parameter_data_en.png" width="70%" height="60%" /> + +> DictionaryType: `paramType`; +> +> DictionaryCode: `PARAM_TYPE`; +> +> DictionaryName: `${spi name}`, input your custom spi name; +> +> DictionaryValue: When used, the value of the drop-down box, do not repeat with the existing; +> +> DictionaryDescribe: desc your custom match strategy; +> +> Sort: to sort; +> +> Status: open or close. + + +* When adding selectors or rules, you can use custom parameter data: + + +<img src="/img/shenyu/custom/use_custom_parameter_data_en.png" width="80%" height="70%" /> + + + diff --git a/versioned_docs/version-2.4.0/developer/spi/custom-predicate-judge.md b/versioned_docs/version-2.4.0/developer/spi/custom-predicate-judge.md new file mode 100644 index 0000000..9131ea3 --- /dev/null +++ b/versioned_docs/version-2.4.0/developer/spi/custom-predicate-judge.md @@ -0,0 +1,81 @@ +--- +title: Custom Predicate Judge +keywords: ["PredicateJudge"] +description: Custom Predicate Judge +--- + + +* This paper describes how to customize the extension of `org.apache.shenyu.plugin.base.condition.judge.PredicateJudge`. + + +* Create a new class `CustomPredicateJudge`, implements `org.apache.shenyu.plugin.base.condition.judge.PredicateJudge`, add annotation `org.apache.shenyu.spi.Join`. + +```java +/** + * custom predicate judge. + */ +@Join +public class CustomPredicateJudge implements PredicateJudge { + + @Override + public Boolean judge(final ConditionData conditionData, final String realData) { + // Custom Predicate Judge + } +} + +``` + + + +* In `org.apache.shenyu.plugin.base.condition.judge.PredicateJudge` file, add key-value as following: + +```shell script +${spi name} = ${custom class path} +``` + +`${spi name}` represents the name of `spi` and `${custom class path}` represents the fully qualified name of the class. Such as: + + +```shell script +custom=org.apache.shenyu.examples.http.judge.CustomPredicateJudge +``` + + + +* Add enum in `org.apache.shenyu.common.enums.OperatorEnum` class: + +```java + + /** + * custom operator enum. + */ + CUSTOM("custom", true), +``` + + +* In the `Apache ShenYu` gateway management system --> BasicConfig --> Dictionary, find the dictionary code as `OPERATOR`, add a new piece of data, pay attention to the dictionary name: `${spi name}`. + +<img src="/img/shenyu/custom/custom_predicate_judge_en.png" width="70%" height="60%" /> + +> DictionaryType: `operator`; +> +> DictionaryCode: `OPERATOR`; +> +> DictionaryName: `${spi name}`, input your custom spi name; +> +> DictionaryValue: When used, the value of the drop-down box, do not repeat with the existing; +> +> DictionaryDescribe: desc your custom match strategy; +> +> Sort: to sort; +> +> Status: open or close. + + +* When adding selectors or rules, you can use custom predicate judge: + + +<img src="/img/shenyu/custom/use_custom_predicate_judge_en.png" width="80%" height="70%" /> + + +
