微服务学习笔记十一 Spring Cloud Zipkin服务跟踪

本文涉及的产品
任务调度 XXL-JOB 版免费试用,400 元额度,开发版规格
服务治理 MSE Sentinel/OpenSergo,Agent数量 不受限
云原生网关 MSE Higress,422元/月
简介: 微服务学习笔记十一 Spring Cloud Zipkin服务跟踪

Spring Cloud Zipkin

Zipkim是一个可以采集并且跟踪分布式系统中请求数据的组件,让开发者可以更加

直观的监控到请求在各个微服务所耗费的时间等,Zipkin:Zipkin Server、Zipkin Client,

**创建Zipkin server**

创建一个maven工程,pom.xml


```yaml

<dependencies>

   <dependency>

       <groupId>io.zipkin.java</groupId>

       <artifactId>zipkin-server</artifactId>

       <version>2.9.4</version>

       <exclusions>

           <exclusion>

               <groupId>org.apache.logging.log4j</groupId>

               <artifactId>log4j-slf4j-impl</artifactId>

           </exclusion>

       </exclusions>

   </dependency>

   <dependency>

       <groupId>io.zipkin.java</groupId>

       <artifactId>zipkin-autoconfigure-ui</artifactId>

       <version>2.9.4</version>

   </dependency>

</dependencies>

```



创建配置文件 application.yml


```yaml

server:

 port: 9090

```


创建启动类


```java

package com.shuang;


import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import zipkin.server.internal.EnableZipkinServer;


@SpringBootApplication

@EnableZipkinServer

public class ZipKinApplication {

   public static void main(String[] args) {

       SpringApplication.run(ZipKinApplication.class,args);

   }

}

```


注解说明:

@EnableZipkinServer:声明启动Zipkin Server

**创建 Zipkin Client**

创建maven工程,pom.xml


```yaml

<dependencies>

   <dependency>

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

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

       <version>2.0.2.RELEASE</version>

   </dependency>

</dependencies>

```


创建配置文件,application.yml


```yaml

server:

 port: 8090

spring:

 application:

   name: zipkinclient

 sleuth:

   web:

     client:

       enabled: true

   sampler:

     probability: 1.0

 zipkin:

   base-url: http://localhost:9090/

eureka:

 client:

   service-url:

     defaultZone: http://localhost:8761/eureka/

```

   


属性说明:

spring.sleuth.web.client.enabled:设置开启请求跟踪

spring.sleuth.sampler.probability:设置采样比例,默认值是1.0。

spring.zipkin.base-url:Zipkin Server地址。

创建启动类


```java

package com.shuang;


import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;


@SpringBootApplication

public class ZipkinClientApplication {

   public static void main(String[] args) {

       SpringApplication.run(ZipkinClientApplication.class,args);

   }

}

```


Handler


```java

package com.shuang.controller;


import org.springframework.beans.factory.annotation.Value;

import org.springframework.web.bind.annotation.GetMapping;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;


@RestController

@RequestMapping("/zipkin")

public class ZipkinHandler {

 

   @Value("${server.port}")

   public String port;

 

   @GetMapping("/index")

   public String index(){

       return this.port;

   }

}

```


依次启动:


![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/2020071806370183.png)

![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/20200718063715941.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ0OTY5NjQz,size_16,color_FFFFFF,t_70)

![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/20200718063728788.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ0OTY5NjQz,size_16,color_FFFFFF,t_70)

