首先在代码里面引入依赖:
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-zipkin</artifactId> </dependency>
这个依赖包括了前几个依赖,所以引入一个就可以了
可以点进这个依赖看下:
</parent> <artifactId>spring-cloud-starter-zipkin</artifactId> <name>Spring Cloud Starter Zipkin</name> <description>Spring Cloud Starter Zipkin</description> <properties> <main.basedir>${basedir}/../..</main.basedir> </properties> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-sleuth</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-sleuth-zipkin</artifactId> </dependency> </dependencies>
所以只需要引入刚才那个依赖就可以了
yml 配置:
eureka: client: serviceUrl: defaultZone: http://admin:admin@127.0.0.1:8761/eureka/ #eureka注册中心地址 spring: application: name: cxy-user-service #应用名 #datasource,数据连接 datasource: driver-class-name: com.mysql.jdbc.Driver url : jdbc:mysql://127.0.0.1:3306/fr_db?zeroDateTimeBehavior=convertToNull&autoReconnect=true&useUnicode=true&characterEncoding=utf-8 password: 1234 username: root sleuth: sampler: probability: 1 #抽样百分比,默认0.1 就是百分十 zipkin: base-url: http://192.168.230.133:9411/ #地址 sender: type: web #mybatis mybatis: type-aliases-package: com.cxy.dataObject #实体类映射文件包 mapper-locations: classpath:mapping/*.xml #生成的sql语句 server: port: 8082 feign: hystrix: enabled: true logging: level: org.springframework.cloud.openfeign: debug
然后docker安装zipkin
启动zipkin
在浏览器输入地址:
然后启动服务:
服务调用成功:
可以看到每个服务的调用时间,可以进行优化相关配置