【Spring Cloud】Spring Cloud之Zipkin server搭建以及RabbitMQ收集,分布式服务跟踪(3)

一、搭建步骤

1)新建Spring Boot项目,引入pom坐标

 <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <dependencies>
        <!-- http -->
        <dependency>
            <groupId>io.zipkin.java</groupId>
            <artifactId>zipkin-server</artifactId>
            <version>2.10.3</version>
        </dependency>
        <dependency>
            <groupId>io.zipkin.java</groupId>
            <artifactId>zipkin-autoconfigure-ui</artifactId>
            <version>2.10.3</version>
        </dependency>
        <!-- 使用消息的方式收集数据(使用rabbitmq) -->
        <dependency>
            <groupId>io.zipkin.java</groupId>
            <artifactId>zipkin-autoconfigure-collector-rabbitmq</artifactId>
            <version>2.12.9</version>
        </dependency>
    </dependencies>

2)增加相关配置

spring.application.name: base-zipkin-server
server.port: 9411

zipkin.collector.rabbitmq.addresses: localhost:5672
zipkin.collector.rabbitmq.username: guest
zipkin.collector.rabbitmq.password: guest
zipkin.collector.rabbitmq.queue: zipkin

#zipkin启动或访问报错无法访问的解决方法
management.metrics.web.server.auto-time-requests: false
 

3)启动类增加注解

@EnableZipkinServer
@SpringBootApplication
public class BaseZipkinServerMqApplication {

    public static void main(String[] args) {
        SpringApplication.run(BaseZipkinServerMqApplication.class, args);
    }

}

4)访问http://lo-calhost:9411/,可以看到、Zipkin管理页面

 

二、应用服务如何以RabbitMQ的方式,将sleuth生成的traceId等追踪数据发送到Zipkin中

1)增加pom坐标

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
<version>2.0.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
<version>2.0.3.RELEASE</version>
</dependency>

2)增加配置,指定MQ的配置

# 指定消息发送方式,web、rabbit、kafka
spring.zipkin.sender.type: rabbit
# 指定mq队列名称
zipkin.rabbitmq.queue: zipkin
# rabbitmq配置
spring.rabbitmq.host: localhost
spring.rabbitmq.port: 5672
spring.rabbitmq.username: guest
spring.rabbitmq.password: guest

 

posted @ 2019-09-15 15:08  N!CE波  阅读(1275)  评论(0编辑  收藏  举报