• plugnType():是表示该插件的执行顺序与功能,BEFORE是最开始执行,Function 是中间,Last是最后执行。方便使用与扩展。
    • getOrder():是指同一种类型插件执行时候的先后顺序。
    • named():插件命名。
    • skip(): 该插件是否需要跳过,默认不跳过。
    • execute():插件执行的链条,会传递到下一个插件,责任链模式了解一下。
    • 第二种是继承
    1. package org.dromara.soul.extend.demo.custom;
    2. import org.dromara.soul.common.dto.zk.RuleZkDTO;
    3. import org.dromara.soul.common.dto.zk.SelectorZkDTO;
    4. import org.dromara.soul.common.enums.PluginTypeEnum;
    5. import org.dromara.soul.common.utils.GsonUtils;
    6. import org.dromara.soul.extend.demo.entity.Test;
    7. import org.dromara.soul.web.cache.ZookeeperCacheManager;
    8. import org.dromara.soul.web.plugin.AbstractSoulPlugin;
    9. import org.dromara.soul.web.plugin.SoulPluginChain;
    10. import org.slf4j.Logger;
    11. import org.slf4j.LoggerFactory;
    12. import org.springframework.web.server.ServerWebExchange;
    13. import reactor.core.publisher.Mono;
    14. /**
    15. * This is your custom plugin.
    16. * He is running in after before plugin, implement your own functionality.
    17. * extends AbstractSoulPlugin so you must user soul-admin And add related plug-in development.
    18. *
    19. * @author xiaoyu(Myth)
    20. */
    21. public class CustomPlugin extends AbstractSoulPlugin {
    22. /**
    23. * logger.
    24. */
    25. private static final Logger LOGGER = LoggerFactory.getLogger(CustomPlugin.class);
    26. public CustomPlugin(final ZookeeperCacheManager dataCacheManager) {
    27. }
    28. /**
    29. * return plugin type.
    30. * The PluginTypeEnum.BEFORE is first
    31. * The PluginTypeEnum.LAST is last.
    32. *
    33. * @return {@linkplain PluginTypeEnum}
    34. */
    35. @Override
    36. public PluginTypeEnum pluginType() {
    37. return PluginTypeEnum.FUNCTION;
    38. }
    39. /**
    40. * return plugin order .
    41. * The same plugin he executes in the same order.
    42. *
    43. * @return int
    44. */
    45. @Override
    46. public int getOrder() {
    47. return 0;
    48. }
    49. /**
    50. * acquire plugin name.
    51. * return you custom plugin name.
    52. * It must be the same name as the plug-in you added in the admin background.
    53. *
    54. * @return plugin name.
    55. */
    56. @Override
    57. public String named() {
    58. return "soul";
    59. }
    60. /**
    61. * plugin is execute.
    62. *
    63. * @param exchange the current server exchange
    64. * @return default false.
    65. */
    66. @Override
    67. public Boolean skip(final ServerWebExchange exchange) {
    68. return false;
    69. }
    70. @Override
    71. protected Mono<Void> doExecute(ServerWebExchange exchange, SoulPluginChain chain, SelectorZkDTO selector, RuleZkDTO rule) {
    72. LOGGER.debug(".......... function plugin start..............");
    73. /*
    74. * Processing after your selector matches the rule.
    75. * rule.getHandle() is you Customize the json string to be processed.
    76. * for this example.
    77. * Convert your custom json string pass to an entity class.
    78. */
    79. final String ruleHandle = rule.getHandle();
    80. final Test test = GsonUtils.getInstance().fromJson(ruleHandle, Test.class);
    81. /*
    82. * Then do your own business processing.
    83. * The last execution chain.execute(exchange).
    84. * Let it continue on the chain until the end.
    85. */
    86. System.out.println(test.toString());
    87. return chain.execute(exchange);
    88. }
    89. }