目录
相关文章
|
2月前
|
JSON Java API
利用Spring Cloud Gateway Predicate优化微服务路由策略
Spring Cloud Gateway 的路由配置中,`predicates`​(断言)用于定义哪些请求应该匹配特定的路由规则。 断言是Gateway在进行路由时,根据具体的请求信息如请求路径、请求方法、请求参数等进行匹配的规则。当一个请求的信息符合断言设置的条件时,Gateway就会将该请求路由到对应的服务上。
182 69
利用Spring Cloud Gateway Predicate优化微服务路由策略
|
7天前
|
网络协议 Java Shell
java spring 项目若依框架启动失败,启动不了服务提示端口8080占用escription: Web server failed to start. Port 8080 was already in use. Action: Identify and stop the process that’s listening on port 8080 or configure this application to listen on another port-优雅草卓伊凡解决方案
java spring 项目若依框架启动失败,启动不了服务提示端口8080占用escription: Web server failed to start. Port 8080 was already in use. Action: Identify and stop the process that’s listening on port 8080 or configure this application to listen on another port-优雅草卓伊凡解决方案
31 7
|
1月前
|
搜索推荐 NoSQL Java
微服务架构设计与实践:用Spring Cloud实现抖音的推荐系统
本文基于Spring Cloud实现了一个简化的抖音推荐系统,涵盖用户行为管理、视频资源管理、个性化推荐和实时数据处理四大核心功能。通过Eureka进行服务注册与发现,使用Feign实现服务间调用,并借助Redis缓存用户画像,Kafka传递用户行为数据。文章详细介绍了项目搭建、服务创建及配置过程,包括用户服务、视频服务、推荐服务和数据处理服务的开发步骤。最后,通过业务测试验证了系统的功能,并引入Resilience4j实现服务降级,确保系统在部分服务故障时仍能正常运行。此示例旨在帮助读者理解微服务架构的设计思路与实践方法。
96 16
|
8天前
|
传感器 监控 安全
智慧工地云平台的技术架构解析:微服务+Spring Cloud如何支撑海量数据?
慧工地解决方案依托AI、物联网和BIM技术,实现对施工现场的全方位、立体化管理。通过规范施工、减少安全隐患、节省人力、降低运营成本,提升工地管理的安全性、效率和精益度。该方案适用于大型建筑、基础设施、房地产开发等场景,具备微服务架构、大数据与AI分析、物联网设备联网、多端协同等创新点,推动建筑行业向数字化、智能化转型。未来将融合5G、区块链等技术,助力智慧城市建设。
|
1月前
|
监控 JavaScript 数据可视化
建筑施工一体化信息管理平台源码,支持微服务架构,采用Java、Spring Cloud、Vue等技术开发。
智慧工地云平台是专为建筑施工领域打造的一体化信息管理平台,利用大数据、云计算、物联网等技术,实现施工区域各系统数据汇总与可视化管理。平台涵盖人员、设备、物料、环境等关键因素的实时监控与数据分析,提供远程指挥、决策支持等功能,提升工作效率,促进产业信息化发展。系统由PC端、APP移动端及项目、监管、数据屏三大平台组成,支持微服务架构,采用Java、Spring Cloud、Vue等技术开发。
|
2月前
|
Java Nacos Sentinel
Spring Cloud Alibaba:一站式微服务解决方案
Spring Cloud Alibaba(简称SCA) 是一个基于 Spring Cloud 构建的开源微服务框架,专为解决分布式系统中的服务治理、配置管理、服务发现、消息总线等问题而设计。
444 13
Spring Cloud Alibaba:一站式微服务解决方案
|
2月前
|
Java 关系型数据库 Nacos
微服务SpringCloud链路追踪之Micrometer+Zipkin
SpringCloud+Openfeign远程调用,并用Mircrometer+Zipkin进行链路追踪
315 20
|
1月前
|
Java 关系型数据库 数据库
微服务SpringCloud分布式事务之Seata
SpringCloud+SpringCloudAlibaba的Seata实现分布式事务,步骤超详细,附带视频教程
73 1
|
3月前
|
前端开发 Java 开发者
Spring生态学习路径与源码深度探讨
【11月更文挑战第13天】Spring框架作为Java企业级开发中的核心框架,其丰富的生态系统和强大的功能吸引了无数开发者的关注。学习Spring生态不仅仅是掌握Spring Framework本身,更需要深入理解其周边组件和工具,以及源码的底层实现逻辑。本文将从Spring生态的学习路径入手,详细探讨如何系统地学习Spring,并深入解析各个重点的底层实现逻辑。
96 9
|
Java API Spring
Spring学习路径
Spring作为一个优秀的开源企业级框架有着一下特点 开源框架 简化企业级应用开发的流程 Spring是一个JavaSE/EE的一站式框架 优点在于 方便解耦 AOP的编程支持 声明式事务的支持 可以引入jUnit4,方便程序测试 对优秀开源框架的支持,方便集成 降低JavaEE API的使用难度.
2526 0