微服务整合Zipkin

一 新建项目microservice-simple-provider-user-trace-zipkin
二 为项目添加以下依赖
  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
      <groupId>com.h2database</groupId>
      <artifactId>h2</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <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>
三 在配置文件application.yml中添加如下内容
server:
  port: 8000
spring:
  jpa:
    generate-ddl: false
    show-sql: true
    hibernate:
      ddl-auto: none
  datasource:                           # 指定数据源
    platform: h2                        # 指定数据源类型
    schema: classpath:schema.sql        # 指定h2数据库的建表脚本
    data: classpath:data.sql            # 指定h2数据库的数据脚本
  application:
    name: microservice-provider-user
  zipkin:
    base-url:http://localhost:9411
  sleuth:
    sampler:
      percentage: 1.0
其中:
spring.zipkin.base-url:指定Zipkin的地址。
spring.sleuth.sampler.percentage:指定需采样的请求百分比,默认为0.1,即10%。这是因为在分布式系统中,数据量可能非常大,因此采样非常重要。
这样就为项目整合了Zipkin。
四 按照同样的方法新建项目microservice-simple-consumer-movie-trace-zipkin
五 测试
1 启动microservice-trace-zipkin-server
2 启动microservice-simple-provider-user-trace-zipkin
3 启动microservice-simple-consumer-movie-trace-zipkin
4 访问http://localhost:8010/user/1,可正常获得结果。
5 访问Zipkin Server首页http://localhost:9411/,填入起始时间、结束时间等筛选条件后,单击Find a trace按钮,可看到trace列表,如下图:
6 单击trace,可看到下图所示:
7 单击span,可获得span的详细信息,如下图
8 查看微服务间的关系


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值