前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >SpringCloud 2.x之Spring Cloud 中整合Zipkin进行服务跟踪zipkin-client

SpringCloud 2.x之Spring Cloud 中整合Zipkin进行服务跟踪zipkin-client

作者头像
BUG弄潮儿
发布2022-06-30 16:46:54
9070
发布2022-06-30 16:46:54
举报
文章被收录于专栏:JAVA乐园

上一篇简介了ZipkinServer的搭建,但是从Spring boot2.x版本后,Zipkin官网已经不再推荐自己搭建定制Zipkin,而是直接提供了编译好的jar包。详情可以查看官网:

https://zipkin.io/pages/quickstart.html

有了Zipkin Server还不能对微服务的调用链路进行人祸监控,Zipkin Server可以被认为是一个数据处理和展示中心,那它的数据哪里来呢?需要Zipkin Client作为代理连接到Zipkin Server源源不断的上送过来。今天讲解一下如何在微服务中引入Zipkin Client,然后结合Zipkin Server监控各微服务间的调用链路。整体调用链路图如下:

涉及的项目:

注册中心:sc-eureka-server

Zipkinserver:sc-zipkin-server

微服务:sc-zipkin-client-web、sc-zipkin-client-service

1、 新建项目sc-zipkin-client-service,对应的pom.xml文件如下

代码语言:javascript
复制
<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.0http://maven.apache.org/xsd/maven-4.0.0.xsd">

   <modelVersion>4.0.0</modelVersion>



   <groupId>spring-cloud</groupId>

   <artifactId>sc-zipkin-client-service</artifactId>

   <version>0.0.1-SNAPSHOT</version>

   <packaging>jar</packaging>



   <name>sc-zipkin-client-service</name>

   <url>http://maven.apache.org</url>

   <parent>

      <groupId>org.springframework.boot</groupId>

      <artifactId>spring-boot-starter-parent</artifactId>

      <version>2.0.4.RELEASE</version>

   </parent>



   <dependencyManagement>

      <dependencies>

        <dependency>

           <groupId>org.springframework.cloud</groupId>

           <artifactId>spring-cloud-dependencies</artifactId>

           <version>Finchley.RELEASE</version>

           <type>pom</type>

           <scope>import</scope>

        </dependency>



      </dependencies>

   </dependencyManagement>



   <properties>

      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

      <maven.compiler.source>1.8</maven.compiler.source>

      <maven.compiler.target>1.8</maven.compiler.target>

   </properties>



   <dependencies>

      <dependency>

        <groupId>org.springframework.cloud</groupId>

         <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>

      </dependency>



      <dependency>

        <groupId>org.springframework.cloud</groupId>

        <artifactId>spring-cloud-starter-zipkin</artifactId>

      </dependency>

      <dependency>

        <groupId>org.springframework.boot</groupId>

        <artifactId>spring-boot-starter-web</artifactId>

      </dependency>

   </dependencies>

</project> 

备注:主要引入了spring-cloud-starter-zipkin,说明这是一个zipkin client。

2、 新建配置文件application.yml

代码语言:javascript
复制
eureka:

  client:

    serviceUrl:

      defaultZone:http://localhost:5001/eureka/  

server:

  port: 9201

spring:

  application:

    name: sc-zipkin-client-service

  zipkin:

base-url:http://localhost:9000

`

3、 sc-zipkin-client-service(普通的微服务)项目其他项目文件如下图

4、 新建项目sc-zipkin-client-web,对应的pom.xml文件如下

代码语言:javascript
复制
<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.0http://maven.apache.org/xsd/maven-4.0.0.xsd">

   <modelVersion>4.0.0</modelVersion>



   <groupId>spring-cloud</groupId>

   <artifactId>sc-zipkin-client-web</artifactId>

   <version>0.0.1-SNAPSHOT</version>

   <packaging>jar</packaging>



   <name>sc-zipkin-client-web</name>

   <url>http://maven.apache.org</url>



   <parent>

      <groupId>org.springframework.boot</groupId>

      <artifactId>spring-boot-starter-parent</artifactId>

      <version>2.0.4.RELEASE</version>

   </parent>



   <dependencyManagement>

      <dependencies>

        <dependency>

           <groupId>org.springframework.cloud</groupId>

           <artifactId>spring-cloud-dependencies</artifactId>

           <version>Finchley.RELEASE</version>

           <type>pom</type>

           <scope>import</scope>

        </dependency>



      </dependencies>

   </dependencyManagement>



   <properties>

      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

      <maven.compiler.source>1.8</maven.compiler.source>

      <maven.compiler.target>1.8</maven.compiler.target>

   </properties>



   <dependencies>

      <dependency>

        <groupId>org.springframework.cloud</groupId>

         <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>

      </dependency>



      <dependency>

        <groupId>org.springframework.cloud</groupId>

        <artifactId>spring-cloud-starter-zipkin</artifactId>

      </dependency>



      <dependency>

        <groupId>org.springframework.boot</groupId>

        <artifactId>spring-boot-starter-web</artifactId>

      </dependency>



      <dependency>

        <groupId>org.springframework.cloud</groupId>

        <artifactId>spring-cloud-starter-openfeign</artifactId>

      </dependency>

   </dependencies>

</project>

`备注:同样引入了spring-cloud-starter-zipkin,说明是一个zipkin client

5、 新建配置文件application.yml

代码语言:javascript
复制
eureka:

  client:

    serviceUrl:

      defaultZone:http://localhost:5001/eureka/



server:

  port: 9202

spring:

  application:

    name: sc-zipkin-client-web

  zipkin:

    base-url: http://localhost:9000

`

6、 sc-zipkin-client-web(普通的微服务)项目其他项目文件如下图

7、 验证

项目启动顺序:

sc-eureka-server

sc-zipkin-server

sc-zipkin-client-service

sc-zipkin-client-web

访问注册中心:http://127.0.0.1:5001/

服务都已经注册成功

访问Zinkin Server:http://localhost:9000/zipkin/

目前zipkin server没有记录任何的微服务调用链路数据。

分别访问接口:

http://127.0.0.1:9202/user/listUser

http://127.0.0.1:9202/user/getUser/1

再次查看Zipkin Server(如果没有出现可以多访问几次接口,Zipkin需要更多的监控数据)

源码:

代码语言:javascript
复制
https://gitee.com/hjj520/spring-cloud-2.x/tree/master/sc-zipkin-client-web
https://gitee.com/hjj520/spring-cloud-2.x/tree/master/sc-zipkin-client-service
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2018-11-18,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 BUG弄潮儿 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
微服务引擎 TSE
微服务引擎(Tencent Cloud Service Engine)提供开箱即用的云上全场景微服务解决方案。支持开源增强的云原生注册配置中心(Zookeeper、Nacos 和 Apollo),北极星网格(腾讯自研并开源的 PolarisMesh)、云原生 API 网关(Kong)以及微服务应用托管的弹性微服务平台。微服务引擎完全兼容开源版本的使用方式,在功能、可用性和可运维性等多个方面进行增强。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档