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 */