天天學點SpringCloud(十四):Zipkin使用SpringCloud Stream以及Elasticsearch

在前面的文章中,咱們已經成功的使用Zipkin收集了項目的調用鏈日誌。可是呢,因爲咱們收集鏈路信息時採用的是http請求方式收集的,並且鏈路信息沒有進行保存,ZipkinServer一旦重啓後就會全部信息都會消失了。基於性能的考慮,咱們能夠對它進行改造,使用SpringCloud Stream進行消息傳遞,使用Elasticsearch進行消息的存儲。java

參考文章


Zipkin全鏈路監控

SpringCloud-Stream整合RabbitMQgit

改造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的相關配置github

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的配置就搞定了。web

3. 客戶端增長依賴

如下兩個依賴任選其一就能夠spring

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
複製代碼

注意要把如下配置去掉哦bash

1
2
3
4
5
複製代碼
spring:
  zipkin:
    base-url: http://localhost:19411
    sender:
      type: web
複製代碼

如今環境已經搭建完畢了,根據你的採樣頻率看一看結果如何吧elasticsearch

GitHub地址:github.com/shiyujun/sp…。代碼所在模塊:cloud-demo-zipkin-server,cloud-demo-consumer-feign-hystrix,cloud-demo-provideride

若是對您有所幫助,請記得幫忙點一個star哦spring-boot

本文出自zhixiang.org.cn,轉載請保留。性能

相關文章
相關標籤/搜索