Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #400 from sofastack/feat/springcloud
Browse files Browse the repository at this point in the history
add springcloud gateway samples
  • Loading branch information
lvjing2 authored Dec 13, 2023
2 parents 1a8311c + ab1b346 commit 89e4326
Show file tree
Hide file tree
Showing 29 changed files with 1,049 additions and 58 deletions.

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/content/zh-cn/home/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ url: "/home/"
<!-- For 搜索引擎检索,修改无用 --><p style="visibility: hidden; margin: 0; height: 0px;">实现 SDK 无感升级:借助 SOFAServerless 将应用依赖尽可能下沉到基座 (类似业务 Sidecar),可以实现 SDK 的无打扰升级。</p>
<!-- For 搜索引擎检索,修改无用 --><p style="visibility: hidden; margin: 0; height: 0px;">极致裁剪长尾应用资源成本:通过 SOFAServerless 将多个应用合并部署在一起,可以实现大量的长尾应用服务器裁撤。</p>
<!-- For 搜索引擎检索,修改无用 --><p style="visibility: hidden; margin: 0; height: 0px;">大幅提升应用研发协作效率:通过 SOFAServerless 将应用快速划分成多个模块 (代码包),且多个模块间可以同时迭代互不影响,进而大幅提升研发效率。</p>
<!-- For 搜索引擎检索,修改无用 --><p style="visibility: hidden; margin: 0; height: 0px;">简化中台业务资产沉淀:支持低成本将业务公共代码下沉到基座并在基座上长出各种轻薄的功能模块,从而让组织分工更加合理、需求交付更加高效。</p>
<!-- For 搜索引擎检索,修改无用 --><p style="visibility: hidden; margin: 0; height: 0px;">简化平台/中台搭建和业务资产沉淀:支持低成本将业务公共代码下沉到基座并在基座上长出各种轻薄的功能模块,从而让组织分工更加合理、需求交付更加高效。</p>
<!-- For 搜索引擎检索,修改无用 --><p style="visibility: hidden; margin: 0; height: 0px;">降低微服务的演进成本:支持业务架构低成本地在单体应用、多模块、独立微服务应用之间来回切换,从而轻松让应用架构与业务发展保持及时同步。</p>


Expand Down Expand Up @@ -442,8 +442,8 @@ url: "/home/"
<path d="M20.9690612,24.3277983 L14.8011945,27.5739983 C14.5829279,27.7423317 14.3133945,27.8431317 14.0147279,27.834065 C13.7161279,27.8431317 13.4465279,27.7423317 13.2282612,27.5739983 L7.06039455,24.3277983 C5.48719455,23.4997983 6.72919455,21.1399983 8.30239455,21.9679983 C9.87559455,22.7959983 8.63359455,25.1557317 7.06039455,24.3277983 L0.727081213,20.994465 C-0.846105453,20.166465 0.395881213,17.806665 1.96906788,18.634665 L8.30239455,21.9679983 L14.0147279,24.974465 L19.7270612,21.9679983 C21.3002612,21.1399983 22.5422612,23.4997983 20.9690612,24.3277983 L19.7270612,21.9679983 L20.9690612,24.3277983 Z M7.06039455,24.3277983 L8.30239455,21.9679983 L7.06039455,24.3277983 Z M20.9690612,18.3277983 L14.8011945,21.5739983 C14.5829279,21.7423317 14.3133945,21.8431317 14.0147279,21.834065 C13.7161279,21.8431317 13.4465279,21.7423317 13.2282612,21.5739983 L7.06039455,18.3277983 C5.48719455,17.4997983 6.72919455,15.1399983 8.30239455,15.9679983 C9.87559455,16.7959983 8.63359455,19.1557983 7.06039455,18.3277983 L0.727081213,14.994465 C-0.846105453,14.166465 0.395881213,11.806665 1.96906788,12.634665 L8.30239455,15.9679983 L14.0147279,18.974465 L19.7270612,15.9679983 C21.3002612,15.1399983 22.5422612,17.4997983 20.9690612,18.3277983 L19.7270612,15.9679983 L20.9690612,18.3277983 Z M7.06039455,18.3277983 L8.30239455,15.9679983 L7.06039455,18.3277983 Z M19.7270612,15.9679983 L26.0603945,12.634665 C27.6335945,11.806665 28.8755945,14.166465 27.3023945,14.994465 L20.9690612,18.3277983 C19.3958612,19.1557983 18.1538612,16.7959983 19.7270612,15.9679983 Z M19.7270612,21.9679983 L26.0603945,18.634665 C27.6335945,17.806665 28.8755945,20.166465 27.3023945,20.994465 L20.9690612,24.3277983 C19.3958612,25.1557317 18.1538612,22.7959983 19.7270612,21.9679983 Z M14.6531945,0.162805 L27.6083945,7.229265 C27.7207945,7.29059833 27.8131279,7.38293167 27.8744612,7.49533167 C28.0507945,7.81853167 27.9316612,8.22353167 27.6083945,8.39979833 L14.6531945,15.466265 C14.2552612,15.6833317 13.7742612,15.6833317 13.3762612,15.466265 L0.421054547,8.39979833 C0.0978278799,8.22353167 -0.0212787868,7.81853167 0.15502788,7.49533167 C0.21632788,7.38293167 0.308681213,7.29059833 0.421054547,7.229265 L13.3762612,0.162805 C13.7742612,-0.0542683333 14.2552612,-0.0542683333 14.6531945,0.162805 Z M4.91692788,7.81453167 L14.0147279,12.7769983 L23.1125279,7.81453167 L14.0147279,2.85211167 L4.91692788,7.81453167 Z" id="形状"></path>
</g>
</g>
<text id="简化中台业务资产沉淀" opacity="0.95" font-family="PingFangSC-Medium, 'Microsoft Yahei'" font-size="20" font-weight="400" line-spacing="32" fill="#FFFFFF">
<tspan x="90.5" y="145">简化中台业务资产沉淀</tspan>
<text id="简化平台/中台搭建和业务资产沉淀" opacity="0.95" font-family="PingFangSC-Medium, 'Microsoft Yahei'" font-size="20" font-weight="400" line-spacing="32" fill="#FFFFFF">
<tspan x="90.5" y="145">简化平台/中台搭建和业务资产沉淀</tspan>
</text>
<text id="支持低成本将业务公共代码下沉到基座并在基" opacity="0.5" font-family="PingFangSC-Regular, PingFang SC, Microsoft Yahei" font-size="14" font-weight="normal" line-spacing="24" fill="#FFFFFF">
<tspan x="65" y="179">支持低成本将业务公共代码下沉到基座并</tspan>
Expand Down
36 changes: 20 additions & 16 deletions samples/README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
## SOFAServerless 模块中间件使用样例清单

