Custom Load Balance
Explanation
-
Before 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
resourcesdirectory,Create a newMETA-INF/shenyudirectory, 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
Adminservice ---> 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
SQLstatement:
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'
);