美文网首页Spring Cloud
spring cloud zipkin2 + kafka + e

spring cloud zipkin2 + kafka + e

作者: 就怕是个demo | 来源:发表于2018-09-04 15:54 被阅读0次

    做个笔记~
    虽然官网建议用官方jar包,但是公司的情况用官方jar行不通,所以自定义一下。

    spring boot 版本:2.0.4.RELEASE
    spring cloud 版本:Finchley.SR1

    zipkin server
    • pom.xml
    <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
                <version>2.0.1.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-actuator</artifactId>
            </dependency>
            
            <!--zipkin-->
            <dependency>
                <groupId>io.zipkin.java</groupId>
                <artifactId>zipkin-server</artifactId>
                <version>2.11.1</version>
            </dependency>
            <dependency>
                <groupId>io.zipkin.java</groupId>
                <artifactId>zipkin-autoconfigure-ui</artifactId>
                <version>2.11.1</version>
            </dependency>
            <dependency>
                <groupId>io.zipkin.java</groupId>
                <artifactId>zipkin-autoconfigure-collector-kafka</artifactId>
                <version>2.11.4</version>
            </dependency>
            <dependency>
                <groupId>io.zipkin.java</groupId>
                <artifactId>zipkin-autoconfigure-storage-elasticsearch-http</artifactId>
                <version>2.8.4</version>
            </dependency>
        </dependencies>
    
    • application.yml
    server:
      port: 9411
      tomcat:
        uri-encoding: UTF-8
    
    spring:
      application:
        name: zipkin-server
    
    zipkin:
      storage:
        type: elasticsearch
        elasticsearch:
          hosts: http://localhost:9200
          #      username: elastic
          #      password: changeme
          cluster: elasticsearch
          index: zipkin
          index-shards: 1
          index-replicas: 1
      collector:
        kafka:
          bootstrap-servers: localhost:9092
          zookeeper: localhost:2181
          topic: zipkin
    
    eureka:
      instance:
        lease-expiration-duration-in-seconds: 15
        lease-renewal-interval-in-seconds: 5
        prefer-ip-address: true
        health-check-url-path: /actuator/health
      client:
        registry-fetch-interval-seconds: 5
        service-url:
          defaultZone: http://127.0.0.1:8761/eureka/
    
    management:
      endpoints:
        web:
          exposure:
            include: "*"
      endpoint:
        health:
          show-details: ALWAYS
      metrics:
        web:
          server:
            auto-time-requests: false
    
    • 启动类
    @SpringBootApplication
    @EnableEurekaClient
    @EnableZipkinServer
    public class ZipkinServerApplication {
        public static void main(String[] args) {
            SpringApplication.run(ZipkinServerApplication.class, args);
        }
    }
    
    provider-service
    • pom.xml
    <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
                <version>2.0.1.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-actuator</artifactId>
            </dependency>
    
            <!--zipkin-->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-zipkin</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.kafka</groupId>
                <artifactId>spring-kafka</artifactId>
            </dependency>
        </dependencies>
    
    • application.yml
    server:
      port: 8080
      tomcat:
        uri-encoding: UTF-8
    
    spring:
      application:
        name: provider
      sleuth:
        sampler:
          probability: 1.0
      zipkin:
        sender:
          type: kafka
        kafka:
          topic: zipkin
      kafka:
        bootstrap-servers: localhost:9092
    
    eureka:
      instance:
        lease-expiration-duration-in-seconds: 15
        lease-renewal-interval-in-seconds: 5
        prefer-ip-address: true
        health-check-url-path: /actuator/health
      client:
        registry-fetch-interval-seconds: 5
        service-url:
          defaultZone: http://127.0.0.1:8761/eureka/
    
    management:
      endpoints:
        web:
          exposure:
            include: "*"
      endpoint:
        health:
          show-details: ALWAYS
    
    • 启动类
    @SpringBootApplication
    @EnableEurekaClient
    public class ProviderApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(ProviderApplication.class, args);
        }
    }
    
    consumer-service 配置同 provider-service,不在赘述

    相关文章

      网友评论

      本文标题:spring cloud zipkin2 + kafka + e

      本文链接:https://www.haomeiwen.com/subject/koogwftx.html