一、About ZipKin
please google
二、 Demo Scene
三、 Result Display
四、Prepare
1、soft version
kafka:2.10-0.10.2.0
zokeeper:3.4.10
elasticsearch:5.2.2
jdk:1.8
spring boot:1.5.3.RELEASE
sprign cloud:Dalston.RELEASE
rabbit mq:3.6.92、install
kafka+zookeeper
elasticsearch
rabbit mq
mysql3、create four spring cloud project
web-api、user-api、order-api、zipkin
ps:
why i will create zipkin project use spring boot by myself not use zipkin.jar from http://zipkin.io/,actually,zipkin.jar is a spring boot project,check it's dependency lib you will find it din't use spring-cloud-sleuth-stream,but i will send trace info to kafka for zipkin server collector ,so i must use spring-cloud-sleuth-stream in my service
and the message send to kafka is a sleuth.span object and use kafka default serialized,but zipkin.jar only receive zipkin.span and json or thrift encode,so it‘s not matching,That's the reason i create zipkin server
but if you use rabbit mq,that's no problem.
4、configuration
4.1、the service web-api、user-api、order-api config part like:
pom.xml
- <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-kafka</artifactId>
- </dependency>
application.properties- spring.sleuth.sampler.percentage=1.0
- spring.cloud.stream.kafka.binder.brokers=10.20.1.11:9092,10.20.1.12:9092
- spring.cloud.stream.kafka.binder.zkNodes=10.20.1.11:2181,10.20.1.12:2181
4.2、the zipkinconfig part like:pom.xml
-
- <dependency>
- <groupId>io.zipkin.java</groupId>
- <artifactId>zipkin</artifactId>
- <version>1.24.0</version>
- </dependency>
- <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-kafka</artifactId>
- </dependency>
- <dependency>
- <groupId>io.zipkin.java</groupId>
- <artifactId>zipkin-autoconfigure-storage-elasticsearch-http</artifactId>
- <version>1.24.0</version>
- <optional>true</optional>
- </dependency>
application.properties
- #kafka config
- spring.sleuth.enabled=false
- spring.sleuth.sampler.percentage=1.0
- spring.cloud.stream.kafka.binder.brokers=10.20.1.11:9092,10.20.1.12:9092
- spring.cloud.stream.kafka.binder.zkNodes=10.20.1.11:2181,10.20.1.12:2181
- #elasticsearch config
- zipkin.storage.type=elasticsearch
- zipkin.storage.elasticsearch.hosts=10.20.1.11:9200,10.20.1.12:9200
- zipkin.storage.elasticsearch.cluster=elasticsearch
- zipkin.storage.elasticsearch.index=zipkin
- zipkin.storage.elasticsearch.index-shards=5
- zipkin.storage.elasticsearch.index-replicas=1
ZipKin Server Startup class configuration
- <span style="font-size:14px;">@SpringBootApplication
-
- @EnableZipkinStreamServer
- public class ZkingApplication {
- public static void main(String[] args) {
- SpringApplication.run(ZkingApplication.class, args);
- }
- }</span>
五、Demo DownLoad
click me
by the way,spring cloud is a pretty boy,i like its combination of terseness and elegance
六、补充
如果kafka没有启动,spring boot会启动失败,这个异常处理设计的真是缺德
/**
* 1、修改背景
* 因kafka节点没有启动 在spring boot启动时初始化outputBindingLifecycle、inputBindingLifecycle
* 两个bean时候连接kafka失败,向外抛出了异常直到EmbeddedWebApplicationContext类
* 捕获处理,处理方式为:stopAndReleaseEmbeddedServletContainer()导致整个应用停止启动
* 2、修改方案
* 干预上面两个bean的初始化,在连接kafka异常时,将异常处理掉,不向上层抛出
* 3、修改步骤
* 3.1、使用自定义MyBindingLifecycle的bean将BindingServiceConfiguration中的两个bean初始化替换掉
* 3.2、在自定bean中启动线程MyBindingThread来控制
版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/qq_34196952/article/details/80351463
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
-
发表于 2020-04-19 11:08:05
- 阅读 ( 1558 )
- 分类: