Dubbo本地调试方法
方法一:用版本号来区分
比如,开发环境上跑的服务版本是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/
欢迎各位转载,但必须在文章页面中给出作者和原文链接!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?