Soul 框架介绍
Soul 是一个基于Java语言的异步的、高性能,响应式的API网关开源框架。该框架由京东的肖宇(猫大人)发起,和其他10多名成员共同开发完成。
Soul框架支持各种多种协议,内置丰富的插件,支持热插拔,支持动态化配置,网关性能约在1~2ms。
Soul 基本架构
用户的Http请求通过Nginx请求到Soul网关集群,配置的插件和协议通过链式调用逐一生效,管理后台的动态配置会同步到网关集群中。 (很多的问号还需要一探究竟:)
Soul 项目结构
以当前最新的2.2.1为例分析每个模块的基本功能。
- soul-admin:网关管理后台,用于插件、规则等动态配置;
- soul-bootstrap:网关启动模块;
- soul-client:客户端模块,支持不同的协议的客户端,如Dubbo协议,http协议;
- soul-common:公共模块,通用实体定义;
- soul-dist:打包;
- soul-examples:示例代码;
- soul-metrics:监控模块;
- soul-plugin:定义丰富的插件;
- soul-regiser-center:配置注册中心,如zk等;
- soul-spi:基于SPI机制,实现插件的热插拔;
- soul-spring-boot-starter:spring boot支持;
- soul-sync-data-center:数据同步模块;
- soul-web:web模块;
Soul 单机部署
运行 soul-admin
- 在 github fork一份,拉取到本地
- 在 Mysql 创建 soul 数据库
mysql> create database soul; Query OK, 1 row affected (0.01 sec)复制代码
- 修改 application.yml 中的数据库配置
- 执行启动类:SoulAdminBootstrap
- 访问 http://127.0.0.1:9095/,使用 admin/123456 登录
运行 soul-bootstrap
- 执行启动类 SoulBootstrapApplication
2021-01-15 08:33:51.281 INFO 22994 --- [ main] o.d.s.b.SoulBootstrapApplication : Starting SoulBootstrapApplication on xxx.local with PID 22994 (soul) 2021-01-15 08:33:51.281 INFO 22994 --- [ main] o.d.s.b.SoulBootstrapApplication : The following profiles are active: local 2021-01-15 08:33:52.634 INFO 22994 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode! 2021-01-15 08:33:52.638 INFO 22994 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Redis repositories in DEFAULT mode. 2021-01-15 08:33:52.692 INFO 22994 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 21ms. Found 0 Redis repository interfaces. 2021-01-15 08:33:53.609 INFO 22994 --- [ main] o.d.s.w.configuration.SoulConfiguration : load plugin:[global] [org.dromara.soul.plugin.global.GlobalPlugin] 2021-01-15 08:33:53.609 INFO 22994 --- [ main] o.d.s.w.configuration.SoulConfiguration : load plugin:[sign] [org.dromara.soul.plugin.sign.SignPlugin] 2021-01-15 08:33:53.609 INFO 22994 --- [ main] o.d.s.w.configuration.SoulConfiguration : load plugin:[waf] [org.dromara.soul.plugin.waf.WafPlugin] 2021-01-15 08:33:53.610 INFO 22994 --- [ main] o.d.s.w.configuration.SoulConfiguration : load plugin:[rate_limiter] [org.dromara.soul.plugin.ratelimiter.RateLimiterPlugin] 2021-01-15 08:33:53.610 INFO 22994 --- [ main] o.d.s.w.configuration.SoulConfiguration : load plugin:[hystrix] [org.dromara.soul.plugin.hystrix.HystrixPlugin] 2021-01-15 08:33:53.610 INFO 22994 --- [ main] o.d.s.w.configuration.SoulConfiguration : load plugin:[resilience4j] [org.dromara.soul.plugin.resilience4j.Resilience4JPlugin] 2021-01-15 08:33:53.610 INFO 22994 --- [ main] o.d.s.w.configuration.SoulConfiguration : load plugin:[divide] [org.dromara.soul.plugin.divide.DividePlugin] 2021-01-15 08:33:53.610 INFO 22994 --- [ main] o.d.s.w.configuration.SoulConfiguration : load plugin:[webClient] [org.dromara.soul.plugin.httpclient.WebClientPlugin] 2021-01-15 08:33:53.610 INFO 22994 --- [ main] o.d.s.w.configuration.SoulConfiguration : load plugin:[divide] [org.dromara.soul.plugin.divide.websocket.WebSocketPlugin] 2021-01-15 08:33:53.610 INFO 22994 --- [ main] o.d.s.w.configuration.SoulConfiguration : load plugin:[alibaba-dubbo-body-param] [org.dromara.soul.plugin.alibaba.dubbo.param.BodyParamPlugin] 2021-01-15 08:33:53.610 INFO 22994 --- [ main] o.d.s.w.configuration.SoulConfiguration : load plugin:[dubbo] [org.dromara.soul.plugin.alibaba.dubbo.AlibabaDubboPlugin] 2021-01-15 08:33:53.610 INFO 22994 --- [ main] o.d.s.w.configuration.SoulConfiguration : load plugin:[monitor] [org.dromara.soul.plugin.monitor.MonitorPlugin] 2021-01-15 08:33:53.610 INFO 22994 --- [ main] o.d.s.w.configuration.SoulConfiguration : load plugin:[response] [org.dromara.soul.plugin.httpclient.response.WebClientResponsePlugin] 2021-01-15 08:33:53.610 INFO 22994 --- [ main] o.d.s.w.configuration.SoulConfiguration : load plugin:[response] [org.dromara.soul.plugin.alibaba.dubbo.response.DubboResponsePlugin] 2021-01-15 08:33:53.874 INFO 22994 --- [ main] b.s.s.d.w.WebsocketSyncDataConfiguration : you use websocket sync soul data....... 2021-01-15 08:33:54.072 INFO 22994 --- [ main] o.d.s.p.s.d.w.WebsocketSyncDataService : websocket connection is successful..... 2021-01-15 08:33:54.217 INFO 22994 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 2 endpoint(s) beneath base path '/actuator' 2021-01-15 08:33:55.130 INFO 22994 --- [ main] o.s.b.web.embedded.netty.NettyWebServer : Netty started on port(s): 9195 2021-01-15 08:33:55.133 INFO 22994 --- [ main] o.d.s.b.SoulBootstrapApplication : Started SoulBootstrapApplication in 5.544 seconds (JVM running for 7.975)复制代码