Skywalking(6.5.0)支持的Rpc框架有以下几种:
接下来为大家提供一些简单使用Dubbo服务调用的项目代码演示, 大家可以参考下面简单版
或者详细请参照Demo中的脚手架示例scaffold-dubbo-demo
pom文件:
<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.0modelVersion>
<parent>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-parentartifactId>
<version>2.1.10.RELEASEversion>
<relativePath/>
parent>
<groupId>com.sf.saasgroupId>
<artifactId>skywalking_dubbo_providerartifactId>
<version>0.0.1-SNAPSHOTversion>
<name>skywalking_dubbo_providername>
<description>Demo project for Spring Bootdescription>
<properties>
<java.version>1.8java.version>
properties>
<dependencies>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-webartifactId>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-testartifactId>
<scope>testscope>
dependency>
<dependency>
<groupId>com.alibaba.spring.bootgroupId>
<artifactId>dubbo-spring-boot-starterartifactId>
<version>2.0.0version>
dependency>
dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-maven-pluginartifactId>
plugin>
plugins>
build>
project>
application.properties
spring.application.name=skywalking_dubbo_provider spring.dubbo.server=true
spring.dubbo.registry=N/A
server.port=8086
为了简化环境搭建,采用了本地直接调用的方式,所以将注册中心写成N/A表示不注册到注册中 心。
IHelloService接口:.
public interface IHelloService {
String hello();
}
IHelloServiceImpl实现类
import com.alibaba.dubbo.config.annotation.Service; import com.itcast.api.IHelloService;
import org.springframework.stereotype.Component;
@Service(interfaceClass = IHelloService.class)
@Component
public class HelloServiceImpl implements IHelloService {
@Override
public String hello() {
return "hello skywalking";
}
}
SkywalkingDubboProviderApplication启动类
import com.alibaba.dubbo.spring.boot.annotation.EnableDubboConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
//添加dubbo生效注解
@EnableDubboConfiguration
public class SkywalkingDubboProviderApplication {
public static void main(String[] args) {
SpringApplication.run(SkywalkingDubboProviderApplication.class, args);
}
}
需要添加@EnableDubboConfiguration注解
pom文件:
<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.0modelVersion>
<parent>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-parentartifactId>
<version>2.1.10.RELEASEversion>
<relativePath/>
parent>
<groupId>com.sf.saasgroupId>
<artifactId>skywalking_dubbo_consumerartifactId>
<version>0.0.1-SNAPSHOTversion>
<name>skywalking_dubbo_consumername>
<description>Demo project for Spring Bootdescription>
<properties>
<java.version>1.8java.version>
properties>
<dependencies>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-webartifactId>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-testartifactId>
<scope>testscope>
dependency>
<dependency>
<groupId>com.alibaba.spring.bootgroupId>
<artifactId>dubbo-spring-boot-starterartifactId>
<version>2.0.0version>
dependency>
dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-maven-pluginartifactId>
plugin>
plugins>
build>
project>
application.properties
spring.application.name=skywalking_dubbo_consumer
server.port=8085
IHelloService接口
public interface IHelloService {
String hello();
}
TestController
import com.alibaba.dubbo.config.annotation.Reference;
import com.itcast.api.IHelloService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class TestController {
@Reference(url = "dubbo://127.0.0.1:20880")
private IHelloService helloService;
@GetMapping("/hello")
public String hello(){
return helloService.hello();
}
}
采用直连而非从注册中心获取服务地址的方式,在@Reference注解中声明
url = “dubbo://127.0.0.1:20880”
SkywalkingDubboConsumerApplication
import com.alibaba.dubbo.spring.boot.annotation.EnableDubboConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
//添加dubbo生效注解
@EnableDubboConfiguration
public class SkywalkingDubboConsumerApplication {
public static void main(String[] args) {
SpringApplication.run(SkywalkingDubboConsumerApplication.class, args);
}
}
需要添加@EnableDubboConfiguration注解
1、将上述两个项目使用package打包后上传至/usr/local/skywalking目录下。
2、首先我们复制两份agent,防止使用的冲突。
cd /usr/local/skywalking/apache-skywalking-apm-bin/ cp -r agent agent_dubbo_provider
cp -r agent agent_dubbo_consumer
vi agent_dubbo_provider/config/agent.config
修改agent_dubbo_provider配置中的应用名为:
# The service name in UI
agent.service_name=${SW_AGENT_NAME:dubbo_provider}
接着修改agent_dubbo_consumer
vi agent_dubbo_consumer/config/agent.config
修改应用名
# The service name in UI
agent.service_name=${SW_AGENT_NAME:dubbo_consumer}
3、先启动provider,等待启动成功
#切换到目录下
cd /usr/local/skywalking
#启动provider
java -javaagent:/usr/local/skywalking/apache-skywalking-apm- bin/agent_dubbo_provider/skywalking-agent.jar -jar skywalking_dubbo_provider.jar &
出现如图所示内容,应用就已经启动成功了
4、启动consumer,等待启动成功。
#启动consumer
java -javaagent:/usr/local/skywalking/apache-skywalking-apm- bin/agent_dubbo_consumer/skywalking-agent.jar -jar skywalking_dubbo_consumer.jar &
5、调用接口,接口地址为:http://虚拟机IP地址:8085/hello
那么dubbo的调用就成功了。
7、打开skywalking查看dubbo调用的监控情况。
目前 dubbo_provider和 dubbo_consumer的服务已经出现,同时出现了两个接口分别是:
该图中已经表示出了一个调用的链路关系:
User(浏览器) ----> dubber_consumer ----> dubbo_provider
并且在服务的上方标识出了每个服务代表的内容,dubbo_consumer是SpringMvc的服务,而 dubbo_provider是Dubbo的服务。
追踪
追踪图中显示本次调用耗时49ms,其中dubbo接口耗时29ms,那么另外的20ms其实是SpringMVC接 口的开销,这样就能很好的评估出每个环节的耗时时间。