soul2.3 初体验

前言

刚刚Soul 网关发布里程碑式的 2.3.0 版本;最为体验和尝鲜的态度,试着体验的新的版本;同时也是因为之前的转载文章[转载]芋道 Soul 极简入门(国产微服务网关)实在是有点久了;一些方式发生了改变,就记录下过程。

一、2.3 更新内容?

通过 2.3 releases可以了解;做了如下的更新;这里简单的中文介绍:

soul-admin(dashboard)

admin是整个网关的控制面板,掌管所有的流量,规则的匹配。

  • 整合shior框架,完成了用户按钮级别的权限控制。

  • 模板化插件,让用户无需感知前端页面,只专注于数据的配置。

  • admin整个后端的国际化,支持中英文切换。

  • 新增支持H2来存储数据。

  • admin界面的美观优化(表格,按钮)。

  • 新增单元测试,覆盖率达到百分之七十。

soul网关插件

插件新增

  • 新增GRPC插件,全面支持GRPC协议。

  • 新增 Tars插件,支持腾讯 tars RPC协议。

  • 新增Sofa 插件,支持 sofa RPC协议。

  • 新增 Sentinel 插件,整合 sentinel 框架的熔断限流功能。

  • 新增 Resilience4j 插件,整合 Resilience4j框架的熔断限流功能。

  • 新增 Rediect 插件,支持用户的重定向。

  • 新增 Context-path插件,支持用户自定义 context-path

插件优化

  • Divide 插件 : 节点探活方式的优化,流量预热方式的优化。

  • Ratelimiter插件 :新增并发,漏桶等不同的限流算法,供用户选择。

  • Sgin 插件 : 修复必须设置 url的bug,新增是否验证 标记,可以用来做开放平台的URI认证。

  • Dubbo插件 : 新增 form表单,URI参数请求, 新增注册中心直连,参数校验等功能。

Soul Client

soul-client只是提供一种快速接入网关的客户端,不是必须的。如果用户不使用,可以在soul-admin自行配置规则即可。

  • spring-mvc客户端的优化,支持springspring-boot所有版本。

  • spring-cloud客户端的优化,支持springspring-boot所有版本。

  • dubbo客户端的优化,支持springspring-boot所有版本。

  • 新增 soul-grpc-client 支持 grpc-java用户接入。

  • 新增 soul-tars-client 支持 tars-java用户接入。

  • 新增 soul-sofa-client 支持 sofa-java用户接入。

在之前的版本中,只支持 http 方式接入 而这次新增注册中心方式接入。

  • 新增 zookeeper 作为注册中心的方式接入soul网关。

  • 新增 Nacos 作为注册中心的方式接入soul网关。

  • 新增 Consul 作为注册中心的方式接入soul网关。

  • 新增 Etcd 作为注册中心的方式接入soul网关。

使用方式请参考: https://dromara.org/projects/soul/register-center-access/

Soul 数据同步

  • 修复Nacos 配置中心同步未设置 NameSpace 的Bug。

  • 优化 Websocket 同步方式。

  • 解决 soul-admin集群部署时候, Http长轮询方式同步数据Bug。

二、动手运行--环境搭建

官方文档中的 环境搭建 · dromara(Open source organization) 本身详细的说明,启动搭建的方式:

  • Docker
  • 远程下载
  • 本地搭建

本着学习的目的;这里推荐使用使用本地搭建的方式(笔者也是通过本地搭建的方式搭建的);其余两种方式适合快速搭建;大家可以试试。

1. Soul Admin 安装

<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="" cid="n154" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--font-monospace); font-size: 0.85rem; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248) !important; position: relative !important; padding: 0.3rem 0px !important; width: inherit; border: 1px solid rgb(244, 244, 244); -webkit-font-smoothing: initial; line-height: 1.43rem; border-radius: 2px; overflow-wrap: normal; margin: 0.8rem 0px !important; color: rgb(52, 73, 94); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> > git clone https://github.com/dromara/soul.git

cd soul</pre>

注意:启动 SoulAdminBootstrap

  • 如果使用h2来存储,设置变量 --spring.profiles.active = h2

  • 如果使用mysql来存储,修改 application.yaml 中的 mysql 配置。

这里我们使用 h2 的内存数据库。

启动 SoulAdminBootstrap类;看到如下内容启动成功:

