Custom Load Balance
#
ExplanationBefore custom development, please customize and build the gateway environment first, please refer to: custom deployment.
This article describes how to customize the extension of
org.apache.shenyu.plugin.divide.balance.LoadBalance
.
#
Extension- Create a new class
${you class}
, implementsorg.apache.shenyu.plugin.divide.balance.LoadBalance
public class ${you class} implements LoadBalance { /** * select one from upstream list. * * @param upstreamList upstream list * @param ip ip * @return divide upstream */ @Override public DivideUpstream doSelect(final List<DivideUpstream> upstreamList, final String ip) { //coding and return }}
- In the project
resources
directory,Create a newMETA-INF/shenyu
directory, and the new file name is :org.apache.shenyu.plugin.divide.balance.LoadBalance
. add${you spi name}
=${you class path}
:
${you spi name} = ${you class path}
- In the
Admin
service ---> BasicConfig ---> Dictionary , Find the dictionary code asLOAD_BALANCE
, add a new piece of data, pay attention to the dictionary name:${you spi name}
.
- Or execute the following custom
SQL
statement:
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-08-30 19:29:10', '2021-08-30 20:15:23' );