三、实战 Gateway 模式效果
基于网关的开发,是一种责任链模式的实践,一关一责任,互不相扰,按需组合。
1、效果预览
定制过的本地网关
@Mapping("/api/v3/app/**")
@Component
public class ApiGateway3x extends UapiGateway {
@Override
protected void register() {
filter(new BreakerFilter()); //融断
before(new StartHandler()); //开始计时
before(new ParamsParseHandler()); //参数解析
before(new ParamsSignCheckHandler(new Md5Encoder())); //参数签名较验
before(new ParamsRebuildHandler(new AesDecoder())); //参数重构
after(new OutputBuildHandler(new AesEncoder())); //输出构建
after(new OutputSignHandler(new Md5Encoder())); //输出签名
after(new OutputHandler()); //输出
after(new EndBeforeLogHandler()); //日志
after(new EndHandler("v3.api.app")); //结束计时
//添加一批具体的接口处理Bean
addBeans(bw -> "api".equals(bw.tag()));
}
}
接口
@Component(tag = "api")
public class API_config_set extends ApiBase {
@Inject
ConfigService configService;
@NotEmpty({"tag", "key"})
@Mapping("config.set")
public void exec(String tag, String key, String value) throws Throwable {
configService.setConfig(tag, key, value);
}
}
2、具体参考:
https://gitee.com/noear/marsh/tree/main/_demo/marsh-api-demo2