This repository has been archived by the owner on Feb 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #400 from sofastack/feat/springcloud
add springcloud gateway samples
- Loading branch information
Showing
29 changed files
with
1,049 additions
and
58 deletions.
There are no files selected for viewing
67 changes: 35 additions & 32 deletions
67
docs/content/zh-cn/docs/tutorials/module-development/runtime-compatibility-list.md
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 类。 |
2 changes: 1 addition & 1 deletion
2
.../sofa/web/biz1/rest/SampleController.java → ...d/gateway/biz1/rest/SampleController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../sofa/web/biz2/rest/SampleController.java → ...d/gateway/biz2/rest/SampleController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../sofa/web/biz1/rest/SampleController.java → ...d/gateway/biz1/rest/SampleController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../sofa/web/biz2/rest/SampleController.java → ...d/gateway/biz2/rest/SampleController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../sofa/web/biz1/rest/SampleController.java → ...d/gateway/biz1/rest/SampleController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 出相同字符 |
Oops, something went wrong.