image-20210410160943950

访问 http://localhost:9095 用户名密码为: admin/123456

2. Soul Bootstrap 安装

<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="" cid="n169" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--font-monospace); font-size: 0.85rem; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248) !important; position: relative !important; padding: 0.3rem 0px !important; width: inherit; border: 1px solid rgb(244, 244, 244); -webkit-font-smoothing: initial; line-height: 1.43rem; border-radius: 2px; overflow-wrap: normal; margin: 0.8rem 0px !important; color: rgb(52, 73, 94); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> > git clone https://github.com/dromara/soul.git

cd soul</pre>

启动 SoulBootstrapApplication类;看到 websocket成功连接网关管理台的内容:

image-20210410161025317

接入 Spring Boot 应用

写简单测试案例的时候;这次我们使用 示例代码 代码运行。

<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="xml" cid="n186" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--font-monospace); font-size: 0.85rem; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248) !important; position: relative !important; padding: 0.3rem 0px !important; width: inherit; border: 1px solid rgb(244, 244, 244); -webkit-font-smoothing: initial; line-height: 1.43rem; border-radius: 2px; overflow-wrap: normal; margin: 0.8rem 0px !important; color: rgb(52, 73, 94); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> <properties>
<soul.version>2.3.0-RELEASE</soul.version>
</properties>


<dependency>
<groupId>org.dromara</groupId>
<artifactId>soul-spring-boot-starter-plugin-divide</artifactId>
<version>${last.version}</version>
</dependency>

<dependency>
<groupId>org.dromara</groupId>
<artifactId>soul-spring-boot-starter-plugin-httpclient</artifactId>
<version>${last.version}</version>
</dependency></pre>

application.yaml关于soul的配置如下:

<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="yaml" cid="n191" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--font-monospace); font-size: 0.85rem; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248) !important; position: relative !important; padding: 0.3rem 0px !important; width: inherit; border: 1px solid rgb(244, 244, 244); -webkit-font-smoothing: initial; line-height: 1.43rem; border-radius: 2px; overflow-wrap: normal; margin: 0.8rem 0px !important; color: rgb(52, 73, 94); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> soul:
client:
registerType: http #zookeeper #etcd #nacos #consul
serverLists: http://localhost:9095 #localhost:2181 #http://localhost:2379 #localhost:8848 # Soul Admin 地址目前也支持注册中心
props:
contextPath: /http # 设置在 Soul 网关的路由前缀,例如说 /order、/product 等等。

后续,网关会根据该 context-path 来进行路由

appName: http #应用名。未配置情况下,默认使用 spring.application.name 配置项
port: 8189 #应用名端口;和配置server.port保持一致;作为路由端口
nacosNameSpace: SoulRegisterCenter</pre>

OrderController内容:

<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="java" cid="n209" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--font-monospace); font-size: 0.85rem; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248) !important; position: relative !important; padding: 0.3rem 0px !important; width: inherit; border: 1px solid rgb(244, 244, 244); -webkit-font-smoothing: initial; line-height: 1.43rem; border-radius: 2px; overflow-wrap: normal; margin: 0.8rem 0px !important; color: rgb(52, 73, 94); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> @RestController
@RequestMapping("/order")
@SoulSpringMvcClient(path = "/order")
public class OrderController {
//...
@PostMapping("/save")
@SoulSpringMvcClient(path = "/save" , desc = "Save order")
public OrderDTO save(@RequestBody final OrderDTO orderDTO) {
orderDTO.setName("hello world save order");
return orderDTO;
}
//...
}</pre>

@SoulSpringMvcClient 注解;有如下内容:

  • path:映射的 HTTP 接口的请求路径。

  • desc:接口的描述,便于知道其用途。

  • enable:是否开启,默认为 true 开启。

启动 SoulTestHttpApplicationmain方法启动项目。

image-20210410162318823

访问 http://localhost:9195/http/order/save ;值得说明:9195是soul网关地址;http是配置的 contextpath

image-20210410162410887

通过简单案例理解如下数据同步原理:

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,847评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,208评论 1 292
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,587评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,942评论 0 205
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,332评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,587评论 1 218
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,853评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,568评论 0 198
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,273评论 1 242
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,542评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,033评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,373评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,031评论 3 236
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,073评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,830评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,628评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,537评论 2 269