SpringCloud学习笔记(十三)_Zipkin使用SpringCloud Stream以及Elasticsearch

在前面的文章中,我们已经成功的使用Zipkin收集了项目的调用链日志。但是呢,由于我们收集链路信息时采用的是http请求方式收集的,而且链路信息没有进行保存,ZipkinServer一旦重启后就会所有信息都会消失了。基于性能的考虑,我们可以对它进行改造,使用SpringCloud Stream进行消息传递,使用Elasticsearch进行消息的存储。

参考文章

Zipkin全链路监控

SpringCloud-Stream整合RabbitMQ

改造ZipkinServer

1. 增加依赖
复制代码
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  

|

复制代码
<dependency>  
            <groupId>io.zipkin.java</groupId>  
            <artifactId>zipkin-autoconfigure-collector-rabbitmq</artifactId>  
            <version>2.11.8</version>  
        </dependency>  
        <dependency>  
            <groupId>io.zipkin.java</groupId>  
            <artifactId>zipkin-autoconfigure-storage-elasticsearch-http</artifactId>  
            <version>2.8.4</version>  
        </dependency>  

---|---

2. 配置文件

增加rabbit和es的相关配置

复制代码
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  

|

复制代码
zipkin:  
  collector:  
    rabbitmq:  
      addresses: 10.0.20.132  
      port: 5672  
      username: root  
      password: root  
      virtual-host: /unicode-pay  
      queue: zipkin  
  storage:  
    StorageComponent: elasticsearch  
    type: elasticsearch  
    elasticsearch:  
      hosts: 10.0.20.25:9200  
      cluster: elasticsearch  
      index: zipkin  
      index-shards: 5  
      index-replicas: 1  

---|---

至此ZipkinServer的配置就搞定了。

3. 客户端增加依赖

以下两个依赖任选其一就可以

复制代码
1  
2  
3  
4  

|

复制代码
<dependency>  
			<groupId>org.springframework.amqp</groupId>  
			<artifactId>spring-rabbit</artifactId>  
		</dependency>  

---|---

复制代码
1  
2  
3  
4  

|

复制代码
<dependency>  
			<groupId>org.springframework.boot</groupId>  
			<artifactId>spring-boot-starter-amqp</artifactId>  
		</dependency>  

---|---

4. 客户端增加mq的相关配置
复制代码
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  

|

复制代码
spring:  
  sleuth:  
    sampler:  
      probability: 1.0  
  rabbitmq:  
    addresses: 10.0.20.132  
    port: 5672  
    username: root  
    password: root  
  zipkin:  
    rabbitmq:  
      queue: zipkin  

---|---

注意要把以下配置去掉哦

复制代码
1  
2  
3  
4  
5  

|

复制代码
spring:  
  zipkin:  
    base-url: http://localhost:19411  
    sender:  
      type: web  

---|---

现在环境已经搭建完毕了,根据你的采样频率看一看结果如何吧

GitHub地址:https://github.com/shiyujun/spring-cloud-demo。代码所在模块:cloud-demo-zipkin-server,cloud-demo-consumer-feign-hystrix,cloud-demo-provider

如果对您有所帮助,请记得帮忙点一个star哦

本文出自http://zhixiang.org.cn,转载请保留。

相关推荐
IT古董21 小时前
【WMS学习笔记系列】03-功能模块设计
笔记·学习·系统架构
vivo互联网技术1 天前
协同文档下的 Agent 协作闭环:可回滚、可对比的透明化编辑实现
人工智能·笔记·agent
Wang's Blog1 天前
PostgreSQL笔记27: 双缓存架构下的内存管理与性能观测实践
笔记·缓存·postgresql
Canmag 兴隆磁性1 天前
充磁的时候,磁铁里面到底发生了什么
学习·永磁材料·充磁·退磁
Wang's Blog1 天前
PostgreSQL笔记22: WAL日志与崩溃恢复原理
数据库·笔记·postgresql
海兰1 天前
【Kafka学习4】六大核心 API
学习·kafka·linq
知识分享小能手1 天前
概理论与数理统计学习教程,从入门到精通,随机变量的数字特征 — 知识点总结与详细推导(7)
学习·机器学习·概率论
却道天凉_好个秋1 天前
计算机网络:CDN
学习·音视频·cdn
圆奋奋1 天前
FreeRTOS学习(十)- 最核心的内容:优先级抢占式调度 + 上下文切换
学习·freertos
程序猿炎义1 天前
【llm-algo-leetcode学习笔记】显存与性能认知底座
笔记·学习·leetcode