Greenwich.SR2版本的Spring Cloud Zipkin实例
调用链跟踪是微服务架构中的基础能力,Spring Cloud Zipkin+Sleuth为我们提供了该能力。首先我们先建立Zipkin服务端,它需要集成Eureka,用于发现服务提供方和消费方,进行数据的采集存储、数据分析与UI展示;然后我们在服务提供方和消费方中植入Zipkin+Sleuth作为客户端,进行追踪数据的生成与上报。
zikpin服务端(三板斧):
1、pom里引入第三方(Twitter的)zipkin的jar包:
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId>
<artifactId>zipkin</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties> <dependencies>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-server</artifactId>
<version>2.11.8</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.11.8</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies> <dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Greenwich.SR2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build> </project>
注意标黄部分,日志jar包冲突会让zipkin无法启动的。
2、application:
#本机端口
server.port=8899 #服务名
spring.application.name=zipkin #注册中心地址
eureka.client.service-url.defaultZone=http://localhost:8888/eureka/ #关闭自动收集web请求
management.metrics.web.server.auto-time-requests=false
3、主类通过@EnableZipkinServer启动zipkin:
package hello; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import zipkin2.server.internal.EnableZipkinServer; @EnableZipkinServer
@EnableEurekaClient
@SpringBootApplication
public class ZipkinApplication { public static void main(String[] args) {
SpringApplication.run(ZipkinApplication.class, args);
} }
zipkin客户端只需干两件事:1、在pom里引入spring-cloud-starter-zipkin即可:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
2、在application中加入zipkin服务端地址和采用率(方便测试观察):
#zipkin服务端地址
spring.zipkin.base-url=http://127.0.0.1:8899 #调用链信息采样率
spring.sleuth.sampler.probability=1.0
  我们在api-gateway、a-bootiful-client、a-beautiful-client和a-feign-client中都引入zipkin客户端,现在打开localhost:8899点击Find Traces即可搜到它们最近1个小时的调用链:  
     
随便点一个看看:

再点开一个具体的调用链,可以看到里面的调用详细信息:

点导航菜单中的“Dependencies”可以看到调用关系图:

Greenwich.SR2版本的Spring Cloud Zipkin实例的更多相关文章
- Greenwich.SR2版本的Spring Cloud Zuul实例
		网关作为对外服务,在微服务架构中是一个很重要的组件,主要体现在动态路由和接入鉴权这两个功能上.现在我们通过Spring Cloud Zuul来实现对之前a-feign-client(参见Greenwi ... 
- Greenwich.SR2版本的Spring Cloud Feign实例
		前面我们了解了Spring Cloud Ribbon和Hystrix,在使用上它们基本上会成队出现,那么是不是可以把它们组合起来使用?而且我们发现,在服务消费方a-beautiful-client里通 ... 
- Greenwich.SR2版本的Spring Cloud Hystrix实例
		之前我们在eureka(参见Greenwich.SR2版本的Spring Cloud Eureka实例)中,服务消费方a-beautiful-client调用服务提供方a-bootiful-clien ... 
- Greenwich.SR2版本的Spring Cloud Ribbon实例
		上次我们了解了eureka(参见Greenwich.SR2版本的Spring Cloud Eureka实例),里面的服务消费方(服务实例a-beautiful-client)我们其实已经用到了ribb ... 
- Greenwich.SR2版本的Spring Cloud Eureka实例
		作为微服务架构中最为核心和基础的服务治理,注册中心提供了微服务实例的自动化注册与发现.而作为一个服务注册中心,eureka的作用与传统的zk.etcd的作用是一样的,同样也支持高可用(集群).不同之处 ... 
- Greenwich.SR2版本的Spring Cloud Config+BUS实例
		Spring Cloud Config统一的配置中心同注册中心Eureka一样,也分服务端和客户端.服务端用来保存配置信息,客户端用来读取.它的优势是基于Git仓库,支持多环境.多分支配置.动态刷新. ... 
- 0.9.0.RELEASE版本的spring cloud alibaba nacos+gateway网关实例
		gateway就是用来替换zuul的,功能都差不多,我们看下它怎么来跟nacos一起玩.老套路,三板斧: 1.pom: <?xml version="1.0" encodin ... 
- 0.9.0.RELEASE版本的spring cloud alibaba nacos+feign实例
		这里的feign依然是原来的feign,只不过将注册中心由eureka换成了nacos.服务提供方参见0.9.0.RELEASE版本的spring cloud alibaba nacos实例,消费方跟 ... 
- 0.9.0.RELEASE版本的spring cloud alibaba nacos实例
		简而言之,nacos与eureka的不同之处有三:后台老板.部署方式.功能.nacos是阿里的,eureka是奈飞的:nacos有自己的安装包,需要独立部署,eureka仅作为一个服务组件,引入jar ... 
随机推荐
- pandas里面过滤列出现ValueError: cannot index with vector containing NA / NaN values错误的解决方法(转)
			###df_18的字段fuek是否包含 / df_18[df_18['fuel'].str.contains('/')] 报错: ValueError Traceback (most recent c ... 
- TODO Android +jacoco的增量覆盖率测试和一些概念
			查了下资料,工具要用mac开发,,,,陷入窘境,正在寻找替代方案. Android中的jacoco只支持offline模式,spring支持on-the-fly(在加载class文件进行,运用java ... 
- LoadRunner在Controller场景中配置获取Windows Resources
			一.首先需要在被监控Windows服务器端(只支持Windows)进行如下设置: 启动服务: Remote Procedure Call (RPC) RemoteRegistry 操作方法: 按Win ... 
- 使用Anaconda管理Python环境
			修改镜像源 conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ conda con ... 
- Jenkins 参数化构建(Extended Choice Parameter)
			1.下载安装 Extended Choice Parameter 插件 2.打开job--->General--->参数化构建过程--->Extended Choice Parame ... 
- Mybatis接口中传递多个参数
			1.接口 public interface MemberMapper { public boolean insertMember(Members member); public Members sel ... 
- SQL Server全文检索
			SQL Server 全文索引的硬伤 http://www.cnblogs.com/gaizai/archive/2010/05/13/1733857.html SQLSERVER全文搜索 http: ... 
- P1928 外星密码
			题目描述 有了防护伞,并不能完全避免 2012 的灾难.地球防卫小队决定去求助外星种族的帮 助.经过很长时间的努力,小队终于收到了外星生命的回信.但是外星人发过来的却是一 串密码.只有解开密码,才能知 ... 
- python3 数据类型测试
			type(要测试的数据): 
- python3 中的bytes类型
