博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring Cloud 分布式应用跟踪
阅读量:2074 次
发布时间:2019-04-29

本文共 3660 字,大约阅读时间需要 12 分钟。

Spring Cloud 分布式应用跟踪

SpanID:阶段性ID,比如一次RPC有可能多Span

TraceID:一次RPC只有一个TraceID

整合Spring Cloud Sleuth

1.增加依赖

org.springframework.cloud
spring-cloud-starter-sleuth

Zipkin整合

新增Zipkin服务器

增加Maven依赖

io.zipkin.java
zipkin-server
io.zipkin.java
zipkin-autoconfigure-ui

激活Zipkin服务器

HTTP方式采集

import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import zipkin.server.EnableZipkinServer;/** * Zipkin 服务器应用 * */@SpringBootApplication@EnableZipkinServerpublic class ZipkinServerApplication {    public static void main(String[] args) {        SpringApplication.run(ZipkinServerApplication.class, args);    }}

配置Zipkin服务器

## 应用元信息## Zipkin 服务器应用名称spring.application.name = zipkin-server## Zipkin 服务器服务端口server.port = 20000## 管理端口安全失效management.security.enabled = false

整合Zipkin客户端

改造user-service-client
HTTP方式上报
增加Maven依赖

org.springframework.cloud
spring-cloud-starter-zipkin

配置:连接zipkin服务器

## Zipkin 配置### 配置 Zipkin 服务器zipkin.server.host = localhostzipkin.server.port = 20000spring.zipkin.base-url = http://${zipkin.server.host}:${zipkin.server.port}

改造user-service-provider

增加Maven依赖

org.springframework.cloud
spring-cloud-starter-zipkin

配置:连接zipkin服务器

## Zipkin 配置### 配置 Zipkin 服务器zipkin.server.host = localhostzipkin.server.port = 20000spring.zipkin.base-url = http://${zipkin.server.host}:${zipkin.server.port}

改造zipkin服务器:使用Stream方式订阅

增加Maven依赖

org.springframework.cloud
spring-cloud-sleuth-zipkin-stream
org.springframework.cloud
spring-cloud-stream-binder-rabbit

替换激活注解:@EnableZipkinStreamServer

Stream方式采集

package com.segumentfault.spring.cloud.lesson15.zipkin.server;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.sleuth.zipkin.stream.EnableZipkinStreamServer;/** * Zipkin 服务器应用 * */@SpringBootApplication//@EnableZipkinServer@EnableZipkinStreamServerpublic class ZipkinServerApplication {    public static void main(String[] args) {        SpringApplication.run(ZipkinServerApplication.class, args);    }}

改造user-service-client

增加Maven依赖

stream方式上报

org.springframework.cloud
spring-cloud-starter-sleuth
org.springframework.cloud
spring-cloud-sleuth-stream
org.springframework.cloud
spring-cloud-stream-binder-rabbit

注意要移除之前zipkin依赖

改造user-service-provider

增加Maven依赖

Stream方式上报

org.springframework.cloud
spring-cloud-starter-sleuth
org.springframework.cloud
spring-cloud-sleuth-stream
org.springframework.cloud
spring-cloud-stream-binder-rabbit

注意要移除zipkin依赖

转载地址:http://cwxmf.baihongyu.com/

你可能感兴趣的文章
Leetcode C++《热题 Hot 100-26》15.三数之和
查看>>
Leetcode C++《热题 Hot 100-27》17.电话号码的字母组合
查看>>
Leetcode C++《热题 Hot 100-28》19.删除链表的倒数第N个节点
查看>>
Leetcode C++《热题 Hot 100-29》22.括号生成
查看>>
Leetcode C++《热题 Hot 100-40》64.最小路径和
查看>>
Leetcode C++《热题 Hot 100-41》75.颜色分类
查看>>
Leetcode C++《热题 Hot 100-42》78.子集
查看>>
Leetcode C++《热题 Hot 100-43》94.二叉树的中序遍历
查看>>
Leetcode C++ 《第175场周赛-1 》5332.检查整数及其两倍数是否存在
查看>>
Leetcode C++ 《第175场周赛-2 》5333.制造字母异位词的最小步骤数
查看>>
Leetcode C++ 《第175场周赛-3》1348. 推文计数
查看>>
Leetcode C++《热题 Hot 100-44》102.二叉树的层次遍历
查看>>
Leetcode C++《热题 Hot 100-45》338.比特位计数
查看>>
读书摘要系列之《kubernetes权威指南·第四版》第一章:kubernetes入门
查看>>
Leetcode C++《热题 Hot 100-46》739.每日温度
查看>>
Leetcode C++《热题 Hot 100-47》236.二叉树的最近公共祖先
查看>>
Leetcode C++《热题 Hot 100-48》406.根据身高重建队列
查看>>
《kubernetes权威指南·第四版》第二章:kubernetes安装配置指南
查看>>
Leetcode C++《热题 Hot 100-49》399.除法求值
查看>>
Leetcode C++《热题 Hot 100-51》152. 乘积最大子序列
查看>>