Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions dubbo32-samples/rpc/dubbo32/dubbo3base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@
<groupId>com.alipay.sofa.koupleless</groupId>
<artifactId>koupleless-base-starter</artifactId>
<version>${koupleless.runtime.version}</version>
<exclusions>
<exclusion>
<groupId>com.alipay.sofa.koupleless</groupId>
<artifactId>koupleless-adapter-log4j2</artifactId>
</exclusion>
<exclusion>
<groupId>com.alipay.sofa.koupleless</groupId>
<artifactId>koupleless-adapter-logback</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.alipay.sofa</groupId>
Expand Down Expand Up @@ -94,6 +104,13 @@
<artifactId>disruptor</artifactId>
<version>${disruptor.version}</version>
</dependency>

<dependency>
<groupId>com.alipay.sofa.koupleless</groupId>
<artifactId>koupleless-base-build-plugin</artifactId>
<version>${koupleless.build.plugin.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alipay.sofa.rpc.dubbo3.base;

import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.model.FrameworkModel;
import org.apache.dubbo.rpc.model.ModuleModel;
import org.apache.dubbo.rpc.model.ScopeModelInitializer;

/**
* @author lianglipeng.llp@alibaba-inc.com
* @version $Id: ClassloaderScopeModelInitializer.java, v 0.1 2024年05月27日 14:50 立蓬 Exp $
*/
public class ClassloaderScopeModelInitializer implements ScopeModelInitializer {
@Override
public void initializeFrameworkModel(FrameworkModel frameworkModel) {

}

@Override
public void initializeApplicationModel(ApplicationModel applicationModel) {

}

@Override
public void initializeModuleModel(ModuleModel moduleModel) {
moduleModel.addClassLoader(Thread.currentThread().getContextClassLoader());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.rpc.Constants;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -41,14 +40,14 @@ public class BaseController {
* 通过远程rpc调用模块triplebiz的CommonService服务
* check = false是因为启动时还没安装模块
*/
@DubboReference(group = "triplebiz", scope = Constants.SCOPE_LOCAL, check = false)
@DubboReference(group = "triplebiz", scope = Constants.SCOPE_LOCAL, check = false, filter = "baseFilter")
private CommonService commonServiceLocal;

/**
* 通过远程rpc调用模块triplebiz的CommonService服务
* check = false是因为启动时还没安装模块
*/
@DubboReference(group = "triplebiz", scope = Constants.SCOPE_REMOTE, check = false)
@DubboReference(group = "triplebiz", scope = Constants.SCOPE_REMOTE, check = false, filter = "baseFilter")
private CommonService commonServiceRemote;

@RequestMapping(value = "/triplebiz/injvm", method = RequestMethod.GET)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alipay.sofa.rpc.dubbo3.base.filter;

import org.apache.dubbo.rpc.Filter;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Result;
import org.apache.dubbo.rpc.RpcException;

/**
* @author lianglipeng.llp@alibaba-inc.com
* @version $Id: BaseFilter.java, v 0.1 2024年05月27日 12:05 立蓬 Exp $
*/
public class BaseFilter implements Filter {
@Override
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
System.out.println("BaseFilter.invoke");
return invoker.invoke(invocation);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
baseFilter=com.alipay.sofa.rpc.dubbo3.base.filter.BaseFilter
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
classloaderScopeModelInit=com.alipay.sofa.rpc.dubbo3.base.ClassloaderScopeModelInitializer
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
dubbo:
application:
logger: slf4j
name: dubbo32base
registry:
address: zookeeper://${zookeeper.address:127.0.0.1}:2181
protocol:
name: tri
port: 50051

server:
port: 8080

spring:
application:
name: dubbo32base
logging:
file:
path: ./samples/dubbo-samples/rpc/dubbo32/logs/
level:
root: info
com.alipay.sofa.rpc.dubbo3: debug
config: classpath:log4j2-spring.xml

# 1. 获取 bizName 的方式与 spring 不同,dubbo 使用的是 dubbo.application.name, 而不是 spring.application.name
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ server:
port: 8080

spring:
profiles:
active:
dev
application:
name: dubbo32base
logging:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alipay.sofa.rpc.dubbo3.grpcbiz.filter;

import org.apache.dubbo.rpc.Filter;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Result;
import org.apache.dubbo.rpc.RpcException;

/**
* @author lianglipeng.llp@alibaba-inc.com
* @version $Id: GRpcFilter.java, v 0.1 2024年05月27日 12:09 立蓬 Exp $
*/
public class GRpcFilter implements Filter {
@Override
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
System.out.println("GRpcFilter.invoke");
return invoker.invoke(invocation);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* @author syd
* @version GrpcBizGreeter.java, v 0.1 2023年11月06日 19:41 syd
*/
@DubboService(group = "grpcbiz")
@DubboService(group = "grpcbiz", filter = { "grpcFilter", "baseFilter" })
public class GrpcBizGreeter extends DubboGreeterTriple.GreeterImplBase {
private static final Logger LOGGER = LoggerFactory.getLogger(GrpcBizGreeter.class);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
grpcFilter=com.alipay.sofa.rpc.dubbo3.grpcbiz.filter.GRpcFilter
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alipay.sofa.rpc.dubbo3.triplebiz.filter;

import org.apache.dubbo.rpc.Filter;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Result;
import org.apache.dubbo.rpc.RpcException;

/**
* @author lianglipeng.llp@alibaba-inc.com
* @version $Id: BaseFilter.java, v 0.1 2024年05月29日 10:28 立蓬 Exp $
*/
public class BaseFilter implements Filter {
@Override
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
System.out.println("BaseFilter.invoke in triplebiz");
return invoker.invoke(invocation);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alipay.sofa.rpc.dubbo3.triplebiz.filter;

import org.apache.dubbo.rpc.Filter;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Result;
import org.apache.dubbo.rpc.RpcException;

/**
* @author lianglipeng.llp@alibaba-inc.com
* @version $Id: TripleFilter.java, v 0.1 2024年05月27日 12:11 立蓬 Exp $
*/
public class TripleFilter implements Filter {
@Override
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
System.out.println("TripleFilter.invoke");
return invoker.invoke(invocation);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @author syd
* @version FastJson2DemoService.java, v 0.1 2023年11月08日 12:52 syd
*/
@DubboService(group = "fastjson2")
@DubboService(group = "fastjson2", filter = "tripleFilter")
public class FastJson2DemoService implements DemoService {
@Override
public DemoResponse sayHello(DemoRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* @author syd
* @version TripleBizCommonService.java, v 0.1 2023年11月05日 16:02 syd
*/
@DubboService(group = "triplebiz")
@DubboService(group = "triplebiz", filter = { "tripleFilter", "baseFilter" })
public class TripleBizCommonService implements CommonService {
@Override
public CommonResponse sayHello(CommonRequest request) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tripleFilter=com.alipay.sofa.rpc.dubbo3.triplebiz.filter.TripleFilter
baseFilter=com.alipay.sofa.rpc.dubbo3.triplebiz.filter.BaseFilter
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
spring.application.name=dynamic-stock-biz1
spring.application.name=dynamic-stock-biz1
app.location=aaa
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
spring.application.name=dynamic-stock-biz1
app.location=bbb
9 changes: 5 additions & 4 deletions springboot-samples/config/apollo/README-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ System.setProperty("env", "DEV");
![init.png](imgs/init.png)

#### 实验步骤
1. cd 进入 config 目录,执行如下命令启动 apollo 服务端
1. cd 进入 config 目录,执行如下命令启动 docker 和 apollo 服务端
```shell
open -a Docker
docker-compose up
```
2. 登录 apollo 管理后台 `localhost:8089`,创建 app id 为 `biz1` 的项目和 key=data.name 的配置,创建 app id 为 `biz2` 的项目和 key=data.name 的配置,具体查看 https://www.apolloconfig.com/#/zh/deployment/quick-start
2. 登录 apollo 管理后台 `localhost:8070`,创建 app id 为 `biz1` 的项目和 key=data.name 的配置,创建 app id 为 `biz2` 的项目和 key=data.name 的配置,具体查看 https://www.apolloconfig.com/#/zh/deployment/quick-start

![apps.png](imgs/apps.png)

Expand All @@ -50,8 +51,8 @@ docker-compose up
3. 执行 `mvn clean package -DskipTests`,然后启动基座
4. 进入 apollo 目录,执行 `arkctl deploy biz1/target/biz1-apollo-0.0.1-SNAPSHOT-ark-biz.jar`, 安装 biz1 模块
5. 进入 apollo 目录,执行 `arkctl deploy biz2/target/biz2-apollo-0.0.1-SNAPSHOT-ark-biz.jar`, 安装 biz2 模块
6. 执行 `curl http://localhost:8081/biz1/getValue` 获取到 biz1 的配置值,修改 biz1 的 data.name,再次执行 `curl http://localhost:8081/biz1/getValue` 能获取到新的 biz1 的配置值
7. 执行 `curl http://localhost:8081/biz2/getValue` 获取到 biz2 的配置值,修改 biz2 的 data.name,再次执行 `curl http://localhost:8081/biz2/getValue` 能获取到新的 biz2 的配置值,也不会影响 biz1 或基座的配置值
6. 执行 `curl http://localhost:8080/biz1/getValue` 获取到 biz1 的配置值,修改 biz1 的 data.name,再次执行 `curl http://localhost:8081/biz1/getValue` 能获取到新的 biz1 的配置值
7. 执行 `curl http://localhost:8080/biz2/getValue` 获取到 biz2 的配置值,修改 biz2 的 data.name,再次执行 `curl http://localhost:8081/biz2/getValue` 能获取到新的 biz2 的配置值,也不会影响 biz1 或基座的配置值

### 不同模块使用相同 app id,独立配置默认就已经支持
模块统一使用[自动排包能力](https://koupleless.gitee.io/docs/tutorials/module-development/module-slimming/#%E4%B8%80%E9%94%AE%E8%87%AA%E5%8A%A8%E7%98%A6%E8%BA%AB),在 rules.txt 文件里确保有这个配置 `excludeGroupIds=com.ctrip.framework.apollo*`,将 apollo client 委托给基座加载即可达到效果。
Expand Down
Loading