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

最新文章

  1. Chrome开发工具之Console
  2. JSPatch
  3. [ASE][Daily Scrum]12.05
  4. 2016年6月23日 星期四 --出埃及记 Exodus 14:20
  5. [转载]mysql的binlog安全删除
  6. 静态化 - 伪静态技术(PHP正则表达式实现)
  7. 老李谈HTTP1.1的长连接 1
  8. 腾讯云存储专家深度解读基于Ceph对象存储的混合云机制
  9. [转]layui点击左侧导航栏,实现不刷新整个页面,只刷新局部
  10. FPC全制造组装的流程介绍(转载)
  11. Codeforces Round #309 (Div. 2) -D. Kyoya and Permutation
  12. SPLIT_STR
  13. 【LeetCode】区间合并
  14. Qt之获取子部件
  15. 漫谈C指针:参数传递的三道题目
  16. W25Q128BV W25Q128FV W25Q128JV 什么区别?
  17. python服务端内存泄露的处理过程
  18. java mongodb 基础系列---查询,排序,limit,$in,$or,输出为list,创建索引,$ne 非操作
  19. (3.10)mysql基础深入——mysqld 服务器与客户端连接过程 源码分析【待写】
  20. 【LeetCode算法题库】Day3:Reverse Integer &amp; String to Integer (atoi) &amp; Palindrome Number

热门文章

  1. Unity3D学习笔记(二)Unity的JavaScript基础
  2. windows linux—unix 跨平台通信集成控制系统----系统硬件信息获取
  3. adb shell后出现error解决方案
  4. linux socket编程之TCP与UDP
  5. HBase开启LZO
  6. cocos2d-x 控制台输出日志
  7. 《深入理解java虚拟机》读书笔记1--java内存区域
  8. SQL解决数值间隔问题
  9. iOS Swift开发的一些坑
  10. PHP基础(一)--字符串函数大盘点(基础篇)