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,转载请保留。

相关推荐
一隅论数智3 天前
给AI一张“业务概念地图“:本体如何从哲学走向企业智能
大数据·人工智能·经验分享·笔记·学习·学习方法·政务
XiHongShi20163 天前
STM32F407 RTC定时器例程,建议保存
stm32·单片机·学习
爱吃苹果的日记本3 天前
离散数学第六课
学习·离散数学
AI职业加油站3 天前
AI智能体应用工程师证书:政策红利下的职业新风口
大数据·运维·人工智能·学习·职场发展
深圳老胡3 天前
STM32F407 控制 L6470 步进电机驱动 —— 控制过程简介
笔记·stm32·单片机·嵌入式硬件·代码规范
旖旎夜光3 天前
力控面试题 01.01: 判定字符是否唯一(位运算) —— 题解
c++·学习·算法·leetcode·力控
奇思妙想聪明勤奋的小羊3 天前
DeepAgents第5章:子Agent 与上下文隔离—让 Agent学会委派
人工智能·python·学习·语言模型
Because_of_Her13 天前
并查集-听课笔记
笔记·算法·并查集
霍霍的袁3 天前
【C++】map 和 set 的使用 | 从用法到底层
开发语言·c++·学习·visual studio