You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by zh...@apache.org on 2021/07/29 08:39:06 UTC

[incubator-shenyu-website] branch main updated: add custom condition match (#158)

This is an automated email from the ASF dual-hosted git repository.

zhangyonglun pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-shenyu-website.git


The following commit(s) were added to refs/heads/main by this push:
     new 92dd777  add custom condition match (#158)
92dd777 is described below

commit 92dd777a5e88d3f877c3687eec99362dd31a36d7
Author: xiaoyu <xi...@apache.org>
AuthorDate: Thu Jul 29 16:39:01 2021 +0800

    add custom condition match (#158)
---
 content/zh/projects/shenyu/_index.md               |   8 ++--
 .../shenyu/custom-condition-match/index.md         |  51 +++++++++++++++++++++
 content/zh/projects/shenyu/flow-control/index.md   |  10 ++++
 .../shenyu/custom/custmo-condition-match-zh.png    | Bin 0 -> 21903 bytes
 static/img/shenyu/design/flow-condition.png        | Bin 0 -> 70752 bytes
 5 files changed, 66 insertions(+), 3 deletions(-)

diff --git a/content/zh/projects/shenyu/_index.md b/content/zh/projects/shenyu/_index.md
index c2ef876..8dca85f 100644
--- a/content/zh/projects/shenyu/_index.md
+++ b/content/zh/projects/shenyu/_index.md
@@ -34,7 +34,7 @@ sidebar:
     link: 'overview'
   - title: '设计文档'
     sub:
-      - title: 'ShenYu Admin数据结构'
+      - title: 'Admin数据结构'
         link: 'database-design'      
       - title: '数据同步原理'
         link: 'data-sync'
@@ -42,6 +42,8 @@ sidebar:
         link: 'register-center-design'
       - title: '流量控制'
         link: 'flow-control'
+      - title: 'SPI扩展设计'
+        link: 'spi-design'  
   - title: '运维部署'
     sub:
       - title: '本地部署'
@@ -175,14 +177,14 @@ sidebar:
         link: 'custom-result'
       - title: '自定义签名插件算法与验证'
         link: 'custom-sign-algorithm' 
+      - title: '自定义匹配条件策略'
+        link: 'custom-condition-match'   
       - title: '多语言Http客户端接入'
         link: 'developer-shenyu-client'
       - title: '线程模型'
         link: 'thread'
       - title: 'ShenYu调优'
         link: 'shenyu-optimize'
-      - title: 'SPI'
-        link: 'spi-design'
   - title: '版本发布'
     link: 'release-notes'
   - title: '文档下载'
diff --git a/content/zh/projects/shenyu/custom-condition-match/index.md b/content/zh/projects/shenyu/custom-condition-match/index.md
new file mode 100644
index 0000000..eb53cce
--- /dev/null
+++ b/content/zh/projects/shenyu/custom-condition-match/index.md
@@ -0,0 +1,51 @@
+---
+title: 自定义匹配条件策略
+keywords: ShenYu
+description: 自定义匹配条件策略
+---
+
+
+## 说明
+
+* 在自定义开发前,请先自定义搭建好网关环境,请参考: [自定义部署](../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/custmo-condition-match-zh.png" width="40%" height="30%" />
+
+* 或者执行以下自定义`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/content/zh/projects/shenyu/flow-control/index.md b/content/zh/projects/shenyu/flow-control/index.md
index f411ede..871ecda 100644
--- a/content/zh/projects/shenyu/flow-control/index.md
+++ b/content/zh/projects/shenyu/flow-control/index.md
@@ -23,3 +23,13 @@ description:  介绍ShenYu网关如何对流量进行控制
 插件、选择器和规则执行逻辑如下,当流量进入到`ShenYu`网关之后,会先判断是否有对应的插件,该插件是否开启;然后判断流量是否匹配该插件的选择器;然后再判断流量是否匹配该选择器的规则。如果请求流量能满足匹配条件才会执行该插件,否则插件不会被执行,处理下一个。`ShenYu`网关就是这样通过层层筛选完成流量控制。
 
 <img src="/img/shenyu/plugin/plugin-chain-execute.png" width="40%" height="30%" />
+
+## 流量筛选
+
+<img src="/img/shenyu/design/flow-condition.png" width="30%" height="30%" />
+
+流量筛选,是选择器和规则的灵魂,对应为选择器与规则里面的匹配条件(conditions),根据不同的流量筛选规则,我们可以处理各种复杂的场景。流量筛选可以从`Header`, `URI`,  `Query`, `Cookie` 等等Http请求获取数据,
+
+然后可以采用 `Match`,`=`,`SpEL`,`Regex`,`Groovy`等匹配方式,匹配出你所预想的数据。多组匹配添加可以使用And/Or的匹配策略。
+
+具体的介绍与使用请看: [选择器与规则管理](../selector-and-rule)
\ No newline at end of file
diff --git a/static/img/shenyu/custom/custmo-condition-match-zh.png b/static/img/shenyu/custom/custmo-condition-match-zh.png
new file mode 100644
index 0000000..b4c7d1e
Binary files /dev/null and b/static/img/shenyu/custom/custmo-condition-match-zh.png differ
diff --git a/static/img/shenyu/design/flow-condition.png b/static/img/shenyu/design/flow-condition.png
new file mode 100644
index 0000000..bb0e832
Binary files /dev/null and b/static/img/shenyu/design/flow-condition.png differ