pomhtml
<dependency> <groupId>io.zipkin</groupId> <artifactId>zipkin-ui</artifactId> <version>1.39.3</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-sleuth-zipkin-stream</artifactId> <version>1.0.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-stream-rabbit</artifactId> <version>1.0.0.RELEASE</version> </dependency> <!--<dependency>--> <!--<groupId>mysql</groupId>--> <!--<artifactId>mysql-connector-java</artifactId>--> <!--</dependency>--> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> </dependency>
application.yamljava
spring: rabbitmq: addresses: rabbitmq # datasource: # #腳本位置:依賴spanstore-jdbc-0.9.3.jar內 ## schema: classpath:/mysql.sql # url: jdbc:mysql://zipkin_mysql:3306/zipkin # username: zipkin # password: zipkin # # Switch this on to create the schema on startup: # initialize: true # continueOnError: true sleuth: # not use sleuth stream to trace zipkin server itself enabled: false #refer to org.springframework.cloud.sleuth.instrument.hystrix.SleuthHystrixAutoConfiguration.java hystrix: strategy: enabled: false zipkin: storage: type: mem #mysql #mem
applicationmysql
@EnableZipkinStreamServer @SpringBootApplication public class ZipkinServerApplication { public static void main(String[] args){ SpringApplication.run(ZipkinServerApplication.class,args); } }
pomreact
<!-- zipkin client --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-sleuth-stream</artifactId> <version>1.0.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-stream-rabbit</artifactId> <version>1.0.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-ribbon</artifactId> <version>1.0.6.RELEASE</version> <exclusions> <exclusion> <groupId>io.reactivex</groupId> <artifactId>rxjava</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>io.reactivex</groupId> <artifactId>rxjava</artifactId> <version>1.1.5</version> </dependency>
application.ymlgit
spring: # mq stream format to send trace data rabbitmq: addresses: rabbitmq #zipkin config zipkin: #defult is true,to use zipkin,false:not use enabled: true baseUrl: http://zipkin:9411/ sleuth: sampler: # 採樣率,默認0.1即10%,如需測試時每次都看到trace則修改成1.0,但對性能有影響,注意上線時修改成合理值 percentage: 1.0 hystrix: strategy: enabled: true #https://github.com/ReactiveX/RxJava/issues/2297 rxjava: schedulers: hook: enabled: false # stream format to send trace msg: enable sleuth.stream to use stream # default is true,refer to SleuthStreamAutoConfiguration.java stream: enabled: true # skip tracing urls' pattern,refer to org.springframework.cloud.sleuth.instrument.web.TraceWebAutoConfiguration #web: #skipPattern: /eureka.* # zipkin properties for ServiceApplication.java to debug when there is no zipkin server sample: zipkin: # When enabled=false, traces log to the console. Comment to send to zipkin enabled: true
applicationgithub
@SpringBootApplication @EnableDiscoveryClient @EnableFeignClients @EnableCircuitBreaker @EnableHystrix @EnableHystrixDashboard @EnableAspectJAutoProxy(proxyTargetClass = true) @EnableAsync public class TraceDemoApplication { @Bean Sampler sampler() { return new AlwaysSampler(); } public static void main(String[] args){ SpringApplication.run(TraceDemoApplication.class,args); } }
rabbitmq: image: rabbitmq:management expose: - 5672 - 15672 ports: - 5672:5672 - 15672:15672 zipkin: image: zipkin-server restart: always ports: # Listen port for the Scribe transport - "9410:9410" # Historical port used for the Zipkin HTTP Api - "9411:9411" - "9901:9901" links: - rabbitmq trace_demo: image: trace-demo restart: always ports: - "9998:9998" links: - discovery - config - rabbitmq - zipkin
http://192.168.99.100:9411/web
查詢spring