spring-cloud-sleuth+zipkin追踪服务实现(三)
1.前言
在上一篇spring-cloud-sleuth+zipkin追踪服务实现(二)中我们讲述了利用mq的方式发送数据,存储在mysql,实际生产过程中调用数据量非常的大,mysql存储并不是很好的选择,这时我们可以采用elasticsearch进行存储。
我们还是使用之前上一节中的三个程序做修改,方便大家看到对比不同点。这里每个项目名都加了一个es,用来表示区别。
2.使用前提
这里选用elasticsearch 2.x版本。
安装elasticsearch的方法详见本人的文章elk搭建实战中elasticsearch部分。
3、microservice-zipkin-stream-server-es
要使用elasticsearch的话,必须在pom.xml中声明相关的依赖。同时不使用mysql,那么去掉mysql相关的依赖。
全部maven依赖如下:
```
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--zipkin依赖-->
<!--此依赖会自动引入spring-cloud-sleuth-stream并且引入zipkin的依赖包-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-zipkin-stream</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-autoconfigure-ui</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin</artifactId>
<version>1.24.0</version>
</dependency>
<!--保存到数据库需要如下依赖-->
<!-- 添加 spring-data-elasticsearch的依赖 -->
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-autoconfigure-storage-elasticsearch-http</artifactId>
<version>1.24.0</version>
<optional>true</optional>
</dependency>
```
由于使用了消息中间件rabbit mq以及elasticsearch,所以我们还需要在配置文件application.properties加入相关的配置:
server.port=11030
spring.application.name=microservice-zipkin-stream-server-es
#zipkin数据保存到数据库中需要进行如下配置
#表示当前程序不使用sleuth
spring.sleuth.enabled=false
#表示zipkin数据存储方式是elasticsearch
zipkin.storage.StorageComponent = elasticsearch
zipkin.storage.type=elasticsearch
zipkin.storage.elasticsearch.cluster=elasticsearch-zipkin-cluster
zipkin.storage.elasticsearch.hosts=127.0.0.1:9300
# zipkin.storage.elasticsearch.pipeline=
zipkin.storage.elasticsearch.max-requests=64
zipkin.storage.elasticsearch.index=zipkin
zipkin.storage.elasticsearch.index-shards=5
zipkin.storage.elasticsearch.index-replicas=1
#rabbitmq配置
spring.rabbitmq.host=localhost
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest
为了避免http通信的干扰,我们将原来的监听端口有11020更改为11030,启动程序,未报错且能够看到rabbit连接日志,说明程序启动成功。
4.microservice-zipkin-stream-client-es、microservice-zipkin-client-stream-backend-es
与上一节中的代码保持一致,当然为了以示区别,端口也做了相应的调整
5.测试
按照上一节的方式访问:http://localhost:11021/call/1,
我们可以server的ui上有相关的数据,同时打开es的管理页面:http://localhost:9200/_plugin/head/,
点击数据浏览,就可以看到以zipkin开头,以日期结尾的index,说明数据成功的写到es了。
6.项目源码:
https://git.oschina.net/shunyang/spring-cloud-microservice-study.git
https://github.com/shunyang/spring-cloud-microservice-study.git
6.参考文档:
spring cloud 官方文档:https://github.com/spring-cloud/spring-cloud-sleuth
spring-cloud-sleuth+zipkin追踪服务实现(三)的更多相关文章
- Spring Cloud Sleuth+ZipKin+ELK服务链路追踪(七)
序言 sleuth是spring cloud的分布式跟踪工具,主要记录链路调用数据,本身只支持内存存储,在业务量大的场景下,为拉提升系统性能也可通过http传输数据,也可换做rabbit或者kafka ...
- 分布式链路追踪之Spring Cloud Sleuth+Zipkin最全教程!
大家好,我是不才陈某~ 这是<Spring Cloud 进阶>第九篇文章,往期文章如下: 五十五张图告诉你微服务的灵魂摆渡者Nacos究竟有多强? openFeign夺命连环9问,这谁受得 ...
- Spring Cloud Alibaba学习笔记(23) - 调用链监控工具Spring Cloud Sleuth + Zipkin
随着业务发展,系统拆分导致系统调用链路愈发复杂一个前端请求可能最终需要调用很多次后端服务才能完成,当整个请求陷入性能瓶颈或不可用时,我们是无法得知该请求是由某个或某些后端服务引起的,这时就需要解决如何 ...
- Spring Cloud Sleuth + Zipkin 链路监控
原文:https://blog.csdn.net/hubo_88/article/details/80878632 在微服务系统中,随着业务的发展,系统会变得越来越大,那么各个服务之间的调用关系也就变 ...
- Spring Cloud 微服务六:调用链跟踪Spring cloud sleuth +zipkin
前言:随着微服务系统的增加,服务之间的调用关系变得会非常复杂,这给运维以及排查问题带来了很大的麻烦,这时服务调用监控就显得非常重要了.spring cloud sleuth实现了对分布式服务的监控解决 ...
- Spring Cloud Sleuth Zipkin - (2)
在上一节<spring-cloud-sleuth+zipkin追踪服务实现(一)>中,我们使用zipkin-server.provider.consumer三个程序实现了使用http方式进 ...
- 【Spring Cloud】Spring Cloud之Spring Cloud Sleuth,分布式服务跟踪(1)
一.Spring Cloud Sleuth组件的作用 为微服务架构增加分布式服务跟踪的能力,对于每个请求,进行全链路调用的跟踪,可以帮助我们快速发现错误根源以及监控分析每条请求链路上的性能瓶颈等. 二 ...
- 阿里高级架构师教你使用Spring Cloud Sleuth跟踪微服务
随着微服务数量不断增长,需要跟踪一个请求从一个微服务到下一个微服务的传播过程,Spring Cloud Sleuth 正是解决这个问题,它在日志中引入唯一ID,以保证微服务调用之间的一致性,这样你就能 ...
- Spring Cloud Sleuth Zipkin - (1)
最近在学习spring cloud构建微服务,很多大牛都提供很多入门的例子帮助我们学习,对于我们这种英语不好的码农来说,效率着实提高不少.这两天学习到追踪微服务rest服务调用链路的问题,接触到zip ...
随机推荐
- Retinex图像增强算法
前一段时间研究了一下图像增强算法,发现Retinex理论在彩色图像增强.图像去雾.彩色图像恢复方面拥有很好的效果,下面介绍一下我对该算法的理解. Retinex理论 Retinex理论始于Land和M ...
- Android NFC开发(一)——初探NFC,了解当前前沿技术
Android NFC开发(一)--初探NFC,了解当前前沿技术 官方文档:http://developer.android.com/guide/topics/connectivity/nfc/ind ...
- JNI技术简介-android学习之旅(92)
分为5步 !!!注意本地方法是java中的方法,本地函数指的是c语言中的对应函数 1.在java类中声明本地方法 2.使用javah命令,生成包含jni本地函数原型的头文件 3. 实现jni本地函数 ...
- 对于CocoaPods的简单理解,实践安装使用过程和常见问题
(本文是自己通过其他文章进行的自我编辑和简单修改,请大家凑活看看) 一.什么是CocoaPods CocoaPods是iOS项目的依赖管理工具,该项目源码在Github上管理.开发iOS项目不可避免地 ...
- javascript语言扩展:可迭代对象(4)
js 1.7中还包含一个数组推导(array comprehension)的特性,如果不在最后介绍它好像显得不怎么完整. 数组推导其实很简单: let a = [x*x for(x in range( ...
- The 1st tip of DB Query Analyzer
The 1st tip of DB Query Analyzer Ma Genfeng (Guangdong Unitoll Services incorporate ...
- SNMP相关的RFC建议和链接
1. SNMP Books or Articleshttp://www.faqs.org/faqs/snmp-faq/part1/http://www.faqs.org/faqs/snmp-faq/p ...
- Maximum Subarray(最大子数组)
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- Eclipse两种部署web项目方法
一).首先使用J2EE的Eclipse的Servers(可以从show view中取出). 1).通过Eclipse建立一个Dynamic Web Project 2).通过Servers视图来创建一 ...
- 精彩源于起点——2018年潍坊市首次青少年Python编程公开课
有一种语言叫计算机语言 I want to talk with Computer 春遇到冬,有了岁月 天遇到地,有了永恒 我们拥有的, 不止是长大, 还有那份长大的悲欢经历. 未来会有很多可能, 但一 ...