spring cloud sleuth zipkin kafka收集


spring cloud sleuth zipkin kafka收集

 

Application: The server sends logs to the message middleware, and zipkin obtains log data from the message middleware to achieve asynchronous acquisition of log data

 

********************************

zipkin creation

 

#zookeeper
docker run -it -d --net fixed3 --ip 192.168.57.2 --name zoo zookeeper


#kafka
docker run -it -d --net fixed3 --ip 192.168.57.3 \
-v /usr/kafka/single/conf/server.properties:/usr/kafka/config/server.properties \
--name kafka kafka bash bin/kafka-server-start.sh config/server.properties


#zipkin
docker run -it -d --net fixed3 --ip 192.168.57.4 -e "QUERY_PORT=8080" \
-e "COLLECTOR_KAFKA_ENABLED=true" -e "KAFKA_BOOTSTRAP_SERVERS=192.168.57.3:9092" \
--name zipkin openzipkin/zipkin

 

 

********************************

Import jar package

 

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zipkin</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-stream-kafka</artifactId>
        </dependency>

 

 

********************************

Service 1: hello-service

 

*******************

Configuration file

 

spring:
  application:
    name: hello-service
  cloud:
    consul:
      host: 192.168.57.21
      port: 8500
  zipkin:
    sender:
      type: kafka
  kafka:
    bootstrap-servers: 192.168.57.3:9092

 

ZipkinSenderProperties.SenderType: Collection type

@ConfigurationProperties("spring.zipkin.sender")
public class ZipkinSenderProperties {
    private ZipkinSenderProperties.SenderType type;

    public ZipkinSenderProperties() {
    }

    public ZipkinSenderProperties.SenderType getType() {
        return this.type;
    }

    public void setType(ZipkinSenderProperties.SenderType type) {
        this.type = type;
    }

    public static enum SenderType {
        ACTIVEMQ,   //使用消息中间件activemq收集
        RABBIT,     //使用消息中间件rabbitmq收集
        KAFKA,      //使用消息中间件kafka收集
        WEB;        //使用http收集

        private SenderType() {
        }
    }
}

 

*******************

controller layer

 

HelloController

@RestController
public class HelloController {

    private Logger logger= LoggerFactory.getLogger(HelloController.class);

    @RequestMapping("/hello")
    public String hello(){
        logger.info("hello controller: {}","hello world");

        return "hello world";
    }
}

 

 

********************************

Service 2: hello-consumer

 

*******************

Configuration file

 

spring:
  application:
    name: hello-conusmer
  cloud:
    consul:
      host: 192.168.57.21
      port: 8500
  zipkin:
    sender:
      type: kafka
  kafka:
    bootstrap-servers: 192.168.57.3:9092

 

*******************

service layer

 

HelloService

@FeignClient(name = "hello-service",fallback = HelloServiceImpl.class)
public interface HelloService {

    @RequestMapping("/hello")
    String hello();
}

 

*******************

serviceImpl layer

 

HelloServiceImpl

@Service
public class HelloServiceImpl implements HelloService {

    @Override
    public String hello() {
        return "本地调用输出: "+"hello world";
    }
}

 

*******************

controller layer

 

HelloConsumerController

@RestController
public class HelloConsumerController {

    private Logger logger= LoggerFactory.getLogger(HelloConsumerController.class);

    @Resource
    private HelloService helloService;

    @RequestMapping("/consume")
    public String consume(){
        logger.info("远程调用hello-service:{}",helloService.hello());
        logger.info("本地调用hello-consumer:{}","hello consumer");

        return "hello consumer";
    }
}

 

 

**************************

Use test

 

Call interface / consume

      

      

 

Multiple calls / consume

      

 

 

Published 387 original articles · Like 98 · Visits 30,000+

Guess you like

Origin blog.csdn.net/weixin_43931625/article/details/104856910