方法一:用版本号来区分
比如,开发环境上跑的服务版本是1.0.0,那么为了在本地打断点调试某个服务,可以在本地启动,将version设置为2.0.0
服务提供者
@DubboService(version = "2.0.0")
public class DemoServiceImpl implements DemoService {
@Override
public String sayHello(String name) {
return "Hello, " + name;
}
}
服务消费者
@DubboReference(version = "2.0.0")
private DemoService demoService;
方法二:直接指定提供者
@DubboReference(url = "dubbo://192.168.71.1:20880")
private DemoService demoService;
或者,启动的时候,通过 -D 参数指定
java -jar Dcom.cjs.dubbo.demo.api.DemoService=dubbo://192.168.71.1:20880 xxx.jar
或者,通过文件映射指定
如果服务比较多,用 -Ddubbo.resolve.file 指定映射文件路径
java -Ddubbo.resolve.file=xxx.properties xxx.jar
然后在映射文件 xxx.properties 中加入配置,其中 key 为服务名,value 为服务提供者 URL
com.cjs.dubbo.demo.api.DemoService=dubbo://192.168.71.1:20880
com.cjs.dubbo.demo.api.xxxService=dubbo://192.168.71.2:20880
pom.xml
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>dubbo-demo</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>dubbo-demo-interface</module>
<module>dubbo-demo-provider</module>
<module>dubbo-demo-consumer</module>
</modules>
<properties>
<!--<spring-boot.version>3.2.0</spring-boot.version>-->
<!--SpringBoot 2.x和3.x版本都行-->
<spring-boot.version>2.7.11</spring-boot.version>
<dubbo.version>3.2.10</dubbo.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencyManagement>
<dependencies>
<!-- Spring Boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- dubbo -->
<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-curator5</artifactId>
<version>${dubbo.version}</version>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
代码地址:
https://gitee.com/chengjiansheng/cjs-dubbo-democ
参考:
https://cn.dubbo.apache.org/zh-cn/overview/tasks/observability/tracing/
标签:Dubbo,cn,dubbo,demo,version,本地,apache,org,调试 From: https://www.cnblogs.com/cjsblog/p/17922056.html