本文主要是介绍SpringCloud之链路追踪(Finchley版本),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
由于SpringCloud的微服务将原本单一项目的模块切分为各个独立的服务了。所以调试和遇到问题变得难一些。因此Spring Cloud就开发了新的组件zipkin
创建链路追踪服务项目
首先创建的链路追踪服务项目需要引入zipkin的几个jar,这里我们pom引入
<?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><parent><groupId>com.funtl</groupId><artifactId>hello-spring-cloud-dependencies</artifactId><version>1.0.0-SNAPSHOT</version><relativePath>../hello-springcloud-dependencies/pom.xml</relativePath></parent><artifactId>hello-spring-cloud-zipkin</artifactId><packaging>jar</packaging><name>hello-spring-cloud-zipkin</name><dependencies><!-- Spring Boot Begin --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-tomcat</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><!-- Spring Boot End --><!-- Spring Cloud Begin --><dependency><groupId>io.zipkin.java</groupId><artifactId>zipkin</artifactId><version>${zipkin.version}</version></dependency><dependency><groupId>io.zipkin.java</groupId><artifactId>zipkin-server</artifactId><version>${zipkin.version}</version></dependency><dependency><groupId>io.zipkin.java</groupId><artifactId>zipkin-autoconfigure-ui</artifactId><version>${zipkin.version}</version></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-server</artifactId></dependency><!-- Spring Cloud End --></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><mainClass>com.funtl.hello.spring.cloud.zipkin.ZipKinApplication</mainClass></configuration></plugin></plugins></build>
</project>
同时在application.yml中配置项目的服务端口和属性
spring:application:name: hello-spring-cloud-zipkinserver:port: 9411eureka:client:serviceUrl:defaultZone: http://localhost:8761/eureka/management:metrics:web:server:auto-time-requests: false
在启动类中加入注解@EnableZipkinServer
@SpringBootApplication
@EnableEurekaClient
@EnableZipkinServer
public class ZipKinApplication {public static void main(String[] args) {SpringApplication.run(ZipKinApplication.class, args);}
}
但此时还需要在链路追踪的各个项目中加入pom依赖,包括注册中心Eureka Server项目
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-zipkin</artifactId></dependency>
此时在浏览器中访问我们昨天的地址之后,在浏览器中访问
http://localhost:9411。切换顶部菜单栏,即可获得如下结果
这篇关于SpringCloud之链路追踪(Finchley版本)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!