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.
- Loading branch information
Showing
89 changed files
with
1,078 additions
and
1 deletion.
There are no files selected for viewing
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,144 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.alipay.sofa</groupId> | ||
<artifactId>dubbo-samples</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<name>dubbo-samples</name> | ||
<description>Demo project for Dubbo</description> | ||
<packaging>pom</packaging> | ||
|
||
<properties> | ||
<java.version>1.8</java.version> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
<dubbo.version>3.1.11</dubbo.version> | ||
<sofa.serverless.runtime.version>0.5.0</sofa.serverless.runtime.version> | ||
<sofa.ark.version>2.2.4-SNAPSHOT</sofa.ark.version> | ||
|
||
<spring.boot.version>2.7.16</spring.boot.version> | ||
<java.version>1.8</java.version> | ||
<disruptor.version>3.4.2</disruptor.version> | ||
<os.plugin.version>1.7.1</os.plugin.version> | ||
<protobuf.plugin.version>0.6.1</protobuf.plugin.version> | ||
<protobuf.version>3.18.3</protobuf.version> | ||
<protoc.version>3.18.3</protoc.version> | ||
<grpc.version>1.54.1</grpc.version> | ||
<maven.compiler.plugin.version>3.8.1</maven.compiler.plugin.version> | ||
</properties> | ||
|
||
<modules> | ||
<module>rpc/grpc/model</module> | ||
<module>rpc/grpc/base</module> | ||
<module>rpc/grpc/biz1</module> | ||
</modules> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.alipay.sofa.rpc.grpc.model</groupId> | ||
<artifactId>model</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-dependencies</artifactId> | ||
<version>${spring.boot.version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-bom</artifactId> | ||
<version>${dubbo.version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-dependencies-zookeeper</artifactId> | ||
<version>${dubbo.version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
<version>${spring.boot.version}</version> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-logging</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
|
||
<!-- 这里添加动态模块相关依赖 --> | ||
<dependency> | ||
<groupId>com.alipay.sofa.serverless</groupId> | ||
<artifactId>sofa-serverless-base-starter</artifactId> | ||
<version>${sofa.serverless.runtime.version}</version> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-core</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.alipay.sofa</groupId> | ||
<artifactId>web-ark-plugin</artifactId> | ||
<version>${sofa.ark.version}</version> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-core</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.lmax</groupId> | ||
<artifactId>disruptor</artifactId> | ||
<version>${disruptor.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<profiles> | ||
<profile> | ||
<id>default</id> | ||
<activation> | ||
<activeByDefault>true</activeByDefault> | ||
</activation> | ||
<repositories> | ||
<repository> | ||
<snapshots> | ||
<enabled>true</enabled> | ||
</snapshots> | ||
<id>ark-snapshot</id> | ||
<url>https://oss.sonatype.org/content/repositories/snapshots</url> | ||
</repository> | ||
</repositories> | ||
<pluginRepositories> | ||
<pluginRepository> | ||
<snapshots> | ||
<enabled>true</enabled> | ||
</snapshots> | ||
<id>ark-snapshot</id> | ||
<url>https://oss.sonatype.org/content/repositories/snapshots</url> | ||
</pluginRepository> | ||
</pluginRepositories> | ||
</profile> | ||
</profiles> | ||
|
||
</project> |
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,119 @@ | ||
# Dubbo 使用 triple 进行 RPC 调用 | ||
|
||
## 实验内容 | ||
### 实验应用 | ||
#### base | ||
base 为普通 dubbo 应用改造而成,改造内容只需在主 pom 里增加如下依赖 | ||
```xml | ||
<!-- 这里添加动态模块相关依赖 --> | ||
<dependency> | ||
<groupId>com.alipay.sofa.serverless</groupId> | ||
<artifactId>sofa-serverless-base-starter</artifactId> | ||
</dependency> | ||
<!-- end 动态模块相关依赖 --> | ||
``` | ||
如果是 web 应用,并且希望后面模块部署与基座使用同一个 tomcat host,则引入如下依赖。详细查看[这里](https://www.sofastack.tech/projects/sofa-boot/sofa-ark-multi-web-component-deploy/) | ||
```xml | ||
<!-- 这里添加 tomcat 单 host 模式部署多web应用的依赖, 非 web 应用可忽略 --> | ||
<dependency> | ||
<groupId>com.alipay.sofa</groupId> | ||
<artifactId>web-ark-plugin</artifactId> | ||
</dependency> | ||
<!-- end 单 host 部署的依赖 --> | ||
``` | ||
|
||
这里基座发布了 RPC 服务, DemoService | ||
|
||
#### biz1 | ||
这是动态安装到基座的模块应用,也是普通 dubbo 应用,只需修改打包插件方式即可变成可合并部署的 ark biz 模块 | ||
```xml | ||
<plugin> | ||
<groupId>com.alipay.sofa</groupId> | ||
<artifactId>sofa-ark-maven-plugin</artifactId> | ||
<version>2.2.3</version> | ||
<executions> | ||
<execution> | ||
<id>default-cli</id> | ||
<goals> | ||
<goal>repackage</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<skipArkExecutable>true</skipArkExecutable> | ||
<outputDirectory>./target</outputDirectory> | ||
<bizName>biz1</bizName> | ||
<webContextPath>biz1</webContextPath> | ||
<declaredMode>true</declaredMode> | ||
<!-- 打包、安装和发布 ark biz--> | ||
<!-- 静态合并部署需要配置--> | ||
<!-- <attach>true</attach>--> | ||
</configuration> | ||
</plugin> | ||
``` | ||
另外模块还额外将基座里有的依赖,设置为了 provided,这样可以尽可能的服用基座的类、rpc client 等。 | ||
|
||
这里模块在 RPCController 里引用了基座里定义的 RPC 服务。 | ||
|
||
#### model | ||
改应用只是作为通信包,里面只放了 RPC 通信需要的通信接口类。 | ||
|
||
另外,为了让基座和模块日志打印到不同的目录下,基座和模块还额外引入了 log4j2 adapter,如果不关心基座和模块日志是否打印在一起还是分开打印,那么这个依赖可以不加。 | ||
```xml | ||
<dependency> | ||
<groupId>com.alipay.sofa.serverless</groupId> | ||
<artifactId>sofa-serverless-adapter-log4j2</artifactId> | ||
<version>${sofa.serverless.runtime.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
``` | ||
|
||
### 实验步骤 | ||
1. 进入目录 `sofa-serverless/samples/dubbo-samples/rpc/grpc/model/`,执行 `mvn instll`,将通信包安装到本地仓库 | ||
1. 执行 `mvn clean package -DskipTests` | ||
2. 启动基座应用 base,确保基座启动成功 | ||
3. 启动 zookeeper | ||
```shell | ||
docker run -p 2181:2181 -it --name zookeeper --restart always -d zookeeper:3.9.0 | ||
``` | ||
4. 执行 curl 命令安装 biz1 | ||
```shell | ||
curl --location --request POST 'localhost:1238/installBiz' \ | ||
--header 'Content-Type: application/json' \ | ||
--data '{ | ||
"bizName": "biz1-triple", | ||
"bizVersion": "0.0.1-SNAPSHOT", | ||
// local path should start with file://, alse support remote url which can be downloaded | ||
"bizUrl": "file:///path/to/sofa-ark-spring-guides/samples/web/tomcat/biz1/target/biz1-triple-0.0.1-SNAPSHOT-ark-biz.jar" | ||
}' | ||
``` | ||
|
||
如果要验证热部署的能力,也可以通过卸载命令卸载模块,然后重新安装模块,发起多次模块安装 | ||
```shell | ||
curl --location --request POST 'localhost:1238/uninstallBiz' \ | ||
--header 'Content-Type: application/json' \ | ||
--data '{ | ||
"bizName": "biz1", | ||
"bizVersion": "0.0.1-SNAPSHOT" | ||
}' | ||
``` | ||
|
||
5. 查看模块安装是否成功 | ||
```shell | ||
curl --location --request POST 'localhost:1238/queryAllBiz' | ||
``` | ||
可以查看到所有安装好的模块列表 | ||
|
||
6. 验证模块的 RPC 调用 | ||
|
||
1. 直接调用基座 rest 接口,验证 injvm 的 rpc 调用 | ||
|
||
```shell | ||
curl localhost:8080 | ||
``` | ||
返回 `Receive result ======> Hello base` | ||
2. 调用模块的 rest 接口,验证 rpc 调用 | ||
```shell | ||
curl localhost:8080/biz1 | ||
``` | ||
返回 `Receive result ======> Hello biz1` |
Oops, something went wrong.