http://blog.csdn.net/qq_15138455/article/details/72956232html
版权声明:@入江之鲸java
1、About ZipKinmysql
please googleweb
2、 Demo Scenespring
3、 Result Display
sql
4、Preparejson
一、soft versionapi
kafka:2.10-0.10.2.0二、installapp
kafka+zookeeper三、create four spring cloud projectelasticsearch
web-api、user-api、order-api、zipkinwhy 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.
四、configuration
4.一、the service web-api、user-api、order-api config part like:pom.xml
5、Demo DownLoad
by the way,spring cloud is a pretty boy,i like its combination of terseness and elegance
6、补充
若是kafka没有启动,spring boot会启动失败,这个异常处理设计的真是缺德
/** * 一、修改背景 * 因kafka节点没有启动 在spring boot启动时初始化outputBindingLifecycle、inputBindingLifecycle * 两个bean时候链接kafka失败,向外抛出了异常直到EmbeddedWebApplicationContext类 * 捕获处理,处理方式为:stopAndReleaseEmbeddedServletContainer()致使整个应用中止启动 * 二、修改方案 * 干预上面两个bean的初始化,在链接kafka异常时,将异常处理掉,不向上层抛出 * 三、修改步骤 * 3.一、使用自定义MyBindingLifecycle的bean将BindingServiceConfiguration中的两个bean初始化替换掉 * 3.二、在自定bean中启动线程MyBindingThread来控制两个bean的初始化 * 四、解决启动问题以后,实际上kafka仍是没有链接的,此时向kafka发送span时会失败,默认的处理方案是捕获到异常以后使用 * handleError处理,再次发送新的span,这就致使循环发送 * 参见:ErrorHandlingTaskExecutor中的execute方法 * catch (Throwable t) * { * ErrorHandlingTaskExecutor.this.errorHandler.handleError(t); * } * 五、解决方案 * 重写ErrorHandler的handleError方法 * 六、跟踪代码发现 * 跟踪发现ErrorHandler对线对象是在SourcePollingChannelAdapterFactoryBean初始化时候设置的 * spca.setErrorHandler(this.pollerMetadata.getErrorHandler()); * 进一步发现是在pollerMetadata对象中,因此须要在pollerMetadata对象初始化时候作修改 * 七、修改步骤 * 自定义MyPollerMetadata且须要@Configuration,重写handleError方法以下 * @author zhangdingxin、yangxi */