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追踪服务实现(三)的更多相关文章

  1. Spring Cloud Sleuth+ZipKin+ELK服务链路追踪(七)

    序言 sleuth是spring cloud的分布式跟踪工具,主要记录链路调用数据,本身只支持内存存储,在业务量大的场景下,为拉提升系统性能也可通过http传输数据,也可换做rabbit或者kafka ...

  2. 分布式链路追踪之Spring Cloud Sleuth+Zipkin最全教程!

    大家好,我是不才陈某~ 这是<Spring Cloud 进阶>第九篇文章,往期文章如下: 五十五张图告诉你微服务的灵魂摆渡者Nacos究竟有多强? openFeign夺命连环9问,这谁受得 ...

  3. Spring Cloud Alibaba学习笔记(23) - 调用链监控工具Spring Cloud Sleuth + Zipkin

    随着业务发展,系统拆分导致系统调用链路愈发复杂一个前端请求可能最终需要调用很多次后端服务才能完成,当整个请求陷入性能瓶颈或不可用时,我们是无法得知该请求是由某个或某些后端服务引起的,这时就需要解决如何 ...

  4. Spring Cloud Sleuth + Zipkin 链路监控

    原文:https://blog.csdn.net/hubo_88/article/details/80878632 在微服务系统中,随着业务的发展,系统会变得越来越大,那么各个服务之间的调用关系也就变 ...

  5. Spring Cloud 微服务六:调用链跟踪Spring cloud sleuth +zipkin

    前言:随着微服务系统的增加,服务之间的调用关系变得会非常复杂,这给运维以及排查问题带来了很大的麻烦,这时服务调用监控就显得非常重要了.spring cloud sleuth实现了对分布式服务的监控解决 ...

  6. Spring Cloud Sleuth Zipkin - (2)

    在上一节<spring-cloud-sleuth+zipkin追踪服务实现(一)>中,我们使用zipkin-server.provider.consumer三个程序实现了使用http方式进 ...

  7. 【Spring Cloud】Spring Cloud之Spring Cloud Sleuth,分布式服务跟踪(1)

    一.Spring Cloud Sleuth组件的作用 为微服务架构增加分布式服务跟踪的能力,对于每个请求,进行全链路调用的跟踪,可以帮助我们快速发现错误根源以及监控分析每条请求链路上的性能瓶颈等. 二 ...

  8. 阿里高级架构师教你使用Spring Cloud Sleuth跟踪微服务

    随着微服务数量不断增长,需要跟踪一个请求从一个微服务到下一个微服务的传播过程,Spring Cloud Sleuth 正是解决这个问题,它在日志中引入唯一ID,以保证微服务调用之间的一致性,这样你就能 ...

  9. Spring Cloud Sleuth Zipkin - (1)

    最近在学习spring cloud构建微服务,很多大牛都提供很多入门的例子帮助我们学习,对于我们这种英语不好的码农来说,效率着实提高不少.这两天学习到追踪微服务rest服务调用链路的问题,接触到zip ...

随机推荐

  1. STL常用查找算法介绍

    adjacent_find() 在iterator对标识元素范围内,查找一对相邻重复元素,找到则返回指向这对元素的第一个元素的迭代器.否则返回past-the-end. #include <io ...

  2. Process Order API - How To Scripts

    In this Document   Purpose   Questions and Answers   References APPLIES TO: Oracle Order Management ...

  3. TCP中的MSS解读(转)

    本文摘录自TCP中的MSS解读. MSS 是TCP选项中最经常出现,也是最早出现的选项.MSS选项占4byte.MSS是每一个TCP报文段中数据字段的最大长度,注意:只是数据部分的字段,不包括TCP的 ...

  4. web.xml 详细介绍

    url:http://mianhuaman.iteye.com/blog/1105522#bc2344393 1.启动一个WEB项目的时候,WEB容器会去读取它的配置文件web.xml,读取<l ...

  5. "C#":MySql批量数量导入

    现在对数据库(以MySql为例)的操作大多会封装成一个类,如下例所示: namespace TESTDATABASE { public enum DBStatusCode { ALL_OK, MySq ...

  6. Android下Json数据解析

    如从网络获取JSON 则需要创建一个工具类,该类返回一个字符串为JSON文本 package com.example.jsonapp; import java.io.InputStreamReader ...

  7. 结合FireBreath在Chrome/FireFox的多进程模式下崩溃一例

    FireBreath是跨浏览器跨操作系统的插件方案,它封装了ActiveX和NPAPI的插件接口,使用统一的API来暴露JSAPI.Chrome和FireFox使用NPAPI,IE使用ActiveX. ...

  8. Apache Hadoop 2.0.2-alpha

    原文出处http://hadoop.apache.org/docs/r2.0.2-alpha/hadoop-yarn/hadoop-yarn-site/Federation.html HDFSF分为2 ...

  9. Android Xlistview的源码浅度分析 监听ListView上下滑动 以及是否到顶和底部

    如转载 请注明出处 http://blog.csdn.net/sk719887916 比如我们很多项目中会用到listview 并且要对listview滑动方向进行判断 也有需要的到listview是 ...

  10. Emmet for Dreamweaver:HTML/CSS代码快速编写神器

    Emmet的前身是大名鼎鼎的Zen coding,如果你从事Web前端开发的话,对该插件一定不会陌生.它使用仿CSS选择器的语法来生成代码,大大提高了HTML/CSS代码编写的速度,比如下面的演示: ...