Skip to main content
Version: 2.4.0

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.
/** * This is custom match strategy. */@Joinpublic 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.
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:

script
custom = org.apache.shenyu.examples.http.strategy.CustomMatchStrategy
  • Add enum in org.apache.shenyu.common.enums.MatchModeEnum class:

    /**     * 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}.

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: