soul2.3 初体验

2021-04-10  本文已影响0人  weir_will

前言

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

一、2.3 更新内容?

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

soul-admin(dashboard)

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

soul网关插件

插件新增

插件优化

Soul Client

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

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

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

Soul 数据同步

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

官方文档中的 环境搭建 · 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 的内存数据库。

启动 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 注解;有如下内容:

启动 SoulTestHttpApplicationmain方法启动项目。

image-20210410162318823

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

image-20210410162410887

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

上一篇下一篇

猜你喜欢

热点阅读