| 框架 | 中间件 | 说明 | 代码样例 |
|-------------|------------------------|---------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------|
| sprintboot | spring context manager | 跨模块bean调用 | [samples/springboot-samples/service](https://github.com/sofastack/sofa-serverless/tree/master/samples/springboot-samples/service) |
| springboot | tomcat | 单host模式 | [samples/springboot-samples/web/tomcat/](https://github.com/sofastack-guides/springboot-samples/tree/master/samples/web/tomcat) |
| springboot | log4j2 | 基座与模块独立日志目录 | [samples/springboot-samples/logging/log4j2](https://github.com/sofastack/sofa-serverless/tree/master/samples/springboot-samples/logging/log4j2) |
| springboot | kafka | 模块独立使用 kafka | [samples/springboot-samples/msg/kafka](https://github.com/sofastack/sofa-serverless/tree/master/samples/springboot-samples/msg/kafka/) |
| springboot | rocketmq | 模块与基座可以共存生产和消费消息 | [samples/springboot-samples/msg/rocketmq](https://github.com/sofastack/sofa-serverless/tree/master/samples/springboot-samples/msg/rocketmq/) |
| springboot | mybatis | 模块使用独立数据源 | [samples/springboot-samples/db/mybatis](https://github.com/sofastack/sofa-serverless/tree/master/samples/springboot-samples/db/mybatis) |
| springboot | mongo | 1. 模块独立使用数据源, 2. 模块复用基座数据源 | [samples/springboot-samples/db/mongo](https://github.com/sofastack/sofa-serverless/tree/master/samples/springboot-samples/db/mongo) |
| springboot | apollo 1.x | 1. 模块独立使用不同 appId 的配置, 2. 模块与基座共用 appId 的配置 | [samples/springboot-samples/config/apollo](https://github.com/sofastack/sofa-serverless/tree/master/samples/springboot-samples/config/apollo) |
| springboot | slimming | 模块瘦身 | [samples/springboot-samples/slimming/log4j2](https://github.com/sofastack/sofa-serverless/tree/master/samples/springboot-samples/slimming/log4j2) |
| springboot | redis | 模块使用 redis | [samples/springboot-samples/cache/redis](https://github.com/sofastack/sofa-serverless/tree/master/samples/springboot-samples/cache/redis) |
| springboot | ehcache | 模块使用 ehcache | [samples/springboot-samples/cache/ehcache](https://github.com/sofastack/sofa-serverless/tree/master/samples/springboot-samples/cache/ehcache) |
| dubbo | dubbo + grpc | 模块使用 grpc | [samples/dubbo-samples/rpc/grpc](https://github.com/sofastack/sofa-serverless/tree/master/samples/dubbo-samples/rpc/grpc) |
| sofaboot | sofarpc/tomcat | 基座调用模块、中台模式 | [samples/sofaboot-samples/dynamic-stock](https://github.com/sofastack/sofa-serverless/tree/master/samples/sofaboot-samples/dynamic-stock) |
| springboot3 | springboot3 | springboot3 | [samples/sofaboot3-samples](https://github.com/sofastack/sofa-serverless/tree/master/samples/sofaboot3-samples) | |
| 框架 | 中间件 | 说明 | 代码样例 |
|-------------|------------------------|---------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------|
| springboot | spring context manager | 跨模块bean调用 | [samples/springboot-samples/service](https://github.com/sofastack/sofa-serverless/tree/master/samples/springboot-samples/service) |
| springboot | tomcat | 单host模式 | [samples/springboot-samples/web/tomcat/](https://github.com/sofastack-guides/springboot-samples/tree/master/samples/web/tomcat) |
| springboot | webflux | 单 host 模式 | [samples/springboot-samples/web/webflux/](https://github.com/sofastack-guides/springboot-samples/tree/master/samples/web/webflux) |
| springboot | log4j2 | 基座与模块独立日志目录 | [samples/springboot-samples/logging/log4j2](https://github.com/sofastack/sofa-serverless/tree/master/samples/springboot-samples/logging/log4j2) |
| springboot | logback | 基座与模块独立日志目录 | [samples/springboot-samples/logging/logback](https://github.com/sofastack/sofa-serverless/tree/master/samples/springboot-samples/logging/logback) |
| springboot | kafka | 模块独立使用 kafka | [samples/springboot-samples/msg/kafka](https://github.com/sofastack/sofa-serverless/tree/master/samples/springboot-samples/msg/kafka/) |
| springboot | rocketmq | 模块与基座可以共存生产和消费消息 | [samples/springboot-samples/msg/rocketmq](https://github.com/sofastack/sofa-serverless/tree/master/samples/springboot-samples/msg/rocketmq/) |
| springboot | mybatis | 模块使用独立数据源 | [samples/springboot-samples/db/mybatis](https://github.com/sofastack/sofa-serverless/tree/master/samples/springboot-samples/db/mybatis) |
| springboot | mongo | 1. 模块独立使用数据源, 2. 模块复用基座数据源 | [samples/springboot-samples/db/mongo](https://github.com/sofastack/sofa-serverless/tree/master/samples/springboot-samples/db/mongo) |
| springboot | apollo 1.x | 1. 模块独立使用不同 appId 的配置, 2. 模块与基座共用 appId 的配置 | [samples/springboot-samples/config/apollo](https://github.com/sofastack/sofa-serverless/tree/master/samples/springboot-samples/config/apollo) |
| springboot | slimming | 模块瘦身 | [samples/springboot-samples/slimming/log4j2](https://github.com/sofastack/sofa-serverless/tree/master/samples/springboot-samples/slimming/log4j2) |
| springboot | redis | 模块使用 redis | [samples/springboot-samples/cache/redis](https://github.com/sofastack/sofa-serverless/tree/master/samples/springboot-samples/cache/redis) |
| springboot | ehcache | 模块使用 ehcache | [samples/springboot-samples/cache/ehcache](https://github.com/sofastack/sofa-serverless/tree/master/samples/springboot-samples/cache/ehcache) |
| springboot | nacos | 模块使用 nacos | [samples/springboot-samples/config/nacos](https://github.com/sofastack/sofa-serverless/tree/master/samples/springboot-samples/config/nacos) |
| springcloud | gateway | 模块与基座同时使用 gateway 配置路由规则 | [samples/springboot-samples/springcloud/gateway](https://github.com/sofastack/sofa-serverless/tree/master/samples/springboot-samples/springcloud/gateway) |
| dubbo | dubbo + grpc | 模块使用 grpc | [samples/dubbo-samples/rpc/grpc](https://github.com/sofastack/sofa-serverless/tree/master/samples/dubbo-samples/rpc/grpc) |
| sofaboot | sofarpc/tomcat | 基座调用模块、中台模式 | [samples/sofaboot-samples/dynamic-stock](https://github.com/sofastack/sofa-serverless/tree/master/samples/sofaboot-samples/dynamic-stock) |
| springboot3 | springboot3 | springboot3 | [samples/sofaboot3-samples](https://github.com/sofastack/sofa-serverless/tree/master/samples/sofaboot3-samples) | |
### 注意请在编译器单独导入对应 samples 工程,例如 sofa-serverless/samples/springboot-samples 工程,否则会出现 BizRuntimeContext Not found 的报错。
![biz runtime context not found](bizruntimecontext_not_found.png)
原因:samples 工程与 sofa-serverless-runtime 在一个工程目录里,会优先使用本地的 sofa-serverless-runtime,而不是 maven 依赖的 sofa-serverless-runtime,导致找不到 BizRuntimeContext 类。
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.alipay.sofa.web.biz1.rest;
package com.alipay.sofa.springcloud.gateway.biz1.rest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.alipay.sofa.web.biz2.rest;
package com.alipay.sofa.springcloud.gateway.biz2.rest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.alipay.sofa.web.biz1.rest;
package com.alipay.sofa.springcloud.gateway.biz1.rest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.alipay.sofa.web.biz2.rest;
package com.alipay.sofa.springcloud.gateway.biz2.rest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
7 changes: 6 additions & 1 deletion samples/springboot-samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
<properties>
<spring.boot.version>2.7.16</spring.boot.version>
<java.version>1.8</java.version>

<sofa.ark.version>2.2.6-SNAPSHOT</sofa.ark.version>
<sofa.serverless.runtime.version>0.5.5-SNAPSHOT</sofa.serverless.runtime.version>
<disruptor.version>3.4.2</disruptor.version>
Expand Down Expand Up @@ -59,6 +58,7 @@
<module>db/mongo/biz2</module>
<module>config/apollo</module>
<module>config/nacos</module>
<module>springcloud/gateway</module>
</modules>

<dependencyManagement>
Expand Down Expand Up @@ -137,6 +137,11 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>netty-ark-plugin</artifactId>
<version>${sofa.ark.version}</version>
</dependency>
<dependency>
<groupId>com.lmax</groupId>
<artifactId>disruptor</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.alipay.sofa.web.biz1.rest;
package com.alipay.sofa.springcloud.gateway.biz1.rest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
87 changes: 87 additions & 0 deletions samples/springboot-samples/springcloud/gateway/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# 实验内容
## 实验应用
### base
base 为普通 springboot cloud改造成的基座,改造内容为在 pom 里增加如下依赖
```xml
<dependency>
<groupId>com.alipay.sofa.serverless</groupId>
<artifactId>sofa-serverless-base-starter</artifactId>
</dependency>

<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>netty-ark-plugin</artifactId>
</dependency>
```

### biz
biz 包含两个模块,分别为 biz1 和 biz2, 都是普通 springboot cloud,修改打包插件方式为 sofaArk biz 模块打包方式,打包为 ark biz jar 包,打包插件配置如下:

```xml
<!-- 修改打包插件为 sofa-ark biz 打包插件,打包成 ark biz jar -->
<plugin>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-ark-maven-plugin</artifactId>
<version>${sofa.ark.version}</version>
<executions>
<execution>
<id>default-cli</id>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<skipArkExecutable>true</skipArkExecutable>
<outputDirectory>./target</outputDirectory>
<bizName>${bizName}</bizName>
<!-- 单host下需更换 web context path -->
<webContextPath>${bizName}</webContextPath>
<declaredMode>true</declaredMode>
<packExcludesConfig>rules.txt</packExcludesConfig>
</configuration>
</plugin>
```
注意这里将不同 biz 的web context path 修改成不同的值,以此才能成功在一个 netty host 里安装多个 web 应用。

## 实验步骤

### 基座启动与模块部署
#### 执行 mvn clean package -DskipTests
可在各 bundle 的 target 目录里查看到打包生成的 ark-biz jar 包

#### 启动基座应用 base,确保基座启动成功
#### 执行 curl 命令安装 biz1 和 biz2
到 gateway 目录
```shell
cd samples/springboot-samples/springcloud/gateway
```
通过 arkctl 部署模块 1 和模块 2
```shell
arkctl deploy biz1/target/biz1-cloud-gateway-0.0.1-SNAPSHOT-ark-biz.jar
arkctl deploy biz2/target/biz2-cloud-gateway-0.0.1-SNAPSHOT-ark-biz.jar
```

#### WebSocket 测试
1. 启动 3个不同端口的 webSocket 服务端
```shell
npm install -g wscat
wscat --listen 9000 # 基座 websocket 端口
wscat --listen 9001 # biz1 websocket 端口
wscat --listen 9002 # biz2 websocket 端口
```
2. 启动 webSocket 客户端链接测试
```shell
wscat --connect ws://localhost:8080/echo
```
输入任意字符, 只有属于基座的 webSocket 服务终端能 echo 出相同字符

```shell
wscat --connect ws://localhost:8080/biz1/echo
```
输入任意字符,只有属于 biz1 9001 端口的 webSocket 服务终端能 echo 出相同字符

```shell
wscat --connect ws://localhost:8080/biz2/echo
```
输入任意字符,只有属于 biz2 9002 端口的 webSocket 服务终端能 echo 出相同字符
Loading

0 comments on commit 89e4326

Please sign in to comment.